MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / didReceiveUDP

Function didReceiveUDP

modules/network/socket/lwip/modSocket.c:1055–1099  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1053}
1054
1055void didReceiveUDP(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *remoteAddr, u16_t remotePort)
1056{
1057 xsSocket xss = arg;
1058 unsigned char i;
1059 struct pbuf *toFree = NULL;
1060
1061#ifdef mxDebug
1062 if (fxInNetworkDebugLoop(xss->the)) {
1063 pbuf_free(p);
1064 return;
1065 }
1066#endif
1067 if (xss->suspended) {
1068 pbuf_free(p);
1069 return;
1070 }
1071
1072 modCriticalSectionBegin();
1073
1074 for (i = 0; i < kReadQueueLength; i++) {
1075 if (NULL == xss->reader[i])
1076 break;
1077 }
1078
1079 if (kReadQueueLength == i) { // all full. make room by tossing earliest entry
1080 toFree = xss->reader[0];
1081 for (i = 0; i < kReadQueueLength - 1; i++) {
1082 xss->reader[i] = xss->reader[i + 1];
1083 xss->remote[i] = xss->remote[i + 1];
1084 }
1085 i = kReadQueueLength - 1;
1086 }
1087
1088 xss->reader[i] = p;
1089 xss->remote[i].port = remotePort;
1090 xss->remote[i].address = *remoteAddr;
1091
1092 modInstrumentationAdjust(NetworkBytesRead, p->tot_len);
1093 modCriticalSectionEnd();
1094
1095 if (toFree)
1096 pbuf_free(toFree); // not pbuf_free_safe, because we are in lwip task
1097
1098 socketSetPending(xss, kPendingReceive);
1099}
1100
1101#if ESP32 || CYW43_LWIP
1102u8_t didReceiveRAW(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr)

Callers 1

didReceiveRAWFunction · 0.85

Calls 2

socketSetPendingFunction · 0.85
fxInNetworkDebugLoopFunction · 0.50

Tested by

no test coverage detected