From bef6611df76c31df3c12bfe3f16084133ad5b52a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 8 Oct 2003 21:47:15 +0000 Subject: [PATCH] Use bitmask for COMSTACK blocking parameter. Bit 0 (&1) controls whether socket is blocking or not. Bit 1 (&2) specifies whether reverse lookup should be performed in cs_addrstr; 0=full/slow ; 1=IP/fast. --- comstack/tcpip.c | 28 +++++++++++++++------------- comstack/unix.c | 9 ++++----- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 3d69f70..ab08873 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: tcpip.c,v 1.58 2003-05-20 20:33:29 adam Exp $ + * $Id: tcpip.c,v 1.59 2003-10-08 21:47:15 adam Exp $ */ #include @@ -134,19 +134,19 @@ COMSTACK tcpip_type(int s, int blocking, int protocol, void *vp) xmalloc(sizeof(tcpip_state))))) return 0; + if (!((p->blocking = blocking)&1)) + { #ifdef WIN32 - if (!(p->blocking = blocking) && ioctlsocket(s, FIONBIO, &tru) < 0) - return 0; + if (ioctlsocket(s, FIONBIO, &tru) < 0) + return 0; #else - if (!(p->blocking = blocking)) - { if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) return 0; #ifndef MSG_NOSIGNAL signal (SIGPIPE, SIG_IGN); #endif - } #endif + } p->io_pending = 0; p->iofile = s; @@ -606,11 +606,11 @@ COMSTACK tcpip_accept(COMSTACK h) } return 0; } - if (!cnew->blocking && + if (!(cnew->blocking&1) && #ifdef WIN32 (ioctlsocket(cnew->iofile, FIONBIO, &tru) < 0) #else - (!cnew->blocking && fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0) + (fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0) #endif ) { @@ -1043,7 +1043,7 @@ char *tcpip_addrstr(COMSTACK h) { struct sockaddr_in addr; tcpip_state *sp = (struct tcpip_state *)h->cprivate; - char *r, *buf = sp->buf; + char *r = 0, *buf = sp->buf; YAZ_SOCKLEN_T len; struct hostent *host; @@ -1053,10 +1053,12 @@ char *tcpip_addrstr(COMSTACK h) h->cerrno = CSYSERR; return 0; } - if ((host = gethostbyaddr((char*)&addr.sin_addr, sizeof(addr.sin_addr), + if (!(h->blocking&2)) { + if ((host = gethostbyaddr((char*)&addr.sin_addr, sizeof(addr.sin_addr), AF_INET))) - r = (char*) host->h_name; - else + r = (char*) host->h_name; + } + if (!r) r = inet_ntoa(addr.sin_addr); if (h->protocol == PROTO_HTTP) sprintf(buf, "http:%s", r); @@ -1086,7 +1088,7 @@ int static tcpip_set_blocking(COMSTACK p, int blocking) return 0; #else flag = fcntl(p->iofile, F_GETFL, 0); - if(!blocking) + if(!(blocking&1)) flag = flag & ~O_NONBLOCK; else flag = flag | O_NONBLOCK; diff --git a/comstack/unix.c b/comstack/unix.c index 23c60ab..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.13 2003-09-16 20:48:28 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 @@ -40,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); @@ -100,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; @@ -369,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; -- 1.7.10.4