ENet has no idea what threads are. So, yes, it is running in the same thread.<div><br></div><div>It's just a function pointer that is executed every time a raw UDP packet comes in. Unless you are trying to solve weather simulations in the intercept callback, it should have no real significant effect on performance.</div>
<div><br></div><div>You get an intercept callback for every single raw UDP packet that comes in. It is happening below the ENet protocol layer, essentially, so it has no relation to relable/unreliable/retries/etc. You just get one incoming raw UDP packet = one intercept callback. <br>
<br><div class="gmail_quote">On Tue, Oct 2, 2012 at 2:39 PM, Jay Sprenkle <span dir="ltr"><<a href="mailto:jsprenkle@gmail.com" target="_blank">jsprenkle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I can definitely see use for this. Thanks for posting it!<br><br>I have a couple of questions:<br><br>I'm assuming the callback will be running in the same thread as whatever calls the host polling code?<br><br>How does this affect efficiency and latency vs polling?<br>

<br>Do we get interrupt callbacks during retries?<br><br>If we use reliable delivery do wet get the interrupts in the correct order or just whatever comes in?<br><br>Thanks again.<br><br><br><br><div class="gmail_quote">
<div><div class="h5">On Tue, Oct 2, 2012 at 5:48 AM, Lee Salzman <span dir="ltr"><<a href="mailto:lsalzman@gmail.com" target="_blank">lsalzman@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">Because there were some requests on github for things that would otherwise use the functionality, or direct appeals for the functionality itself, I finally bit the bullet and added a simple packet intercept callback to ENetHost, usage looks sorta like this:<div>


<br></div><div><br></div><div>int intercept_callback(ENetHost *host, ENetEvent *event)</div><div>{</div><div>   // the first two bytes of a valid ENet protocol packet will never be 0xFFFF, so you should ideally use this to distinguish user data packets from ENet protocol packets</div>


<div>   if(host->receivedDataLength >= 2 && *(unsigned short *)host->receivedData == 0xFFFF)</div><div>   {</div><div>      // host->receivedAddress contains the address the UDP packet came from</div>

<div>
      // do magical stuff with packet here...</div><div>      // if event is non-NULL, you can also set event->type with your own non-zero event number that ENet will pass out of enet_host_service(), but this is not required, just optional</div>


<div>      // if event->type is untouched, ENet will still skip the packet so long as you return 1... </div><div>      return 1; // tell ENet to skip the packet</div><div>   }</div><div>   return 0; // tell ENet to continue processing the packet</div>


<div>   // returning -1 will propagate the -1 return value out of enet_host_service...</div><div>}</div><div><br></div><div>....</div><div>host -> intercept = intercept_callback;</div><div>....</div><div>enet_host_service(host, event, timeout); // intercept gets called from in here when ENet receives a raw udp packet</div>


<div>// if you propagated a custom event type from within the intercept callback, it will get returned out here too with enet_host_service returning 1 like for any other event</div><div><br></div><div>This system can be used to implement all manner of fun things, from simulating packet loss to multiplexing your own data like pings or whatever over the ENet socket.</div>


<div>This is currently in the github repo, going to let it stew a bit before I release anything in case people have suggestions.</div><div><br></div>
<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><span class="HOEnZb"><font color="#888888"><br><br clear="all"><br>-- <br>---<br><i style="font-size:12px;font-family:Verdana,Helvetica,sans-serif">"Why do you have that banana in your ear?" <br>
"To keep away the alligators."<br>
"But there are no alligators here."<br>"See! It's working!"</i>
<div><i style="font-size:12px;font-family:Verdana,Helvetica,sans-serif">--</i></div><div><i style="font-size:12px;font-family:Verdana,Helvetica,sans-serif">The Democrats are the left wing.</i></div>
<div><i style="font-size:12px;font-family:Verdana,Helvetica,sans-serif">The Republicans are the right wing.</i></div><div><i style="font-size:12px;font-family:Verdana,Helvetica,sans-serif">We all know how well a bird flies with just one wing.</i></div>

<br>
</font></span><br>_______________________________________________<br>
ENet-discuss mailing list<br>
<a href="mailto:ENet-discuss@cubik.org">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>