From 4e687307f10bd595d8af05c022871d1875c8c463 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 22 Oct 2001 13:57:24 +0000 Subject: [PATCH] Implemented cs_rcvconnect and cs_look as described in the documentation. --- comstack/comstack.c | 10 ++++++++- comstack/tcpip.c | 57 +++++++++++++++++++++++++++++++++++++++++++----- doc/yaz.xml | 4 ++-- doc/yazhtml.dsl | 4 ++-- doc/yazphp.dsl | 4 ++-- doc/yazprint.dsl | 4 ++-- include/yaz/comstack.h | 8 +++---- 7 files changed, 73 insertions(+), 18 deletions(-) diff --git a/comstack/comstack.c b/comstack/comstack.c index 6a4cc05..b15eb5f 100644 --- a/comstack/comstack.c +++ b/comstack/comstack.c @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: comstack.c,v $ - * Revision 1.8 2001-07-19 19:49:02 adam + * Revision 1.9 2001-10-22 13:57:24 adam + * Implemented cs_rcvconnect and cs_look as described in the documentation. + * + * Revision 1.8 2001/07/19 19:49:02 adam * Added include of string.h. * * Revision 1.7 2001/03/21 12:43:36 adam @@ -100,3 +103,8 @@ COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp) } return cs; } + +int cs_look (COMSTACK cs) +{ + return cs->event; +} diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 9347e04..d3ddb3f 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: tcpip.c,v $ - * Revision 1.41 2001-10-12 21:49:26 adam + * Revision 1.42 2001-10-22 13:57:24 adam + * Implemented cs_rcvconnect and cs_look as described in the documentation. + * + * Revision 1.41 2001/10/12 21:49:26 adam * For accept/recv/send check for EAGAIN if it's differs from EWOULDBLOCK. * * Revision 1.40 2001/08/23 09:02:46 adam @@ -495,6 +498,7 @@ int tcpip_connect(COMSTACK h, void *address) #ifdef WIN32 if (WSAGetLastError() == WSAEWOULDBLOCK) { + h->event = CS_CONNECT; h->state = CS_CONNECTING; h->io_pending = CS_WANT_WRITE; return 1; @@ -502,6 +506,7 @@ int tcpip_connect(COMSTACK h, void *address) #else if (errno == EINPROGRESS) { + h->event = CS_CONNECT; h->state = CS_CONNECTING; h->io_pending = CS_WANT_WRITE|CS_WANT_READ; return 1; @@ -510,6 +515,7 @@ int tcpip_connect(COMSTACK h, void *address) h->cerrno = CSYSERR; return -1; } + h->event = CS_CONNECT; h->state = CS_CONNECTING; } if (h->state != CS_CONNECTING) @@ -548,6 +554,7 @@ int tcpip_connect(COMSTACK h, void *address) } } #endif + h->event = CS_DATA; h->state = CS_DATAXFER; return 0; } @@ -555,10 +562,39 @@ int tcpip_connect(COMSTACK h, void *address) /* * nop */ -int tcpip_rcvconnect(COMSTACK h) +int tcpip_rcvconnect(COMSTACK cs) { TRC(fprintf(stderr, "tcpip_rcvconnect\n")); - return 0; + + if (cs->event == CS_CONNECT) + { + int fd = cs->iofile; + fd_set input, output; + struct timeval tv; + int r; + + tv.tv_sec = 0; + tv.tv_usec = 1; + + FD_ZERO(&input); + FD_ZERO(&output); + FD_SET (fd, &input); + FD_SET (fd, &output); + + r = select (fd+1, &input, &output, 0, &tv); + if (r > 0) + { + if (FD_ISSET(cs->iofile, &output)) + { + cs->state = CS_DATA; + return 0; /* write OK, we're OK */ + } + else + return -1; /* an error, for sure */ + } + return 0; /* timeout - incomplete */ + } + return -1; /* wrong state */ } #define CERTF "ztest.pem" @@ -629,6 +665,7 @@ int tcpip_bind(COMSTACK h, void *address, int mode) return -1; } h->state = CS_IDLE; + h->event = CS_LISTEN; return 0; } @@ -807,6 +844,7 @@ COMSTACK tcpip_accept(COMSTACK h) } h->io_pending = 0; h->state = CS_DATAXFER; + h->event = CS_DATA; return h; } @@ -1008,6 +1046,7 @@ int tcpip_put(COMSTACK h, char *buf, int size) TRC(fprintf(stderr, "tcpip_put: size=%d\n", size)); h->io_pending = 0; + h->event = CS_DATA; if (state->towrite < 0) { state->towrite = size; @@ -1020,8 +1059,15 @@ 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, 0)) < 0) + if ((res = + send(h->iofile, buf + state->written, size - + state->written, +#ifdef MSG_NOSIGNAL + MSG_NOSIGNAL +#else + 0 +#endif + )) < 0) { if ( #ifdef WIN32 @@ -1066,6 +1112,7 @@ int ssl_put(COMSTACK h, char *buf, int size) TRC(fprintf(stderr, "ssl_put: size=%d\n", size)); h->io_pending = 0; + h->event = CS_DATA; if (state->towrite < 0) { state->towrite = size; diff --git a/doc/yaz.xml b/doc/yaz.xml index faff797..e89335c 100644 --- a/doc/yaz.xml +++ b/doc/yaz.xml @@ -1,6 +1,6 @@ @@ -19,7 +19,7 @@ ODR"> COMSTACK"> ]> - + YAZ User's Guide and Reference diff --git a/doc/yazhtml.dsl b/doc/yazhtml.dsl index b7e89ea..8e71d9e 100644 --- a/doc/yazhtml.dsl +++ b/doc/yazhtml.dsl @@ -1,9 +1,9 @@ ]> diff --git a/doc/yazphp.dsl b/doc/yazphp.dsl index e0c2fda..ad25e61 100644 --- a/doc/yazphp.dsl +++ b/doc/yazphp.dsl @@ -1,9 +1,9 @@ ]> diff --git a/doc/yazprint.dsl b/doc/yazprint.dsl index 8736d92..3b65687 100644 --- a/doc/yazprint.dsl +++ b/doc/yazprint.dsl @@ -1,9 +1,9 @@ ]> diff --git a/include/yaz/comstack.h b/include/yaz/comstack.h index f7a5121..aa8da82 100644 --- a/include/yaz/comstack.h +++ b/include/yaz/comstack.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: comstack.h,v 1.5 2001-03-21 12:43:36 adam Exp $ + * $Id: comstack.h,v 1.6 2001-10-22 13:57:24 adam Exp $ */ #ifndef COMSTACK_H @@ -138,18 +138,18 @@ struct comstack #define cs_want_read(handle) ((handle)->io_pending & CS_WANT_READ) #define cs_want_write(handle) ((handle)->io_pending & CS_WANT_WRITE) #define cs_set_blocking(handle,blocking) ((handle)->f_set_blocking(handle, blocking) - + #define CS_WANT_READ 1 #define CS_WANT_WRITE 2 +YAZ_EXPORT int cs_look (COMSTACK); YAZ_EXPORT const char *cs_strerror(COMSTACK h); YAZ_EXPORT const char *cs_errmsg(int n); YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp); - /* * error management. */ - + #define CSNONE 0 #define CSYSERR 1 #define CSOUTSTATE 2 -- 1.7.10.4