X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ftcpip.c;h=f6796373d51640401612aa742c7b541ff63839d0;hp=896eaf3d4da542a4b7cdc76ae6d2e5b0002f60f7;hb=c9c54c9f75cfea59f26489d1b0ef011dafa4297e;hpb=dc86a5103817732735d2591d3775114a86de94ae diff --git a/src/tcpip.c b/src/tcpip.c index 896eaf3..f679637 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -84,11 +84,6 @@ static int tcpip_listen(COMSTACK h, char *raddr, int *addrlen, void *cd); static int tcpip_set_blocking(COMSTACK p, int blocking); -#if HAVE_GNUTLS_H -static int ssl_put(COMSTACK h, char *buf, int size); -#endif - - #if HAVE_GETADDRINFO struct addrinfo *tcpip_getaddrinfo(const char *str, const char *port, int *ipv6_only); @@ -334,7 +329,6 @@ COMSTACK ssl_type(int s, int flags, int protocol, void *vp) p = tcpip_type(s, flags, protocol, 0); if (!p) return 0; - p->f_put = ssl_put; p->type = ssl_type; sp = (tcpip_state *) p->cprivate; @@ -1025,7 +1019,9 @@ COMSTACK tcpip_accept(COMSTACK h) TRC(fprintf(stderr, "tcpip_accept h=%p pid=%d\n", h, getpid())); if (h->state == CS_ST_INCON) { +#if HAVE_GNUTLS_H tcpip_state *st = (tcpip_state *)h->cprivate; +#endif tcpip_state *state = tcpip_state_create(); cnew = (COMSTACK) xmalloc(sizeof(*cnew)); @@ -1185,7 +1181,6 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) break; return -1; } - hasread += res; } else #endif @@ -1235,12 +1230,12 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) h->cerrno = CSYSERR; return -1; } +#endif } else if (!res) return hasread; - hasread += res; -#endif } + hasread += res; if (hasread > h->max_recv_bytes) { h->cerrno = CSBUFSIZE; @@ -1296,6 +1291,7 @@ int tcpip_put(COMSTACK h, char *buf, int size) { state->towrite = size; state->written = 0; + state->altlen = 0; /* reset input buf in case of excess bytes YAZ-830 */ } else if (state->towrite != size) { @@ -1304,88 +1300,60 @@ int tcpip_put(COMSTACK h, char *buf, int size) } while (state->towrite > state->written) { - if ((res = - send(h->iofile, buf + state->written, size - - state->written, +#if HAVE_GNUTLS_H + if (state->session) + { + res = gnutls_record_send(state->session, buf + state->written, + size - state->written); + if (res <= 0) + { + if (ssl_check_error(h, state, res)) + return 1; + return -1; + } + } + else +#endif + { + if ((res = + send(h->iofile, buf + state->written, size - + state->written, #ifdef MSG_NOSIGNAL - MSG_NOSIGNAL + MSG_NOSIGNAL #else - 0 + 0 #endif - )) < 0) - { - if ( + )) < 0) + { + if ( #ifdef WIN32 - WSAGetLastError() == WSAEWOULDBLOCK + WSAGetLastError() == WSAEWOULDBLOCK #else - yaz_errno() == EWOULDBLOCK + yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || yaz_errno() == EAGAIN + || yaz_errno() == EAGAIN #endif #endif #ifdef __sun__ - || yaz_errno() == ENOENT /* Sun's sometimes set errno to this value! */ + || yaz_errno() == ENOENT /* Sun's sometimes set errno to this value! */ #endif - || yaz_errno() == EINPROGRESS + || yaz_errno() == EINPROGRESS #endif - ) - { - TRC(fprintf(stderr, " Flow control stop\n")); - h->io_pending = CS_WANT_WRITE; - return 1; - } - if (h->flags & CS_FLAGS_BLOCKING) - { - h->cerrno = CSYSERR; - return -1; + ) + { + TRC(fprintf(stderr, " Flow control stop\n")); + h->io_pending = CS_WANT_WRITE; + return 1; + } + if (h->flags & CS_FLAGS_BLOCKING) + { + h->cerrno = CSYSERR; + return -1; + } + else + return cont_connect(h); } - else - return cont_connect(h); - } - state->written += res; - TRC(fprintf(stderr, " Wrote %d, written=%d, nbytes=%d\n", - res, state->written, size)); - } - state->towrite = state->written = -1; - TRC(fprintf(stderr, " Ok\n")); - return 0; -} - - -#if HAVE_GNUTLS_H -/* - * Returns 1, 0 or -1 - * In nonblocking mode, you must call again with same buffer while - * return value is 1. - */ -int ssl_put(COMSTACK h, char *buf, int size) -{ - int res; - struct tcpip_state *state = (struct tcpip_state *)h->cprivate; - - TRC(fprintf(stderr, "ssl_put: size=%d\n", size)); - h->io_pending = 0; - h->event = CS_DATA; - if (state->towrite < 0) - { - state->towrite = size; - state->written = 0; - } - else if (state->towrite != size) - { - h->cerrno = CSWRONGBUF; - return -1; - } - while (state->towrite > state->written) - { - res = gnutls_record_send(state->session, buf + state->written, - size - state->written); - if (res <= 0) - { - if (ssl_check_error(h, state, res)) - return 1; - return -1; } state->written += res; TRC(fprintf(stderr, " Wrote %d, written=%d, nbytes=%d\n", @@ -1395,7 +1363,6 @@ int ssl_put(COMSTACK h, char *buf, int size) TRC(fprintf(stderr, " Ok\n")); return 0; } -#endif void tcpip_close(COMSTACK h) {