3
@node A VU Handler for the URL Socket Scheme
4
@chapter A VU Handler for the URL Socket Scheme
6
These functions provide VU namespace handlers for file-names
7
that designate various kinds of sockets. By using these handlers,
8
your programs can (almost) transparently handle filenames
13
inet://myserver.host.com:10000
24
unix:/tmp/.X11-unix/X0
30
Two kinds of sockets are available: @emph{server} sockets and @emph{client}
34
@geindex server sockets
35
@dfn{server sockets} are created with @code{socket(2)}, @code{bind(2)}, and
36
@code{listen(2)}. When @code{vu_open} is called, a call to @code{listen(2)} is
37
made and the client connection (if any) is returned.
40
@geindex client sockets
41
@dfn{client sockets} are created with @code{socket(2)}, @code{bind(2)}, and
45
Sockets may be named in either the @code{unix} or @code{inet} domains.
48
The syntax of these URLs is described in the documentation for
49
@code{url_socket_push_client_handler} and
50
@code{url_socket_push_socket_handler}.
55
@b{* Function} @code{url_socket_push_client_handler}@fuindex url_socket_push_client_handler
59
void url_socket_push_client_handler (enum url_socket_domains domains,
67
Push a VU namespace handler for client sockets.
72
------------------------------------------------------------------
73
url_socket_unix unix:$PATH
74
url_socket_inet inet://$HOST[:$PORT]
75
url_socket_inet_or_unix unix:$PATH or inet://$HOST[:$PORT]
81
Note that the @code{$PATH} of a unix domain socket is subject to @geindex ~
83
using @code{file_name_tilde_expand}.
86
(See @strong{file_name_tilde_expand} in @ref{Home Directories}.)
89
@code{default_port} is used for internet-domain sockets.
92
If @code{is_optional} is @code{0}, the handler is immediately added to the VU namespace.
93
If @code{is_optional} is not @code{0}, the handler is added to the list of optional
94
handlers and may be enabled by @code{vu_enable_optional_name_handler}.
97
(See @strong{vu_enable_optional_name_handler} in @ref{Establishing VU Handlers}.)
101
Domains: Optional Handler Name:
102
------------------------------------------------------------------
103
url_socket_unix client/unix
104
url_socket_inet client/inet
105
url_socket_inet_or_unix client/any
113
@b{* Function} @code{url_socket_push_socket_handler}@fuindex url_socket_push_socket_handler
117
void url_socket_push_socket_handler
118
(enum url_socket_domains domains,
128
url_socket_server_callback server_callback,
129
url_socket_connect_callback connection_callback,
130
url_socket_server_close_callback server_close_callback,
138
Push a VU namespace handler for server sockets. After this call, a
139
call to @code{vu_open} with a suitable file name will work by creating a
143
@code{server_flags} may be any bitwise combination of:
147
O_NONBLOCK # Don't block waiting for connections.
153
There are two kinds of file name patterns: those that can be used
154
to name both clients and servers, and those that can only be used
159
server only: client or server:
160
-------------------------------------------------
161
unix-server:$PATH unix:$PATH
162
inet-server://$HOST[:$PORT] inet://$HOST[:$PORT]
168
By default, both kinds of URL are accepted and interpreted as names
169
of server sockets. Note that:
173
`$PATH' of a unix domain socket is subject to "~" expansion using
174
`file_name_tilde_expand'.
181
`$HOST' of an internet-domain socket may be `INADDR_LOOPBACK'.
182
If the URL is the name of a server, `$HOST' may also be
183
`INADDR_ANY'. (See `inet(4)'.)
190
`$PORT' of an internet-domain server may be 0, meaning that the
191
system should assign a port number which will be reported in
192
the server callback in the `server_addr' parameter (see below).
198
If @code{may_be_client} is not @code{0}, then accept both kinds of URLs, but
199
interpret @geindex client or server
200
@dfn{client or server} URLs as naming client sockets (your
201
process will open a connection to some other server).
204
If @code{only_server_url} is not @code{0}, then accept @geindex server only
205
@dfn{server only} URLs, but
206
not @geindex client or server
207
@dfn{client or server} URLs. In this case, @code{may_be_client} is
208
ignored. This is especially useful in combination with
209
@code{url_socket_push_client_handler} and other calls to
210
@code{vu_push_name_handler}.
213
@code{default_port} is used when creating an internet-domain socket for
214
which the port number was not specified in the file-name.
217
@code{backlog} is used for the call to @code{listen(2)}.
220
@code{server_callback} is called when a new server socket has been
221
created successfully. It's arguments are explained below.
224
@code{connect_callback} is called when a new connection has been
225
received. It's arguments are explained below.
228
@code{server_close_callback} is called when the server descriptor
229
is closed. It's arguments are explained below.
232
@code{closure} is an opaque value passed to the callback functions.
235
If @code{is_optional} is @code{0}, the handler is immediately added to the VU namespace.
236
If @code{is_optional} is non-0, the handler is added to the list of optional
237
handlers and may be enabled by @code{vu_enable_optional_name_handler}.
241
domain(s) only_server_url may_be_client Optional Handler Name
242
--------------------------------------------------------------------
245
inet_or_unix 0 0 server/any
252
inet_or_unix 0 1 socket/any
253
unix 1 * socket/unix-server
254
inet 1 * socket/inet-server
255
inet_or_unix 1 * socket/any-server
261
@strong{Calling Conventions for Callbacks}
265
typedef void (*url_socket_server_callback) (char * path,
270
struct sockaddr * server_addr,
279
`path' is the file name that caused the server socket to
287
`server_flags' is 0 or a bit-wise combination of `O_NONBLOCK'.
294
`flags' is the `flags' parameter passed to `vu_open', if this
295
server socket was created by a call to `vu_open', 0 otherwise.
302
`mode' is the `mode' parameter passed to `vu_open', if this
303
server socket was created by a call to `vu_open', 0 otherwise.
310
`server_fd' is the descriptor number of the server socket.
317
`server_addr' and `server_addr_len' is the address passed to
325
`closure' is the `closure' argument passed to
326
`url_socket_push_socket_handler'.
333
typedef void (*url_socket_connect_callback)
339
struct sockaddr * client_addr,
348
`path' is the file name that caused the client connection to this
349
server to be created.
356
`flags' is the `flags' parameter passed to `vu_open'.
363
`mode' is the `mode' parameter passed to `vu_open'.
370
`server_fd' is the descriptor number of the server socket.
377
`connection_fd' is the descriptor number of the client connection.
384
`client_addr' and `client_addr_len' is the address from `accept'.
391
`closure' is the `closure' argument passed to
392
`url_socket_push_socket_handler'.
399
typedef void (*url_socket_server_close_callback)
401
struct sockaddr * server_addr,
410
`server_fd' is the descriptor number of the server socket.
417
`server_addr' and `server_addr_len' is the address passed to
425
`closure' is the `closure' argument passed to
426
`url_socket_push_socket_handler'.