Hi Mihai, enet_host_service() is essential in Enet, since it handles all the connectivity of the network engine (reliability, disconnections...) I think you're about to miss what enet is designed for, and your code just won't work.
Maybe you should go TCP and I/O ports? regards, Ju On Sat, Aug 1, 2009 at 3:45 PM, Mihai Draghicioiu < [email protected]> wrote: > Hi all. I'm working on frogmod, a sauerbraten server. At first it used the > original sauer main loop, then I changed it to use a loop similar to > BloodFrontier (checks for events then sleeps for 1ms), but now I want to > make it work with libevent. The way libevent works -- you receive a callback > for each event that happens on the socket. That way the most cpu is saved > when there are no connections, and everything is asynchronous (including the > dns). From what I can see in the enet code -- enet_host_service() and > enet_socket_wait(), the way to replace the main loop would be something like > this, for reading: > > // basically set a callback for when data is available for reading > event_set(&evinfo, socket, EV_READ | EV_PERSIST, readcb, NULL); > event_add(&evinfo, NULL); > > void readcb(...) { // handle incoming data. the code is pasted > if (event != NULL) > { > event -> type = ENET_EVENT_TYPE_NONE; > event -> peer = NULL; > event -> packet = NULL; > > switch (enet_protocol_dispatch_incoming_commands (host, event)) > { > case 1: > return 1; > > case -1: > perror ("Error dispatching incoming packets"); > > return -1; > > default: > break; > } > } > } > > (and something similar for writing) > > So basically, it would mean replacing enet_host_service() in the program > with the libevent setup. > > The reason I'm doing this is because libevent also provides me with async > DNS, http server/client code, and I've already written IRC client code. This > would also make frogmod modular, able to easily support other enet based > servers (like blood frontier). > > My questions are: > 1. Is this code the good way to go about it? Basically with libevent you > add some fds for reading and some for writing, then enter its loop, from > where it dispatches. > 2. What would you recommend instead? > > > _______________________________________________ > ENet-discuss mailing list > [email protected] > http://lists.cubik.org/mailman/listinfo/enet-discuss > >
_______________________________________________ ENet-discuss mailing list [email protected] http://lists.cubik.org/mailman/listinfo/enet-discuss
