Reputation: 565
I have a socket which is used to receive and also send packets. And the pseudo codes are:
setnonblock(fd);
add_event(event_base, recv_ev);
while("I have packets to write"){
send(fd, packet);
....
}
....
now the issue is, since fd is non-blocking, send(fd) many return before it finish sending packets. but I hope it can send the packet successfully before the program runs to the next step, or register an event for it. But if I register an event for it, the event may be triggered frequently even if there are no packets available (note the packets are not from recv() in the pseudo code ,but from somewhere else)
then how to deal with it?
Upvotes: 0
Views: 251
Reputation: 310884
The is all back to front. Sockets are almost always writeable. So you should:
Upvotes: 1