ok I thought you didn't want to use enet_host_service() ...<br><br>If you really want to "receive a callback for each event that happens on the socket", then use IO ports or select.<br>Enet is mainly designed for fast messaging, so it sounds weird, IMHO, to use it in an event system with sleeps.<br>
<br>Ju<br><br><br><div class="gmail_quote">On Tue, Aug 4, 2009 at 2:08 PM, Mihai Draghicioiu <span dir="ltr"><<a href="mailto:mihai.draghicioiu@gmail.com" target="_blank">mihai.draghicioiu@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I've already managed to get it to work, thanks to the hopmod guys (reactor branch).<br>
<br>
<a href="http://code.google.com/p/frogmod/source/detail?r=193" target="_blank">http://code.google.com/p/frogmod/source/detail?r=193</a><br><br>
It seems enet_host_service is used without a timeout, so it doesn't block.<br><br>Thanks for replying!<div><div></div><div><br><br><br><div class="gmail_quote">On Tue, Aug 4, 2009 at 1:27 PM, Uj <span dir="ltr"><<a href="mailto:ujdevil@gmail.com" target="_blank">ujdevil@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Mihai,<br><br>enet_host_service() is essential in Enet, since it handles all the connectivity of the network engine (reliability, disconnections...)<br>
I think you're about to miss what enet is designed for, and your code just won't work.<br>
<br>Maybe you should go TCP and I/O ports?<br><br>regards,<br>Ju<br><br><br><div class="gmail_quote"><div><div></div><div>On Sat, Aug 1, 2009 at 3:45 PM, Mihai Draghicioiu <span dir="ltr"><<a href="mailto:mihai.draghicioiu@gmail.com" target="_blank">mihai.draghicioiu@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div>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:<br>
<br>// basically set a callback for when data is available for reading<br>event_set(&evinfo, socket, EV_READ | EV_PERSIST, readcb, NULL);<br>event_add(&evinfo, NULL);<br><br>void readcb(...) { // handle incoming data. the code is pasted<br>
if (event != NULL)<br> {<br> event -> type = ENET_EVENT_TYPE_NONE;<br> event -> peer = NULL;<br> event -> packet = NULL;<br><br> switch (enet_protocol_dispatch_incoming_commands (host, event))<br>
{<br> case 1:<br> return 1;<br><br> case -1:<br> perror ("Error dispatching incoming packets");<br><br> return -1;<br><br> default:<br> break;<br>
}<br> }<br>
}<br>
<br>
(and something similar for writing)<br><br>So basically, it would mean replacing enet_host_service() in the program with the libevent setup.<br><br>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).<br>
<br>My questions are:<br>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.<br>2. What would you recommend instead?<br>
<br>
<br></div></div>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>
</div></div><br>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org" target="_blank">ENet-discuss@cubik.org</a><br>
<a href="http://lists.cubik.org/mailman/listinfo/enet-discuss" target="_blank">http://lists.cubik.org/mailman/listinfo/enet-discuss</a><br>
<br></blockquote></div><br>