Ticket #787: unix-sockets-pair.diff.txt

File unix-sockets-pair.diff.txt, 1.7 KB (added by Jim Ursetto, 14 years ago)
Line 
1# HG changeset patch
2# User Jim Ursetto <jim@3e8.org>
3# Date 1329005031 21600
4# Node ID 6283ea4b16138c7e06bba7987620a10203cd06f0
5# Parent 71549a2c37f7bf8a29006dde81cf5d15f45f64d4
6add unix-pair
7
8diff --git a/unix-sockets.scm b/unix-sockets.scm
9--- a/unix-sockets.scm
10+++ b/unix-sockets.scm
11@@ -42,7 +42,8 @@
12 unix-listener-fileno unix-listener-path
13 unix-close
14 unix-listener?
15- unix-listen)
16+ unix-listen
17+ unix-pair)
18
19 ;; TODO: errno should be accessed using the proper API?
20 (import scheme (except chicken errno) easyffi foreign)
21@@ -126,6 +127,19 @@
22
23 return s2;
24 }
25+
26+static int
27+create_socket_pair(___out int *s2)
28+{
29+ int s1, rc;
30+ int pair[2];
31+ rc = socketpair(PF_LOCAL, SOCK_STREAM, 0, pair);
32+ if (rc < 0) return -1;
33+ s1 = pair[0];
34+ *s2 = pair[1];
35+ return s1;
36+}
37+
38 <#
39
40
41@@ -152,6 +166,14 @@
42 (unix-error 'unix-connect "can not connect" filename)
43 (io-ports 'unix-connect n) ) ) )
44
45+(define (unix-pair)
46+ (let-values (((s1 s2) (create_socket_pair)))
47+ (if (negative? s1)
48+ (unix-error 'unix-pair "cannot create socket pair")
49+ (let-values (((i1 o1) (io-ports 'unix-pair s1))
50+ ((i2 o2) (io-ports 'unix-pair s2)))
51+ (values i1 o1 i2 o2)))))
52+
53 (define-constant +buffer-size+ 1024)
54
55 (define make-nonblocking
56# HG changeset patch
57# User Jim Ursetto <jim@3e8.org>
58# Date 1329005059 21600
59# Node ID 6ed0828a79bdde0c2d01a0fc0add6efa2766cd51
60# Parent 6283ea4b16138c7e06bba7987620a10203cd06f0
61bump to 1.7
62
63diff --git a/unix-sockets.setup b/unix-sockets.setup
64--- a/unix-sockets.setup
65+++ b/unix-sockets.setup
66@@ -7,4 +7,4 @@
67 (install-extension
68 'unix-sockets
69 '("unix-sockets.so" "unix-sockets.import.so")
70- '((version 1.6)))
71+ '((version 1.7)))