# HG changeset patch # User Jim Ursetto # Date 1329005031 21600 # Node ID 6283ea4b16138c7e06bba7987620a10203cd06f0 # Parent 71549a2c37f7bf8a29006dde81cf5d15f45f64d4 add unix-pair diff --git a/unix-sockets.scm b/unix-sockets.scm --- a/unix-sockets.scm +++ b/unix-sockets.scm @@ -42,7 +42,8 @@ unix-listener-fileno unix-listener-path unix-close unix-listener? - unix-listen) + unix-listen + unix-pair) ;; TODO: errno should be accessed using the proper API? (import scheme (except chicken errno) easyffi foreign) @@ -126,6 +127,19 @@ return s2; } + +static int +create_socket_pair(___out int *s2) +{ + int s1, rc; + int pair[2]; + rc = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair); + if (rc < 0) return -1; + s1 = pair[0]; + *s2 = pair[1]; + return s1; +} + <# @@ -152,6 +166,14 @@ (unix-error 'unix-connect "can not connect" filename) (io-ports 'unix-connect n) ) ) ) +(define (unix-pair) + (let-values (((s1 s2) (create_socket_pair))) + (if (negative? s1) + (unix-error 'unix-pair "cannot create socket pair") + (let-values (((i1 o1) (io-ports 'unix-pair s1)) + ((i2 o2) (io-ports 'unix-pair s2))) + (values i1 o1 i2 o2))))) + (define-constant +buffer-size+ 1024) (define make-nonblocking # HG changeset patch # User Jim Ursetto # Date 1329005059 21600 # Node ID 6ed0828a79bdde0c2d01a0fc0add6efa2766cd51 # Parent 6283ea4b16138c7e06bba7987620a10203cd06f0 bump to 1.7 diff --git a/unix-sockets.setup b/unix-sockets.setup --- a/unix-sockets.setup +++ b/unix-sockets.setup @@ -7,4 +7,4 @@ (install-extension 'unix-sockets '("unix-sockets.so" "unix-sockets.import.so") - '((version 1.6))) + '((version 1.7)))