X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=comstack%2Funix.c;h=960ccec437a738f711f7a94f353dc5f23cfee10d;hb=b08d68a3edac5a93dce61f98d2f030ea722311c4;hp=7666b29e4029320a964f9cca62ef6626da23fbad;hpb=f576c6403441fc35f85a3e57f9423ff07d052de1;p=yaz-moved-to-github.git diff --git a/comstack/unix.c b/comstack/unix.c index 7666b29..960ccec 100644 --- a/comstack/unix.c +++ b/comstack/unix.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: unix.c,v 1.2 2002-06-18 21:30:38 adam Exp $ + * $Id: unix.c,v 1.7 2002-09-25 12:37:07 adam Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ #ifndef WIN32 @@ -26,6 +26,10 @@ /* Chas added the following, so we get the definition of completeBER */ #include +#ifndef YAZ_SOCKLEN_T +#define YAZ_SOCKLEN_T int +#endif + int unix_close(COMSTACK h); int unix_put(COMSTACK h, char *buf, int size); int unix_get(COMSTACK h, char **buf, int *bufsize); @@ -43,6 +47,10 @@ COMSTACK unix_accept(COMSTACK h); char *unix_addrstr(COMSTACK h); void *unix_straddr(COMSTACK h, const char *str); +#ifndef SUN_LEN +#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ + + strlen ((ptr)->sun_path)) +#endif #if 0 #define TRC(x) x #else @@ -143,11 +151,15 @@ COMSTACK unix_type(int s, int blocking, int protocol, void *vp) int unix_strtoaddr_ex(const char *str, struct sockaddr_un *add) { + char *cp; if (!unix_init ()) return 0; TRC(fprintf(stderr, "unix_strtoaddress: %s\n", str ? str : "NULL")); add->sun_family = AF_UNIX; strncpy(add->sun_path, str, sizeof(add->sun_path)); + cp = strchr (add->sun_path, ':'); + if (cp) + *cp = '\0'; return 1; } @@ -201,7 +213,7 @@ int unix_connect(COMSTACK h, void *address) r = connect(h->iofile, (struct sockaddr *) add, SUN_LEN(add)); if (r < 0) { - if (errno == EINPROGRESS) + if (yaz_errno() == EINPROGRESS) { h->event = CS_CONNECT; h->state = CS_ST_CONNECTING; @@ -252,7 +264,7 @@ int unix_bind(COMSTACK h, void *address, int mode) int socket_out = -1; if(! S_ISSOCK(stat_buf.st_mode)) { h->cerrno = CSYSERR; - errno = EEXIST; /* Not a socket (File exists) */ + yaz_set_errno(EEXIST); /* Not a socket (File exists) */ return -1; } if((socket_out = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { @@ -262,7 +274,7 @@ int unix_bind(COMSTACK h, void *address, int mode) socket_unix.sun_family = AF_UNIX; strncpy(socket_unix.sun_path, path, sizeof(socket_unix.sun_path)); if(connect(socket_out, (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix)) < 0) { - if(errno == ECONNREFUSED) { + if(yaz_errno() == ECONNREFUSED) { TRC (fprintf (stderr, "Socket exists but nobody is listening\n")); } else { h->cerrno = CSYSERR; @@ -271,7 +283,7 @@ int unix_bind(COMSTACK h, void *address, int mode) } else { close(socket_out); h->cerrno = CSYSERR; - errno = EADDRINUSE; + yaz_set_errno(EADDRINUSE); return -1; } unlink(path); @@ -297,11 +309,7 @@ int unix_listen(COMSTACK h, char *raddr, int *addrlen, void *cd) { struct sockaddr_un addr; -#ifdef __cplusplus - socklen_t len = SUN_LEN(&addr); -#else - int len = SUN_LEN(&addr); -#endif + YAZ_SOCKLEN_T len = SUN_LEN(&addr); TRC(fprintf(stderr, "unix_listen pid=%d\n", getpid())); if (h->state != CS_ST_IDLE) @@ -313,10 +321,10 @@ int unix_listen(COMSTACK h, char *raddr, int *addrlen, if (h->newfd < 0) { if ( - errno == EWOULDBLOCK + yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif ) @@ -443,19 +451,19 @@ int unix_get(COMSTACK h, char **buf, int *bufsize) TRC(fprintf(stderr, " recv res=%d, hasread=%d\n", res, hasread)); if (res < 0) { - if (errno == EWOULDBLOCK + if (yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif - || errno == EINPROGRESS + || yaz_errno() == EINPROGRESS ) { h->io_pending = CS_WANT_READ; break; } - else if (errno == 0) + else if (yaz_errno() == 0) continue; else return -1; @@ -527,10 +535,10 @@ int unix_put(COMSTACK h, char *buf, int size) )) < 0) { if ( - errno == EWOULDBLOCK + yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif )