[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 19/23: nio: add non-blocking connect
From: |
Andy Wingo |
Subject: |
[Guile-commits] 19/23: nio: add non-blocking connect |
Date: |
Thu, 24 Mar 2016 14:26:04 +0000 |
wingo pushed a commit to branch wip-ethreads
in repository guile.
commit a487ade8c8e43147486a7dc45f93b615b984a8ad
Author: Andy Wingo <address@hidden>
Date: Fri Mar 30 17:11:22 2012 +0200
nio: add non-blocking connect
* libguile/nio.c (scm_nio_connect):
* module/ice-9/nio.scm (nio-connect): Add non-blocking connect
primitive.
---
libguile/nio.c | 32 ++++++++++++++++++++++++++++++++
module/ice-9/nio.scm | 13 ++++++++++++-
2 files changed, 44 insertions(+), 1 deletions(-)
diff --git a/libguile/nio.c b/libguile/nio.c
index bebb059..b8541b7 100644
--- a/libguile/nio.c
+++ b/libguile/nio.c
@@ -169,6 +169,37 @@ scm_nio_accept (SCM fd)
}
#undef FUNC_NAME
+/* Initiate a connection from a socket.
+
+ The second argument should be a socket address object as returned by
+ @code{make-socket-address}.
+
+ Returns @code{#t} if the connection succeeded immediately, and
+ @code{#f} otherwise. */
+static SCM
+scm_nio_connect (SCM fd, SCM sockaddr)
+#define FUNC_NAME "nio-connect"
+{
+ int c_fd, rv, save_errno;
+ struct sockaddr *soka;
+ size_t size;
+
+ c_fd = scm_to_int (fd);
+ soka = scm_to_sockaddr (sockaddr, &size);
+ rv = connect (c_fd, soka, size);
+ save_errno = errno;
+
+ if (rv == -1 && save_errno != EINPROGRESS)
+ {
+ free (soka);
+ errno = save_errno;
+ SCM_SYSERROR;
+ }
+ free (soka);
+ return scm_from_bool (rv == 0);
+}
+#undef FUNC_NAME
+
@@ -179,6 +210,7 @@ scm_init_nio (void)
scm_c_define_gsubr ("%nio-read", 4, 0, 0, scm_nio_read);
scm_c_define_gsubr ("%nio-write", 4, 0, 0, scm_nio_write);
scm_c_define_gsubr ("%nio-accept", 1, 0, 0, scm_nio_accept);
+ scm_c_define_gsubr ("%nio-connect", 2, 0, 0, scm_nio_connect);
}
void
diff --git a/module/ice-9/nio.scm b/module/ice-9/nio.scm
index b2f0e71..d69630d 100644
--- a/module/ice-9/nio.scm
+++ b/module/ice-9/nio.scm
@@ -20,7 +20,8 @@
(define-module (ice-9 nio)
#:export (nio-read
nio-write
- nio-accept))
+ nio-accept
+ nio-connect))
(eval-when (eval load compile)
(load-extension (string-append "libguile-" (effective-version))
@@ -44,3 +45,13 @@ read without blocking. A return value of 0 indicates EOF."
new client socket, unless the @code{accept} call would have blocked, in
which case return @code{#f}."
(%nio-accept fd))
+
+(define (nio-connect fd sockaddr)
+ "Initiate a connection from a socket whose file descriptor is
address@hidden The second argument should be a socket address object as
+returned by @code{make-socket-address}. Returns @code{#t} if the
+connection succeeded immediately, and @code{#f} otherwise.
+
+Once this socket becomes writable, it is ready. If there was a
+connection error, it can be retrieved with getsockopt of SO_ERROR."
+ (%nio-connect fd sockaddr))
- [Guile-commits] branch wip-ethreads created (now 4dc952f), Andy Wingo, 2016/03/24
- [Guile-commits] 04/23: add (ice-9 ethreads), Andy Wingo, 2016/03/24
- [Guile-commits] 09/23: eports: some more exports, Andy Wingo, 2016/03/24
- [Guile-commits] 12/23: (web server ethreads): Use a large backlog., Andy Wingo, 2016/03/24
- [Guile-commits] 13/23: add latin1 chars and strings to eports, Andy Wingo, 2016/03/24
- [Guile-commits] 18/23: (web server ethreads) TCP_NODELAY tweak, Andy Wingo, 2016/03/24
- [Guile-commits] 05/23: http: allow custom read-line / continuation-line? functions, Andy Wingo, 2016/03/24
- [Guile-commits] 06/23: setsockopt can take an fd, Andy Wingo, 2016/03/24
- [Guile-commits] 10/23: EOF fix for continuation-line?, Andy Wingo, 2016/03/24
- [Guile-commits] 19/23: nio: add non-blocking connect,
Andy Wingo <=
- [Guile-commits] 08/23: add #:limit to get-bytevector-delimited, Andy Wingo, 2016/03/24
- [Guile-commits] 11/23: socket: TCP_CORK, TCP_NODELAY, Andy Wingo, 2016/03/24
- [Guile-commits] 23/23: virtualize read/write/close operations in <eport>, Andy Wingo, 2016/03/24
- [Guile-commits] 15/23: (web server ethreads): more use of latin1 accessors, Andy Wingo, 2016/03/24
- [Guile-commits] 01/23: add (ice-9 nio), Andy Wingo, 2016/03/24
- [Guile-commits] 20/23: eports: nonblocking connect-eport, Andy Wingo, 2016/03/24
- [Guile-commits] 14/23: refactoring to (web server ethreads) read-http-line, Andy Wingo, 2016/03/24
- [Guile-commits] 02/23: add (ice-9 eports), Andy Wingo, 2016/03/24
- [Guile-commits] 17/23: getsockopt: allow raw file descriptors, Andy Wingo, 2016/03/24
- [Guile-commits] 16/23: eports: add put-utf8-char, put-utf8-string, Andy Wingo, 2016/03/24