Make private functions static
[yaz-moved-to-github.git] / comstack / tcpip.c
index dac5b2a..fa9a205 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2002, Index Data
  * See the file LICENSE for details.
  *
- * $Id: tcpip.c,v 1.46 2002-02-19 20:02:40 adam Exp $
+ * $Id: tcpip.c,v 1.51 2002-12-16 13:11:24 adam Exp $
  */
 
 #include <stdio.h>
 /* Chas added the following, so we get the definition of completeBER */
 #include <yaz/odr.h>
 
-int tcpip_close(COMSTACK h);
-int tcpip_put(COMSTACK h, char *buf, int size);
-int tcpip_get(COMSTACK h, char **buf, int *bufsize);
-int tcpip_connect(COMSTACK h, void *address);
-int tcpip_more(COMSTACK h);
-int tcpip_rcvconnect(COMSTACK h);
-int tcpip_bind(COMSTACK h, void *address, int mode);
-int tcpip_listen(COMSTACK h, char *raddr, int *addrlen,
+static int tcpip_close(COMSTACK h);
+static int tcpip_put(COMSTACK h, char *buf, int size);
+static int tcpip_get(COMSTACK h, char **buf, int *bufsize);
+static int tcpip_connect(COMSTACK h, void *address);
+static int tcpip_more(COMSTACK h);
+static int tcpip_rcvconnect(COMSTACK h);
+static int tcpip_bind(COMSTACK h, void *address, int mode);
+static int tcpip_listen(COMSTACK h, char *raddr, int *addrlen,
                 int (*check_ip)(void *cd, const char *a, int len, int type),
                 void *cd);
-int static tcpip_set_blocking(COMSTACK p, int blocking);
+static int tcpip_set_blocking(COMSTACK p, int blocking);
 
 #if HAVE_OPENSSL_SSL_H
-int ssl_get(COMSTACK h, char **buf, int *bufsize);
-int ssl_put(COMSTACK h, char *buf, int size);
+static int ssl_get(COMSTACK h, char **buf, int *bufsize);
+static int ssl_put(COMSTACK h, char *buf, int size);
 #endif
 
-COMSTACK tcpip_accept(COMSTACK h);
-char *tcpip_addrstr(COMSTACK h);
-void *tcpip_straddr(COMSTACK h, const char *str);
+static COMSTACK tcpip_accept(COMSTACK h);
+static char *tcpip_addrstr(COMSTACK h);
+static void *tcpip_straddr(COMSTACK h, const char *str);
 
 #if 0
 #define TRC(x) x
@@ -53,6 +53,10 @@ void *tcpip_straddr(COMSTACK h, const char *str);
 #define TRC(X)
 #endif
 
+#ifndef YAZ_SOCKLEN_T
+#define YAZ_SOCKLEN_T int
+#endif
+
 /* this state is used for both SSL and straight TCP/IP */
 typedef struct tcpip_state
 {
@@ -306,7 +310,7 @@ int tcpip_connect(COMSTACK h, void *address)
             return 1;
         }
 #else
-        if (errno == EINPROGRESS)
+        if (yaz_errno() == EINPROGRESS)
         {
             h->event = CS_CONNECT;
             h->state = CS_ST_CONNECTING;
@@ -449,11 +453,7 @@ int tcpip_listen(COMSTACK h, char *raddr, int *addrlen,
                 void *cd)
 {
     struct sockaddr_in addr;
-#ifdef __cplusplus
-    socklen_t len = sizeof(addr);
-#else
-    int len = sizeof(addr);
-#endif
+    YAZ_SOCKLEN_T len = sizeof(addr);
 
     TRC(fprintf(stderr, "tcpip_listen pid=%d\n", getpid()));
     if (h->state != CS_ST_IDLE)
@@ -468,10 +468,10 @@ int tcpip_listen(COMSTACK h, char *raddr, int *addrlen,
 #ifdef WIN32
            WSAGetLastError() == WSAEWOULDBLOCK
 #else
-           errno == EWOULDBLOCK 
+           yaz_errno() == EWOULDBLOCK 
 #ifdef EAGAIN
 #if EAGAIN != EWOULDBLOCK
-            || errno == EAGAIN
+            || yaz_errno() == EAGAIN
 #endif
 #endif
 #endif
@@ -672,19 +672,22 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize)
            else
                return -1;
 #else
-           if (errno == EWOULDBLOCK 
+           if (yaz_errno() == EWOULDBLOCK 
 #ifdef EAGAIN   
 #if EAGAIN != EWOULDBLOCK
-                || errno == EAGAIN
+                || yaz_errno() == EAGAIN
+#endif
 #endif
+               || yaz_errno() == EINPROGRESS
+#ifdef __sun__
+               || yaz_errno() == ENOENT /* Sun's sometimes set errno to this */
 #endif
-               || errno == EINPROGRESS
                )
            {
                h->io_pending = CS_WANT_READ;
                break;
            }
-           else if (errno == 0)
+           else if (yaz_errno() == 0)
                continue;
            else
                return -1;
@@ -844,10 +847,10 @@ int tcpip_put(COMSTACK h, char *buf, int size)
 #ifdef WIN32
                WSAGetLastError() == WSAEWOULDBLOCK
 #else
-               errno == EWOULDBLOCK 
+               yaz_errno() == EWOULDBLOCK 
 #ifdef EAGAIN
 #if EAGAIN != EWOULDBLOCK
-             || errno == EAGAIN
+             || yaz_errno() == EAGAIN
 #endif
 #endif
 #endif
@@ -965,7 +968,7 @@ char *tcpip_addrstr(COMSTACK h)
     struct sockaddr_in addr;
     tcpip_state *sp = (struct tcpip_state *)h->cprivate;
     char *r, *buf = sp->buf;
-    size_t len;
+    YAZ_SOCKLEN_T len;
     struct hostent *host;
     
     len = sizeof(addr);