MCPcopy Create free account
hub / github.com/JACoders/OpenJK / NET_GetLoopPacket

Function NET_GetLoopPacket

code/qcommon/net_chan.cpp:440–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

438*/
439
440qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message)
441{
442 int i;
443 loopback_t *loop;
444
445 loop = &loopbacks[sock];
446
447 //If read and write positions are the same, nothing left to read.
448 if (loop->get == loop->send)
449 return qfalse;
450
451 //Get read position. Wrap if too close to end.
452 i = loop->get;
453 if(i > MAX_LOOPDATA - 4) {
454 i = 0;
455 }
456
457 //Get length of packet.
458 byteAlias_t *ba = (byteAlias_t *)&loop->loopData[i];
459 const int length = ba->i;
460 i += 4;
461
462 //See if entire packet is at end of buffer or part is at the beginning.
463 if(i + length <= MAX_LOOPDATA) {
464 //Everything fits, full copy.
465 memcpy (net_message->data, loop->loopData + i, length);
466 net_message->cursize = length;
467 i += length;
468 loop->get = i;
469 } else {
470 //Doesn't all fit, partial copy
471 const int copyToEnd = MAX_LOOPDATA - i;
472 memcpy (net_message->data, loop->loopData + i, copyToEnd);
473 memcpy ((char*)net_message->data + copyToEnd,
474 loop->loopData, length - copyToEnd);
475 net_message->cursize = length;
476 loop->get = length - copyToEnd;
477 }
478
479 memset (net_from, 0, sizeof(*net_from));
480 net_from->type = NA_LOOPBACK;
481
482 return qtrue;
483}
484
485
486void NET_SendLoopPacket (netsrc_t sock, int length, const void *data, netadr_t to)

Callers 1

Com_EventLoopFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected