| 985 | } |
| 986 | |
| 987 | err_t didReceive(void * arg, struct tcp_pcb * pcb, struct pbuf * p, err_t err) |
| 988 | { |
| 989 | xsSocket xss = arg; |
| 990 | unsigned char i; |
| 991 | struct pbuf *walker; |
| 992 | uint16 offset; |
| 993 | |
| 994 | #ifdef mxDebug |
| 995 | if (p && fxInNetworkDebugLoop(xss->the)) |
| 996 | return ERR_MEM; |
| 997 | #endif |
| 998 | |
| 999 | if (xss->pending & kPendingClose) |
| 1000 | return ERR_OK; |
| 1001 | |
| 1002 | if (err) { // this is defensive, as the lwip sources appear to always pass ERR_OK for err |
| 1003 | #ifdef mxDebug |
| 1004 | modLog("unexpected error in didReceive"); |
| 1005 | #endif |
| 1006 | socketSetPending(xss, kPendingError); |
| 1007 | return ERR_OK; |
| 1008 | } |
| 1009 | |
| 1010 | if (!p) { // connnection closed |
| 1011 | tcp_recv(xss->skt, NULL); |
| 1012 | tcp_sent(xss->skt, NULL); |
| 1013 | tcp_err(xss->skt, NULL); |
| 1014 | |
| 1015 | if (xss->reader[0] || xss->buflen) |
| 1016 | xss->disconnectedWhileReading = true; |
| 1017 | else |
| 1018 | socketSetPending(xss, kPendingDisconnect); |
| 1019 | |
| 1020 | return ERR_OK; |
| 1021 | } |
| 1022 | |
| 1023 | modCriticalSectionBegin(); |
| 1024 | for (i = 0; i < kReadQueueLength; i++) { |
| 1025 | if (NULL == xss->reader[i]) { |
| 1026 | xss->reader[i] = p; |
| 1027 | break; |
| 1028 | } |
| 1029 | } |
| 1030 | modCriticalSectionEnd(); |
| 1031 | |
| 1032 | if (kReadQueueLength == i) |
| 1033 | return ERR_MEM; // no space. return error so lwip will redeliver later |
| 1034 | |
| 1035 | modInstrumentationAdjust(NetworkBytesRead, p->tot_len); |
| 1036 | |
| 1037 | socketSetPending(xss, kPendingReceive); |
| 1038 | |
| 1039 | return ERR_OK; |
| 1040 | } |
| 1041 | |
| 1042 | err_t didSend(void *arg, struct tcp_pcb *pcb, u16_t len) |
| 1043 | { |
nothing calls this directly
no test coverage detected