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">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>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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>_______________________________________________<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><br clear="all"><br>-- <br>---<br><i style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">"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-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">--</i></div><div><i style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">The Democrats are the left wing.</i></div>
<div><i style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">The Republicans are the right wing.</i></div><div><i style="font-family:Verdana,Helvetica,sans-serif;font-size:12px;background-color:rgb(255,255,255)">We all know how well a bird flies with just one wing.</i></div>
<br>