| 207 | } |
| 208 | |
| 209 | static void udpReceive(struct net_context *context, struct net_pkt *pkt, union net_ip_header *ip_hdr, union net_proto_header *proto_hdr, int status, void *user_data) |
| 210 | { |
| 211 | UDP udp = user_data; |
| 212 | UDPPacket packet; |
| 213 | |
| 214 | #ifdef mxDebug |
| 215 | if (fxInNetworkDebugLoop(udp->the)) { |
| 216 | net_pkt_unref(pkt); |
| 217 | return; |
| 218 | } |
| 219 | #endif |
| 220 | |
| 221 | packet = c_malloc(sizeof(UDPPacketRecord)); |
| 222 | if (!packet) { |
| 223 | net_pkt_unref(pkt); |
| 224 | return; |
| 225 | } |
| 226 | |
| 227 | packet->next = NULL; |
| 228 | packet->pkt = pkt; |
| 229 | packet->port = ntohs(proto_hdr->udp->src_port); |
| 230 | packet->address = *(struct net_addr *)ip_hdr->ipv4->src; |
| 231 | |
| 232 | modInstrumentationAdjust(NetworkBytesRead, net_pkt_get_len(pkt)); |
| 233 | |
| 234 | builtinCriticalSectionBegin(); |
| 235 | uint8_t readablePending = udp->readablePending; |
| 236 | if (udp->packets) { |
| 237 | UDPPacket walker; |
| 238 | |
| 239 | for (walker = udp->packets; walker->next; walker = walker->next) |
| 240 | ; |
| 241 | walker->next = packet; |
| 242 | } |
| 243 | else |
| 244 | udp->packets = packet; |
| 245 | builtinCriticalSectionEnd(); |
| 246 | |
| 247 | if (!readablePending && udp->onReadable) { |
| 248 | udp->readablePending = true; |
| 249 | modMessagePostToMachine(udp->the, NULL, 0, udpDeliver, udp); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | void udpDeliver(void *the, void *refcon, uint8_t *message, uint16_t messageLength) |
| 254 | { |
nothing calls this directly
no test coverage detected