views:

279

answers:

2

I've a non-blocking socket currently subscribed to:

 ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP | EPOLLRDHUP| EPOLLET;

It receives a couple of EPOLLINs which I read non-blocking till EAGAIN and then I receive HUP & RDHUP, sometimes with a few bytes more to read.

The other side is just:

send(socket,960_bytes_buffer)
close(socket);

I've tried recv with msg_peek directly in the event loop for both epollin and in close time, and adding received data it doesn't receive 960 always, sometimes only around 480 bytes.

Making the socket non-blocking or putting a sleep(1) in the client between the send and the close works OK.

It looks to me more a problem of non-blocking sockets than epoll related. Something simple as "nc -l -p port" receives the proper amount of bytes.

A: 

Are you issuing a lingering close or a non lingering close?

Len Holgate
In the client side its just standard connect send close, no setsockopt nor nothing related, so no SO_LINGER there.
Arkaitz Jimenez
+4  A: 

Have a look at The ultimate SO_LINGER page, or: why is my tcp not reliable which nicely explains what is happening and how to fix it.

cmeerw
That's a nice link!
Len Holgate