From 596304d4463f7cb2f615a6650670a30460b5b909 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 28 Jan 2016 17:32:58 +0000 Subject: [PATCH] conditional use of MSG_NOSIGNAL and EPOLLRDHUP --- stio/lib/main.c | 4 ++++ stio/lib/stio-tcp.c | 8 ++++++-- stio/lib/stio.c | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/stio/lib/main.c b/stio/lib/main.c index a530f24..34349a7 100644 --- a/stio/lib/main.c +++ b/stio/lib/main.c @@ -133,6 +133,10 @@ int main () sigact.sa_handler = handle_signal; sigaction (SIGINT, &sigact, STIO_NULL); + //STIO_MEMSET (&sigact, 0, STIO_SIZEOF(sigact)); + //sigact.sa_handler = SIG_IGN; + //sigaction (SIGPIPE, &sigact, STIO_NULL); + /* pkt = stio_pkt_open (packet type, protocol type); // packet socket arp = stio_arp_open (binding_addr); // raw socket - arp filter diff --git a/stio/lib/stio-tcp.c b/stio/lib/stio-tcp.c index 5fbd013..220e579 100644 --- a/stio/lib/stio-tcp.c +++ b/stio/lib/stio-tcp.c @@ -129,9 +129,13 @@ static int tcp_send (stio_dev_t* dev, const void* data, stio_len_t* len) { stio_dev_tcp_t* tcp = (stio_dev_tcp_t*)dev; ssize_t x; - + int flags = 0; + /* flags MSG_DONTROUTE, MSG_DONTWAIT, MSG_MORE, MSG_OOB, MSG_NOSIGNAL */ - x = sendto (tcp->sck, data, *len, 0, STIO_NULL, 0); +#if defined(MSG_NOSIGNAL) + flags |= MSG_NOSIGNAL; +#endif + x = sendto (tcp->sck, data, *len, flags, STIO_NULL, 0); if (x <= -1) { if (errno == EINPROGRESS || errno == EWOULDBLOCK) return 0; /* no data can be written */ diff --git a/stio/lib/stio.c b/stio/lib/stio.c index 097ccb9..bd636e7 100644 --- a/stio/lib/stio.c +++ b/stio/lib/stio.c @@ -231,7 +231,11 @@ 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 (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;