| 1081 | } |
| 1082 | |
| 1083 | int nw_SendReliable(uint32_t socketid, uint8_t *data, int length, bool urgent) { |
| 1084 | int i; |
| 1085 | int bytesout; |
| 1086 | int use_buffer = -1; |
| 1087 | reliable_socket *rsocket; |
| 1088 | reliable_header send_header; |
| 1089 | int send_this_packet = 1; |
| 1090 | |
| 1091 | if (length == 0) { |
| 1092 | mprintf(0, "Attempting to send 0 byte network packet in nw_SendReliable()\n"); |
| 1093 | Int3(); |
| 1094 | } |
| 1095 | // mprintf(0,"Socket id passed to nw_NewSendReliable() -- %d\n",socketid); |
| 1096 | |
| 1097 | if (NetDebugFile) { |
| 1098 | cfprintf(NetDebugFile, "nw_SendReliable packet of type %d at %f seconds.\n", data[0], timer_GetTime()); |
| 1099 | } |
| 1100 | |
| 1101 | if (Use_DirectPlay) { |
| 1102 | #ifdef WIN32 |
| 1103 | network_address who_to; |
| 1104 | who_to.connection_type = NP_DIRECTPLAY; |
| 1105 | memcpy(&who_to.address, &socketid, sizeof(DPID)); |
| 1106 | return dp_DirectPlaySend(&who_to, data, length, true); |
| 1107 | #endif |
| 1108 | } |
| 1109 | |
| 1110 | ASSERT(length < sizeof(reliable_header)); |
| 1111 | // nw_WorkReliable(); |
| 1112 | nw_DoReceiveCallbacks(); |
| 1113 | |
| 1114 | if (socketid >= MAXRELIABLESOCKETS) { |
| 1115 | mprintf(0, "Invalid socket id passed to nw_NewSendReliable() -- %d\n", socketid); |
| 1116 | return -1; |
| 1117 | } |
| 1118 | |
| 1119 | rsocket = &reliable_sockets[socketid]; |
| 1120 | if (rsocket->status != RNF_CONNECTED) { |
| 1121 | // We can't send because this isn't a connected reliable socket. |
| 1122 | mprintf(0, "Can't send packet because of status %d in nw_SendReliable(). socket = %d\n", rsocket->status, socketid); |
| 1123 | return -1; |
| 1124 | } |
| 1125 | if (urgent) |
| 1126 | rsocket->send_urgent = 1; |
| 1127 | // See if there is a packet waiting to be sent |
| 1128 | if (-1 != rsocket->waiting_packet_number) { |
| 1129 | int pnum = rsocket->waiting_packet_number; |
| 1130 | ASSERT(rsocket->sbuffers[pnum]); |
| 1131 | // See if there's room for this data |
| 1132 | if (sizeof(reliable_net_sendbuffer) < (rsocket->send_len[pnum] + length)) { |
| 1133 | // Send the previous packet, then use the normal code to generate a new packet |
| 1134 | mprintf(0, "Pending reliable packet buffer full, sending packet now.\n"); |
| 1135 | rsocket->waiting_packet_number = -1; |
| 1136 | |
| 1137 | use_buffer = pnum; |
| 1138 | network_address send_address; |
| 1139 | memset(&send_address, 0, sizeof(network_address)); |
| 1140 |
no test coverage detected