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

Last change on this file since 22329 was 22329, checked in by svnwiki, 10 years ago

Anonymous wiki edit for IP [216.107.215.226]: a small gotcha involving sigpipe

File size: 3.7 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=== Gotchas
64
65If 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]].
66
67=== Changelog
68
69* 1.4 Do not import errno, to make it compatible with Chicken 4.1.0
70* 1.3 Applied bugfix by Shawn Wagner
71* 1.2 Added include for sys/time.h, which is needed on some systems [Thanks to Kon Lovett]
72* 1.1 Replaced use of {{(end-of-file)}} with {{#!eof}}
73* 1.0 Initial release
74
75=== License
76
77  Copyright (c) 2005, Felix L. Winkelmann
78  All rights reserved.
79 
80  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
81  conditions are met:
82 
83    Redistributions of source code must retain the above copyright notice, this list of conditions and the following
84      disclaimer.
85    Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
86      disclaimer in the documentation and/or other materials provided with the distribution.
87    Neither the name of the author nor the names of its contributors may be used to endorse or promote
88      products derived from this software without specific prior written permission.
89 
90  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
91  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
92  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
93  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
94  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
95  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
96  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
97  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
98  POSSIBILITY OF SUCH DAMAGE.
Note: See TracBrowser for help on using the repository browser.