Fix sample PQF
[yaz-moved-to-github.git] / comstack / unix.c
index 235c9b1..4efed27 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Copyright (c) 1995-2002, Index Data
+ * Copyright (c) 1995-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: unix.c,v 1.8 2002-12-15 21:22:58 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 <yaz/comstack.h>
 #include <yaz/unix.h>
 #include <yaz/log.h>
-
-/* Chas added the following, so we get the definition of completeBER */
-#include <yaz/odr.h>
+#include <yaz/nmem.h>
 
 #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;