X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=comstack%2Ftcpip.c;h=ab08873e7921043b0ccfe2a762d09c351bbfc7b8;hb=6588b4176290d756fa422b9b93e297ddba3e22d8;hp=05b10dd1002885211dbf1e56fe30943b6e8f2a19;hpb=125af6f8db172ec8fd4c24dfe6f6ebeca49afacb;p=yaz-moved-to-github.git diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 05b10dd..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.57 2003-05-13 14:21:13 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 ) { @@ -726,8 +726,8 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) return -1; #ifdef __sun__ yaz_set_errno( 0 ); - // unfortunatly, sun sometimes forgets to set errno in recv - // when EWOULDBLOCK etc. would be required (res = -1) + /* unfortunatly, sun sometimes forgets to set errno in recv + when EWOULDBLOCK etc. would be required (res = -1) */ #endif res = recv(h->iofile, *buf + hasread, CS_TCPIP_BUFCHUNK, 0); TRC(fprintf(stderr, " recv res=%d, hasread=%d\n", res, hasread)); @@ -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;