[ENet-discuss] enet, epoll and libevent
Uj
ujdevil at gmail.com
Tue Aug 4 10:10:19 PDT 2009
ok I thought you didn't want to use enet_host_service() ...
If you really want to "receive a callback for each event that happens on the
socket", then use IO ports or select.
Enet is mainly designed for fast messaging, so it sounds weird, IMHO, to use
it in an event system with sleeps.
Ju
On Tue, Aug 4, 2009 at 2:08 PM, Mihai Draghicioiu <
mihai.draghicioiu at gmail.com> wrote:
> I've already managed to get it to work, thanks to the hopmod guys (reactor
> branch).
>
> http://code.google.com/p/frogmod/source/detail?r=193
>
> It seems enet_host_service is used without a timeout, so it doesn't block.
>
> Thanks for replying!
>
>
>
> On Tue, Aug 4, 2009 at 1:27 PM, Uj <ujdevil at gmail.com> wrote:
>
>> 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 <
>> mihai.draghicioiu at gmail.com> 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
>>> ENet-discuss at cubik.org
>>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>>
>>>
>>
>> _______________________________________________
>> ENet-discuss mailing list
>> ENet-discuss at cubik.org
>> http://lists.cubik.org/mailman/listinfo/enet-discuss
>>
>>
>
> _______________________________________________
> ENet-discuss mailing list
> ENet-discuss at cubik.org
> http://lists.cubik.org/mailman/listinfo/enet-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20090804/17cfe656/attachment-0001.htm>
More information about the ENet-discuss
mailing list