[GRASS5] G_socks_* unix socket wrapper functions...
Eric G . Miller
egm2 at jps.net
Sat Jan 27 22:20:38 EST 2001
I've been playing around with a few small library type functions for
creating and using UNIX domain sockets in GRASS. The basic idea is
that all such sockets could have the socket file created in the user's
current mapset tempdir, then detached processes or modules could use
these functions to set-up communications channels (I'm thinking alot
about this FIFO vs. IPC thing for the Raster/Display libes).
Anyway, here's a short run-down on the functions. I've only done a
simple test of them, but so far they work right. All functions that
take a "name" paramater want a full path, except G_sock_get_fname()
which will build the path. This way, code can just say:
mon = G_sock_get_fname ("x0");
and then use "mon" for other calls. I'll upload this to libes/gis if
there's interest. Will require adding <sys/un.h> as an include in
gis.h for the G_sock_accept() function.
/* ----------------------------------------------------------------------
* G_sock_get_fname(), builds the full path for a UNIX socket using the
* G__temp_element() routine (tempfile.c). Caller should free() the
* return value when it is no longer needed.
* ---------------------------------------------------------------------*/
char *
G_sock_get_fname (char *name)
/* -------------------------------------------------------------------
* G_sock_exists(char *): Returns 1 if path is to a UNIX socket that
* already exists, 0 otherwise.
* -------------------------------------------------------------------*/
int
G_sock_exists (char *name)
/* -----------------------------------------------------------------
* G_sock_bind (char *): Takes the full pathname for a UNIX socket
* and returns the file descriptor to the socket after a successful
* call to bind(). On error, it returns -1
* ----------------------------------------------------------------*/
int
G_sock_bind (char *name)
/* ---------------------------------------------------------------------
* G_sock_listen(int, unsigned int): Wrapper around the listen()
* function.
* --------------------------------------------------------------------*/
int
G_sock_listen (int sockfd, unsigned int queue_len)
/* -----------------------------------------------------------------------
* G_sock_accept (int sockfd, struct sockaddr_un *caddr, socklen_t *clen):
* Wrapper around the accept() function. Both *caddr, and *clen can be
* NULL if the server doesn't care about this info. Function returns
* the file descriptor or an error code generated by accept(). Note,
* this call will usually block until a connection arrives. You can use
* select() for a time out on the call.
* ---------------------------------------------------------------------*/
int
G_sock_accept (int sockfd, struct sockaddr_un *caddr, socklen_t *clen)
/* ----------------------------------------------------------------------
* G_sock_connect (char *name): Tries to connect to the unix socket
* specified by "name". Returns the file descriptor if successful, or
* -1 if unsuccessful. Global errno is set by connect() if return is -1.
* --------------------------------------------------------------------*/
int
G_sock_connect (char *name)
--
Eric G. Miller <egm2 at jps.net>
----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'
More information about the grass-dev
mailing list