source: project/wiki/eggref/4/unix-sockets @ 27292

Last change on this file since 27292 was 27292, checked in by felix winkelmann, 9 years ago

unix-sockets wiki-page update

File size: 4.0 KB
Line 
1[[tags: egg]]
2
3== unix-sockets
4
5[[toc:]]
6
7=== Description
8
9Simple access to UNIX domain sockets.
10
11=== Author
12
13[[/users/felix winkelmann|felix winkelmann]]
14
15=== Requirements
16
17[[easyffi]]
18
19=== Documentation
20
21The interface is similar to the builtin TCP socket functionality in CHICKEN.
22
23<procedure>(unix-listen PATHNAME [BACKLOG])</procedure>
24
25Creates a socket listener object. {{PATHNAME}} gives the name of the
26file that represents the connection. {{BACKLOG}} specifies how many
27pending connections are allowed and defaults to 10.
28
29<procedure>(unix-listener? X)</procedure>
30
31Returns {{#t}} if {{X}} is a unix socket listener object, or {{#f}} otherwise.
32
33<procedure>(unix-close LISTENER)</procedure>
34
35Closes the socket associated with the listener object.
36
37<procedure>(unix-accept LISTENER)</procedure>
38
39Waits for a connection from a client and returns two values: an input-
40and output-port which can be used to communicate with the connecting
41process. Calling {{unix-accept}} does not block other threads from
42running.
43
44<procedure>(unix-accept-ready? LISTENER)</procedure>
45
46Returns {{#t}} if a {{unix-accept}} for this listener would not block the current thread, or {{#f}}
47otherwise.
48
49
50<procedure>(unix-connect PATHNAME)</procedure>
51
52Connects to the socket given in {{PATHNAME}} and returns two values: an input- and output-port
53which allow communication with the server.
54
55<procedure>(unix-listener-fileno LISTENER)</procedure>
56
57Returns the file-descriptor of the socket associated with the given listener object.
58
59<procedure>(unix-listener-path LISTENER)</procedure>
60
61Returns the pathname of the socket associated with the given listener object.
62
63<procedure>(unix-pair)</procedure>
64
65Create a pair of connected sockets and returns four values: an input-
66and output-port for the first socket, and the same for the second
67socket.  These ports can be used for bidirectional communication
68between a parent and child process, for example.
69
70=== Gotchas
71
72If you try to write to the socket's output port when the other side has shut down the socket, a SIGPIPE will be generated. The application must handle or ignore the signal (see [[posix]]); once the signal is dealt with, the write attempt will raise an exception of its own using {{signal}} from [[Exceptions]].
73
74=== Changelog
75
76* 1.7 Add {{unix-pair}}
77* 1.4 Do not import errno, to make it compatible with Chicken 4.1.0
78* 1.3 Applied bugfix by Shawn Wagner
79* 1.2 Added include for sys/time.h, which is needed on some systems [Thanks to Kon Lovett]
80* 1.1 Replaced use of {{(end-of-file)}} with {{#!eof}}
81* 1.0 Initial release
82
83=== License
84
85  Copyright (c) 2005, Felix L. Winkelmann
86  All rights reserved.
87 
88  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
89  conditions are met:
90 
91    Redistributions of source code must retain the above copyright notice, this list of conditions and the following
92      disclaimer.
93    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
94      disclaimer in the documentation and/or other materials provided with the distribution.
95    Neither the name of the author nor the names of its contributors may be used to endorse or promote
96      products derived from this software without specific prior written permission.
97 
98  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
99  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
100  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
101  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
102  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
103  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
104  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
105  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
106  POSSIBILITY OF SUCH DAMAGE.
Note: See TracBrowser for help on using the repository browser.