X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=comstack%2Funix.c;h=4efed2736b133aefe7c792fefacde957c75d5a8f;hp=908ab7e6b780a4b46b2118ce47ee0aa8a120b667;hb=c71d717ada2a9ef730d527f161eb5ba9aa641a9f;hpb=4d531a1a9131d69c3b6c27fbac42837e22cff61c diff --git a/comstack/unix.c b/comstack/unix.c index 908ab7e..4efed27 100644 --- a/comstack/unix.c +++ b/comstack/unix.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: unix.c,v 1.9 2003-01-06 08:20:27 adam Exp $ + * $Id: unix.c,v 1.14 2003-10-08 21:47:15 adam Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ #ifndef WIN32 @@ -22,9 +22,7 @@ #include #include #include - -/* Chas added the following, so we get the definition of completeBER */ -#include +#include #ifndef YAZ_SOCKLEN_T #define YAZ_SOCKLEN_T int @@ -42,7 +40,6 @@ static int unix_listen(COMSTACK h, char *raddr, int *addrlen, void *cd); static int unix_set_blocking(COMSTACK p, int blocking); - static COMSTACK unix_accept(COMSTACK h); static char *unix_addrstr(COMSTACK h); static void *unix_straddr(COMSTACK h, const char *str); @@ -102,7 +99,7 @@ COMSTACK unix_type(int s, int blocking, int protocol, void *vp) xmalloc(sizeof(unix_state))))) return 0; - if (!(p->blocking = blocking)) + if (!((p->blocking = blocking)&1)) { if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) return 0; @@ -140,7 +137,7 @@ COMSTACK unix_type(int s, int blocking, int protocol, void *vp) if (protocol == PROTO_WAIS) state->complete = completeWAIS; else - state->complete = completeBER; + state->complete = cs_complete_auto; p->timeout = COMSTACK_DEFAULT_TIMEOUT; TRC(fprintf(stderr, "Created new UNIX comstack\n")); @@ -294,6 +291,7 @@ static int unix_bind(COMSTACK h, void *address, int mode) h->cerrno = CSYSERR; return -1; } + chmod(path, 0777); if (mode == CS_SERVER && listen(h->iofile, 3) < 0) { h->cerrno = CSYSERR; @@ -309,7 +307,7 @@ static int unix_listen(COMSTACK h, char *raddr, int *addrlen, void *cd) { struct sockaddr_un addr; - YAZ_SOCKLEN_T len = SUN_LEN(&addr); + YAZ_SOCKLEN_T len = sizeof(addr); TRC(fprintf(stderr, "unix_listen pid=%d\n", getpid())); if (h->state != CS_ST_IDLE) @@ -370,8 +368,8 @@ static COMSTACK unix_accept(COMSTACK h) } return 0; } - if (!cnew->blocking && - (!cnew->blocking && fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0) + if (!(cnew->blocking&1) && + (fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0) ) { h->cerrno = CSYSERR; @@ -389,6 +387,7 @@ static COMSTACK unix_accept(COMSTACK h) state->altsize = state->altlen = 0; state->towrite = state->written = -1; state->complete = st->complete; + memcpy(&state->addr, &st->addr, sizeof(state->addr)); cnew->state = CS_ST_ACCEPT; cnew->event = CS_NONE; h->state = CS_ST_IDLE;