From cccb7bee6522347a1cbee2322e247a93a538f0c6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 1 Feb 2016 07:42:49 +0000 Subject: [PATCH] enhanced event handlings a bit --- stio/lib/Makefile.am | 2 - stio/lib/Makefile.in | 2 - stio/lib/main.c | 4 +- stio/lib/stio-prv.h | 92 +++++++++++++++++++++++++- stio/lib/stio-tcp.c | 152 ++++++++++++++++++++++++++----------------- stio/lib/stio-tcp.h | 5 +- stio/lib/stio-tim.c | 1 - stio/lib/stio-tim.h | 124 ----------------------------------- stio/lib/stio.c | 19 ++++-- stio/lib/stio.h | 5 ++ 10 files changed, 208 insertions(+), 198 deletions(-) delete mode 100644 stio/lib/stio-tim.h diff --git a/stio/lib/Makefile.am b/stio/lib/Makefile.am index 192f4a0..6151634 100644 --- a/stio/lib/Makefile.am +++ b/stio/lib/Makefile.am @@ -29,8 +29,6 @@ pkginclude_HEADERS = \ pkglib_LTLIBRARIES = libstio.la libstio_la_SOURCES = \ stio-prv.h \ - stio-tim.h \ - stio-tmr.h \ stio.c \ stio-sck.c \ stio-tcp.c \ diff --git a/stio/lib/Makefile.in b/stio/lib/Makefile.in index 7bf93f2..6f9f369 100644 --- a/stio/lib/Makefile.in +++ b/stio/lib/Makefile.in @@ -386,8 +386,6 @@ pkginclude_HEADERS = \ pkglib_LTLIBRARIES = libstio.la libstio_la_SOURCES = \ stio-prv.h \ - stio-tim.h \ - stio-tmr.h \ stio.c \ stio-sck.c \ stio-tcp.c \ diff --git a/stio/lib/main.c b/stio/lib/main.c index fa44220..96a44dc 100644 --- a/stio/lib/main.c +++ b/stio/lib/main.c @@ -176,8 +176,8 @@ int main () memset (&sin, 0, STIO_SIZEOF(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(9999); - //inet_pton (sin.sin_family, "192.168.1.1", &sin.sin_addr); - inet_pton (sin.sin_family, "127.0.0.1", &sin.sin_addr); + inet_pton (sin.sin_family, "192.168.1.1", &sin.sin_addr); + //inet_pton (sin.sin_family, "127.0.0.1", &sin.sin_addr); memset (&tcp_conn, 0, STIO_SIZEOF(tcp_conn)); memcpy (&tcp_conn.addr, &sin, STIO_SIZEOF(sin)); diff --git a/stio/lib/stio-prv.h b/stio/lib/stio-prv.h index b98bb84..75a93e3 100644 --- a/stio/lib/stio-prv.h +++ b/stio/lib/stio-prv.h @@ -28,7 +28,6 @@ #define _STIO_PRV_H_ #include "stio.h" -#include "stio-tim.h" #include @@ -42,6 +41,9 @@ #define STIO_MEMMOVE(dst,src,count) memmove(dst,src,count) #define STIO_ASSERT assert + +#define STIO_USE_TMRJOB_IDXPTR + struct stio_tmrjob_t { void* ctx; @@ -87,6 +89,68 @@ struct stio_t }; + + +#define STIO_EPOCH_YEAR (1970) +#define STIO_EPOCH_MON (1) +#define STIO_EPOCH_DAY (1) +#define STIO_EPOCH_WDAY (4) + +/* windows specific epoch time */ +#define STIO_EPOCH_YEAR_WIN (1601) +#define STIO_EPOCH_MON_WIN (1) +#define STIO_EPOCH_DAY_WIN (1) + +#define STIO_DAYS_PER_WEEK (7) +#define STIO_MONS_PER_YEAR (12) +#define STIO_HOURS_PER_DAY (24) +#define STIO_MINS_PER_HOUR (60) +#define STIO_MINS_PER_DAY (STIO_MINS_PER_HOUR*STIO_HOURS_PER_DAY) +#define STIO_SECS_PER_MIN (60) +#define STIO_SECS_PER_HOUR (STIO_SECS_PER_MIN*STIO_MINS_PER_HOUR) +#define STIO_SECS_PER_DAY (STIO_SECS_PER_MIN*STIO_MINS_PER_DAY) +#define STIO_MSECS_PER_SEC (1000) +#define STIO_MSECS_PER_MIN (STIO_MSECS_PER_SEC*STIO_SECS_PER_MIN) +#define STIO_MSECS_PER_HOUR (STIO_MSECS_PER_SEC*STIO_SECS_PER_HOUR) +#define STIO_MSECS_PER_DAY (STIO_MSECS_PER_SEC*STIO_SECS_PER_DAY) + +#define STIO_USECS_PER_MSEC (1000) +#define STIO_NSECS_PER_USEC (1000) +#define STIO_NSECS_PER_MSEC (STIO_NSECS_PER_USEC*STIO_USECS_PER_MSEC) +#define STIO_USECS_PER_SEC (STIO_USECS_PER_MSEC*STIO_MSECS_PER_SEC) +#define STIO_NSECS_PER_SEC (STIO_NSECS_PER_USEC*STIO_USECS_PER_MSEC*STIO_MSECS_PER_SEC) + +#define STIO_SECNSEC_TO_MSEC(sec,nsec) \ + (((stio_intptr_t)(sec) * STIO_MSECS_PER_SEC) + ((stio_intptr_t)(nsec) / STIO_NSECS_PER_MSEC)) + +#define STIO_SECNSEC_TO_USEC(sec,nsec) \ + (((stio_intptr_t)(sec) * STIO_USECS_PER_SEC) + ((stio_intptr_t)(nsec) / STIO_NSECS_PER_USEC)) + +#define STIO_SEC_TO_MSEC(sec) ((sec) * STIO_MSECS_PER_SEC) +#define STIO_MSEC_TO_SEC(sec) ((sec) / STIO_MSECS_PER_SEC) + +#define STIO_USEC_TO_NSEC(usec) ((usec) * STIO_NSECS_PER_USEC) +#define STIO_NSEC_TO_USEC(nsec) ((nsec) / STIO_NSECS_PER_USEC) + +#define STIO_MSEC_TO_NSEC(msec) ((msec) * STIO_NSECS_PER_MSEC) +#define STIO_NSEC_TO_MSEC(nsec) ((nsec) / STIO_NSECS_PER_MSEC) + +#define STIO_SEC_TO_NSEC(sec) ((sec) * STIO_NSECS_PER_SEC) +#define STIO_NSEC_TO_SEC(nsec) ((nsec) / STIO_NSECS_PER_SEC) + +#define STIO_SEC_TO_USEC(sec) ((sec) * STIO_USECS_PER_SEC) +#define STIO_USEC_TO_SEC(usec) ((usec) / STIO_USECS_PER_SEC) + +#define stio_inittime(x,s,ns) (((x)->sec = (s)), ((x)->nsec = (ns))) +#define stio_cleartime(x) stio_inittime(x,0,0) +/*#define stio_cleartime(x) ((x)->sec = (x)->nsec = 0)*/ +#define stio_cmptime(x,y) \ + (((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): \ + ((x)->sec - (y)->sec)) + +#define stio_iszerotime(x) ((x)->sec == 0 && (x)->nsec == 0) + + #ifdef __cplusplus extern "C" { #endif @@ -100,6 +164,32 @@ int stio_makesckasync (stio_sckhnd_t sck); int stio_getsckadrinfo (stio_t* stio, const stio_sckadr_t* addr, stio_scklen_t* len, stio_sckfam_t* family); + +/** + * The stio_gettime() function gets the current time. + */ +STIO_EXPORT void stio_gettime ( + stio_ntime_t* nt +); + +/** + * The stio_addtime() function adds x and y and stores the result in z + */ +STIO_EXPORT void stio_addtime ( + const stio_ntime_t* x, + const stio_ntime_t* y, + stio_ntime_t* z +); + +/** + * The stio_subtime() function subtract y from x and stores the result in z. + */ +STIO_EXPORT void stio_subtime ( + const stio_ntime_t* x, + const stio_ntime_t* y, + stio_ntime_t* z +); + /** * The stio_instmrjob() function schedules a new event. * diff --git a/stio/lib/stio-tcp.c b/stio/lib/stio-tcp.c index 4b080aa..9b4c9e9 100644 --- a/stio/lib/stio-tcp.c +++ b/stio/lib/stio-tcp.c @@ -88,7 +88,7 @@ static void tcp_kill (stio_dev_t* dev) { stio_dev_tcp_t* tcp = (stio_dev_tcp_t*)dev; - if (tcp->state & (STIO_DEV_TCP_ACCEPTED | STIO_DEV_TCP_CONNECTED)) + if (tcp->state & (STIO_DEV_TCP_ACCEPTED | STIO_DEV_TCP_CONNECTED | STIO_DEV_TCP_CONNECTING | STIO_DEV_TCP_LISTENING)) { if (tcp->on_disconnected) tcp->on_disconnected (tcp); } @@ -160,12 +160,15 @@ static void tmr_connect_handle (stio_t* stio, const stio_ntime_t* now, stio_tmrj if (tcp->state & STIO_DEV_TCP_CONNECTING) { - /* the state check is actually redundant as it must not be fired - * after it gets connected. the timer job doesn't need to be deleted - * when it gets connected for this check here */ + /* the state check for STIO_DEV_TCP_CONNECTING is actually redundant + * as it must not be fired after it gets connected. the timer job + * doesn't need to be deleted when it gets connected for this check + * here. this libarary, however, deletes the job when it gets + * connected. */ +/* if (tcp->on_disconnected) tcp->on_disconnected (tcp); - tcp->state &= ~STIO_DEV_TCP_CONNECTING; +*/ stio_dev_tcp_kill (tcp); } } @@ -341,24 +344,39 @@ static int tcp_ready (stio_dev_t* dev, int events) stio_dev_tcp_t* tcp = (stio_dev_tcp_t*)dev; printf ("TCP READY...%p\n", dev); + if (events & STIO_DEV_EVENT_ERR) + { + int errcode; + stio_scklen_t len; + + len = STIO_SIZEOF(errcode); + if (getsockopt (tcp->sck, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) + { + /* the error number is set to the socket error code. + * errno resulting from getsockopt() doesn't reflect the actual + * socket error. so errno is not used to set the error number. + * instead, the generic device error STIO_EDEVERRR is used */ + tcp->stio->errnum = STIO_EDEVERR; + } + else + { + tcp->stio->errnum = stio_syserrtoerrnum (errcode); + } + return -1; + } + if (tcp->state & STIO_DEV_TCP_CONNECTING) { - if (events & (STIO_DEV_EVENT_ERR | STIO_DEV_EVENT_HUP | STIO_DEV_EVENT_PRI | STIO_DEV_EVENT_IN)) + if (events & STIO_DEV_EVENT_HUP) { - int errcode; - stio_scklen_t len; - - len = STIO_SIZEOF(errcode); - if (getsockopt (tcp->sck, SOL_SOCKET, SO_ERROR, (char*)&errcode, &len) == -1) - { -printf ("CANNOT CONNECT ERRORCODE - %s\n", strerror(errcode)); - tcp->stio->errnum = stio_syserrtoerrnum(errno); - } - else - { - tcp->stio->errnum = stio_syserrtoerrnum(errcode); - } - + /* device hang-up */ + tcp->stio->errnum = STIO_EDEVHUP; + return -1; + } + else if (events & (STIO_DEV_EVENT_PRI | STIO_DEV_EVENT_IN)) + { + /* invalid event masks. generic device error */ + tcp->stio->errnum = STIO_EDEVERR; return -1; } else if (events & STIO_DEV_EVENT_OUT) @@ -413,57 +431,73 @@ printf ("CAANOT MANIPULTE EVENT ...\n"); } else if (tcp->state & STIO_DEV_TCP_LISTENING) { - stio_sckhnd_t clisck; - stio_sckadr_t peer; - stio_scklen_t addrlen; - stio_dev_tcp_t* clitcp; - - /* this is a server(lisening) socket */ - - addrlen = STIO_SIZEOF(peer); - clisck = accept (tcp->sck, (struct sockaddr*)&peer, &addrlen); - if (clisck == -1) + if (events & STIO_DEV_EVENT_HUP) { - if (errno == EINPROGRESS || errno == EWOULDBLOCK) return 0; - if (errno == EINTR) return 0; /* if interrupted by a signal, treat it as if it's EINPROGRESS */ - - tcp->stio->errnum = stio_syserrtoerrnum(errno); + /* device hang-up */ + tcp->stio->errnum = STIO_EDEVHUP; return -1; } - - - /* addr is the address of the peer */ - /* local addresss is inherited from the server */ - clitcp = (stio_dev_tcp_t*)stio_makedev (tcp->stio, STIO_SIZEOF(*tcp), &tcp_acc_mth, tcp->evcb, &clisck); - if (!clitcp) + else if (events & (STIO_DEV_EVENT_PRI | STIO_DEV_EVENT_OUT)) { - close (clisck); + tcp->stio->errnum = STIO_EDEVERR; return -1; } + else if (events & STIO_DEV_EVENT_IN) + { + stio_sckhnd_t clisck; + stio_sckadr_t peer; + stio_scklen_t addrlen; + stio_dev_tcp_t* clitcp; - clitcp->state |= STIO_DEV_TCP_ACCEPTED; - clitcp->peer = peer; - clitcp->parent = tcp; + /* this is a server(lisening) socket */ + + addrlen = STIO_SIZEOF(peer); + clisck = accept (tcp->sck, (struct sockaddr*)&peer, &addrlen); + if (clisck == -1) + { + if (errno == EINPROGRESS || errno == EWOULDBLOCK) return 0; + if (errno == EINTR) return 0; /* if interrupted by a signal, treat it as if it's EINPROGRESS */ + + tcp->stio->errnum = stio_syserrtoerrnum(errno); + return -1; + } + + /* addr is the address of the peer */ + /* local addresss is inherited from the server */ + clitcp = (stio_dev_tcp_t*)stio_makedev (tcp->stio, STIO_SIZEOF(*tcp), &tcp_acc_mth, tcp->evcb, &clisck); + if (!clitcp) + { + close (clisck); + return -1; + } + + clitcp->state |= STIO_DEV_TCP_ACCEPTED; + clitcp->peer = peer; + /*clitcp->parent = tcp;*/ - /* inherit some event handlers from the parent. - * you can still change them inside the on_connected handler */ - clitcp->on_connected = tcp->on_connected; - clitcp->on_disconnected = tcp->on_disconnected; - clitcp->on_sent = tcp->on_sent; - clitcp->on_recv = tcp->on_recv; + /* inherit some event handlers from the parent. + * you can still change them inside the on_connected handler */ + clitcp->on_connected = tcp->on_connected; + clitcp->on_disconnected = tcp->on_disconnected; + clitcp->on_sent = tcp->on_sent; + clitcp->on_recv = tcp->on_recv; - clitcp->tmridx_connect = STIO_TMRIDX_INVALID; - if (clitcp->on_connected (clitcp) <= -1) stio_dev_tcp_kill (clitcp); - return 0; /* success but don't invoke on_recv() */ + clitcp->tmridx_connect = STIO_TMRIDX_INVALID; + if (clitcp->on_connected (clitcp) <= -1) stio_dev_tcp_kill (clitcp); + return 0; /* success but don't invoke on_recv() */ + } } - -printf ("READY WITH %d\n", events); - - if (events & (STIO_DEV_EVENT_ERR | STIO_DEV_EVENT_HUP)) + else if (events & STIO_DEV_EVENT_HUP) { -printf ("DISCONNECTED or ERROR \n"); - return -1; /* the caller must kill the device */ + if (events & (STIO_DEV_EVENT_PRI | STIO_DEV_EVENT_IN | STIO_DEV_EVENT_OUT)) + { + /* probably half-open? */ + return 1; + } + + tcp->stio->errnum = STIO_EDEVHUP; + return -1; } return 1; /* the device is ok. carry on reading or writing */ diff --git a/stio/lib/stio-tcp.h b/stio/lib/stio-tcp.h index 10b3fb1..83fdaef 100644 --- a/stio/lib/stio-tcp.h +++ b/stio/lib/stio-tcp.h @@ -28,7 +28,6 @@ #define _STIO_TCP_H_ #include -#include enum stio_dev_tcp_ioctl_cmd_t { @@ -72,7 +71,7 @@ struct stio_dev_tcp_t stio_sckadr_t peer; /* parent tcp device. valid if STIO_DEV_TCP_ACCEPTED is set */ - stio_dev_tcp_t* parent; + /*stio_dev_tcp_t* parent;*/ /** return 0 on succes, -1 on failure/ * called on a new tcp device for an accepted client or @@ -125,7 +124,7 @@ struct stio_dev_tcp_accept_t { stio_syshnd_t sck; /* TODO: add timeout */ - stio_dev_tcp_t* parent; /* TODO: is this really needed? */ + /*stio_dev_tcp_t* parent;*/ stio_sckadr_t peer; }; diff --git a/stio/lib/stio-tim.c b/stio/lib/stio-tim.c index dfa014a..d676160 100644 --- a/stio/lib/stio-tim.c +++ b/stio/lib/stio-tim.c @@ -24,7 +24,6 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "stio-tim.h" #include "stio-prv.h" #if defined(_WIN32) diff --git a/stio/lib/stio-tim.h b/stio/lib/stio-tim.h deleted file mode 100644 index 642892d..0000000 --- a/stio/lib/stio-tim.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * $Id$ - * - Copyright (c) 2015-2016 Chung, Hyung-Hwan. All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _STIO_TIME_H_ -#define _STIO_TIME_H_ - -#include - -#define STIO_EPOCH_YEAR (1970) -#define STIO_EPOCH_MON (1) -#define STIO_EPOCH_DAY (1) -#define STIO_EPOCH_WDAY (4) - -/* windows specific epoch time */ -#define STIO_EPOCH_YEAR_WIN (1601) -#define STIO_EPOCH_MON_WIN (1) -#define STIO_EPOCH_DAY_WIN (1) - -#define STIO_DAYS_PER_WEEK (7) -#define STIO_MONS_PER_YEAR (12) -#define STIO_HOURS_PER_DAY (24) -#define STIO_MINS_PER_HOUR (60) -#define STIO_MINS_PER_DAY (STIO_MINS_PER_HOUR*STIO_HOURS_PER_DAY) -#define STIO_SECS_PER_MIN (60) -#define STIO_SECS_PER_HOUR (STIO_SECS_PER_MIN*STIO_MINS_PER_HOUR) -#define STIO_SECS_PER_DAY (STIO_SECS_PER_MIN*STIO_MINS_PER_DAY) -#define STIO_MSECS_PER_SEC (1000) -#define STIO_MSECS_PER_MIN (STIO_MSECS_PER_SEC*STIO_SECS_PER_MIN) -#define STIO_MSECS_PER_HOUR (STIO_MSECS_PER_SEC*STIO_SECS_PER_HOUR) -#define STIO_MSECS_PER_DAY (STIO_MSECS_PER_SEC*STIO_SECS_PER_DAY) - -#define STIO_USECS_PER_MSEC (1000) -#define STIO_NSECS_PER_USEC (1000) -#define STIO_NSECS_PER_MSEC (STIO_NSECS_PER_USEC*STIO_USECS_PER_MSEC) -#define STIO_USECS_PER_SEC (STIO_USECS_PER_MSEC*STIO_MSECS_PER_SEC) -#define STIO_NSECS_PER_SEC (STIO_NSECS_PER_USEC*STIO_USECS_PER_MSEC*STIO_MSECS_PER_SEC) - -#define STIO_SECNSEC_TO_MSEC(sec,nsec) \ - (((stio_intptr_t)(sec) * STIO_MSECS_PER_SEC) + ((stio_intptr_t)(nsec) / STIO_NSECS_PER_MSEC)) - -#define STIO_SECNSEC_TO_USEC(sec,nsec) \ - (((stio_intptr_t)(sec) * STIO_USECS_PER_SEC) + ((stio_intptr_t)(nsec) / STIO_NSECS_PER_USEC)) - -#define STIO_SEC_TO_MSEC(sec) ((sec) * STIO_MSECS_PER_SEC) -#define STIO_MSEC_TO_SEC(sec) ((sec) / STIO_MSECS_PER_SEC) - -#define STIO_USEC_TO_NSEC(usec) ((usec) * STIO_NSECS_PER_USEC) -#define STIO_NSEC_TO_USEC(nsec) ((nsec) / STIO_NSECS_PER_USEC) - -#define STIO_MSEC_TO_NSEC(msec) ((msec) * STIO_NSECS_PER_MSEC) -#define STIO_NSEC_TO_MSEC(nsec) ((nsec) / STIO_NSECS_PER_MSEC) - -#define STIO_SEC_TO_NSEC(sec) ((sec) * STIO_NSECS_PER_SEC) -#define STIO_NSEC_TO_SEC(nsec) ((nsec) / STIO_NSECS_PER_SEC) - -#define STIO_SEC_TO_USEC(sec) ((sec) * STIO_USECS_PER_SEC) -#define STIO_USEC_TO_SEC(usec) ((usec) / STIO_USECS_PER_SEC) - -#define stio_inittime(x,s,ns) (((x)->sec = (s)), ((x)->nsec = (ns))) -#define stio_cleartime(x) stio_inittime(x,0,0) -/*#define stio_cleartime(x) ((x)->sec = (x)->nsec = 0)*/ -#define stio_cmptime(x,y) \ - (((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): \ - ((x)->sec - (y)->sec)) - -#define stio_iszerotime(x) ((x)->sec == 0 && (x)->nsec == 0) - -#if defined(__cplusplus) -extern "C" { -#endif - -/** - * The stio_gettime() function gets the current time. - */ -STIO_EXPORT void stio_gettime ( - stio_ntime_t* nt -); - -/** - * The stio_addtime() function adds x and y and stores the result in z - */ -STIO_EXPORT void stio_addtime ( - const stio_ntime_t* x, - const stio_ntime_t* y, - stio_ntime_t* z -); - -/** - * The stio_subtime() function subtract y from x and stores the result in z. - */ -STIO_EXPORT void stio_subtime ( - const stio_ntime_t* x, - const stio_ntime_t* y, - stio_ntime_t* z -); - -#if defined(__cplusplus) -} -#endif - -#endif diff --git a/stio/lib/stio.c b/stio/lib/stio.c index e77f4d9..e7a61fc 100644 --- a/stio/lib/stio.c +++ b/stio/lib/stio.c @@ -267,15 +267,16 @@ int stio_exec (stio_t* stio) int x, events = 0; if (stio->revs[i].events & EPOLLERR) events |= STIO_DEV_EVENT_ERR; - #if defined(EPOLLRDHUP) - if (stio->revs[i].events & (EPOLLHUP | EPOLLRDHUP)) events |= STIO_DEV_EVENT_HUP; - #else if (stio->revs[i].events & EPOLLHUP) events |= STIO_DEV_EVENT_HUP; - #endif + #if defined(EPOLLRDHUP) + /* treat it the same way as EPOLLHUP */ + if (stio->revs[i].events & EPOLLRDHUP) events |= STIO_DEV_EVENT_HUP; + #endif if (stio->revs[i].events & EPOLLIN) events |= STIO_DEV_EVENT_IN; if (stio->revs[i].events & EPOLLOUT) events |= STIO_DEV_EVENT_OUT; if (stio->revs[i].events & EPOLLPRI) events |= STIO_DEV_EVENT_PRI; + /* return value of ready() * <= -1 - failure. kill the device. * == 0 - ok. but don't invoke recv() or send(). @@ -594,6 +595,16 @@ stio_errnum_t stio_syserrtoerrnum (int no) return STIO_ENFILE; #endif + #if defined(ECONNREFUSED) + case ECONNREFUSED: + return STIO_ECONRF; + #endif + + #if defined(ECONNRESETD) + case ECONNRESET: + return STIO_ECONRS; + #endif + default: return STIO_ESYSERR; } diff --git a/stio/lib/stio.h b/stio/lib/stio.h index 2ce78e0..9fbf367 100644 --- a/stio/lib/stio.h +++ b/stio/lib/stio.h @@ -105,8 +105,13 @@ enum stio_errnum_t STIO_ENOSUP, /* not supported */ STIO_EMFILE, STIO_ENFILE, + STIO_ECONRF, /* connection refused */ + STIO_ECONRS, /* connection reset */ STIO_EDEVMAKE, + STIO_EDEVERR, + STIO_EDEVHUP, + STIO_ESYSERR };