Fix sample PQF
[yaz-moved-to-github.git] / comstack / unix.c
index bfd6de1..4efed27 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: unix.c,v 1.10 2003-02-21 12:08: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,6 +22,7 @@
 #include <yaz/comstack.h>
 #include <yaz/unix.h>
 #include <yaz/log.h>
+#include <yaz/nmem.h>
 
 #ifndef YAZ_SOCKLEN_T
 #define YAZ_SOCKLEN_T int
@@ -39,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);
@@ -99,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;
@@ -291,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;
@@ -306,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)
@@ -367,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;
@@ -386,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;