| 969 | // >0 Buffer filled with the number of bytes recieved |
| 970 | |
| 971 | int nw_ReceiveReliable(SOCKET socketid, uint8_t *buffer, int max_len) { |
| 972 | |
| 973 | int i; |
| 974 | if (Use_DirectPlay) { |
| 975 | #ifdef WIN32 |
| 976 | dp_DirectPlayDispatch(); |
| 977 | |
| 978 | // try and get a free buffer and return its size |
| 979 | if (nw_psnet_buffer_get_next_by_packet_id((uint8_t *)buffer, &max_len, socketid)) { |
| 980 | return max_len; |
| 981 | } |
| 982 | return 0; |
| 983 | #endif |
| 984 | } |
| 985 | reliable_socket *rsocket = NULL; |
| 986 | // nw_WorkReliable(); |
| 987 | nw_DoReceiveCallbacks(); |
| 988 | if (socketid >= MAXRELIABLESOCKETS) { |
| 989 | mprintf(0, "Invalid socket id passed to nw_NewReceiveReliable() -- %d\n", socketid); |
| 990 | return -1; |
| 991 | } |
| 992 | rsocket = &reliable_sockets[socketid]; |
| 993 | if ((RNF_CONNECTED != rsocket->status) && (RNF_LIMBO != rsocket->status)) { |
| 994 | mprintf(0, "Can't receive packet because it isn't connected in nw_ReceiveReliable(). socket = %d\n", socketid); |
| 995 | return 0; |
| 996 | } |
| 997 | // If the buffer position is the position we are waiting for, fill in |
| 998 | // the buffer we received in the call to this function and return true |
| 999 | |
| 1000 | for (i = 0; i < MAXNETBUFFERS; i++) { |
| 1001 | if ((rsocket->rsequence[i] == rsocket->oursequence) && (rsocket->rbuffers[i])) { |
| 1002 | memcpy(buffer, rsocket->rbuffers[i]->buffer, rsocket->recv_len[i]); |
| 1003 | mem_free(rsocket->rbuffers[i]); |
| 1004 | rsocket->rbuffers[i] = NULL; |
| 1005 | rsocket->rsequence[i] = 0; |
| 1006 | /* |
| 1007 | mprintf(0,"Found packet for upper layer in nw_ReceiveReliable() %d bytes. seq:%d.\n", |
| 1008 | rsocket->recv_len[i], |
| 1009 | rsocket->oursequence); |
| 1010 | */ |
| 1011 | rsocket->oursequence++; |
| 1012 | return rsocket->recv_len[i]; |
| 1013 | } |
| 1014 | } |
| 1015 | |
| 1016 | return 0; |
| 1017 | } |
| 1018 | |
| 1019 | // This function will look for a control packet, indicating a |
| 1020 | // desire to establish a reliable link. |
no test coverage detected