I'm starting with libev and I've followed this example:
http://codefundas.blogspot.com/2010/09/create-tcp-echo-server-using-libev.html
which creates an echo server. However, I don't think it's not the most
efficient approach because the writing could get blocked, isn't it?

So, what I've done is:
a) to create a io watcher for accepting a socket connection --> client_sd =
accept(...)
b) to create a io watcher for reading data from an accepted socket
connection  --> read = recv(client_sd, ...)
    - If read == 0, then the socket is closed --> close(client_sd);
    - else a new io watcher (EV_WRITE) is created which puts data in the
socket and close the socket afterwards --> send(client_sd, ...);
close(client_sd);

However, with this approach, when I open another connection, the watcher for
reading returns an EV_ERROR due to "Invalid file descriptor", what it's
really strange for me. The socket is closed by the "write watcher", and when
the second connection is created, the accept returns the same file
descriptor than the previous socket and the "read watcher/callback" provides
the EV_ERROR.
On the other hand, if I avoid creating the "write watcher" and send the data
directly in the "read watcher/callback", everything works fine.

So, I have 2 questions:
a) Why the "Invalid file descriptor" error is created?
b) What's the most convenient way to write data in a TCP socket:
    1.- "send" data directly in the read callback
    2.- Create a write watcher
    3.- Create a watcher of both types: READ&WRITE.

Thanks in advance,
Jaime
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

Reply via email to