in my program, I register a EV_READ event conn_ev for connfd in libevent event loop. when this event is triggered, I usegetpeername
to get the IP/PORT address of the peersocklen_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?