[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] Triggered EV_READ event socket get ENOT Transport endpoint is not connected






On Fri, Jun 21, 2013 at 5:20 AM, liu lily <politoesolve@xxxxxxxxx> wrote:

in my program, I register a EV_READ event conn_ev for connfd in libevent event loop. when this event is triggered, I use getpeername to get the IP/PORT address of the peer
socklen_t socklen;
struct sockaddr_in client_addr;
socklen = sizeof(client_addr);
retval = getpeername(connfd, (struct sockaddr *)&client_addr, &socklen);
if(retval == -1) perror("getpeername error!\n");

but sometimes, it returns 0.0.0.0:0

and then I notice the error is Transport endpoint is not connected

but recv(connfd,buf,..) returns a 1273 , which means it receives 1273 bytes.

One  possibility is the socket connfd is closed locally. Indeed, I have a function which call event_del(conn_ev) and close(connfd) , and  some other events sometimes call this function. But if the function is called, the event is deleted and the connfd is closed. How can the event be triggered?



My guess would be that something in your program isn't working the way you think it is -- deleting an event should indeed be sufficient to make it not get called.

One thing you might try for debugging this is to use a system-call trace tool to verify that the events are happening in the order you think -- a close, then a getpeername, then a recv().  If that recv is really succeeding after the close, I'd be quite surprised.

Anybody else have ideas here?

-- 
Nick