| 1165 | }; |
| 1166 | |
| 1167 | static void TcpServerThread(void* ctx_ptr) |
| 1168 | { |
| 1169 | TcpServerContext* ctx = (TcpServerContext*) ctx_ptr; |
| 1170 | |
| 1171 | dmSocket::Socket server_socket = dmSocket::INVALID_SOCKET_HANDLE; |
| 1172 | dmSocket::Socket client_socket = dmSocket::INVALID_SOCKET_HANDLE; |
| 1173 | dmSocket::Address bind_address; |
| 1174 | dmSocket::Address server_name; |
| 1175 | dmSocket::Result r = dmSocket::New(dmSocket::DOMAIN_IPV4, dmSocket::TYPE_STREAM, dmSocket::PROTOCOL_TCP, &server_socket); |
| 1176 | if (r != dmSocket::RESULT_OK) |
| 1177 | { |
| 1178 | ctx->m_Result = r; |
| 1179 | dmAtomicStore32(&ctx->m_Completed, 1); |
| 1180 | return; |
| 1181 | } |
| 1182 | |
| 1183 | r = dmSocket::SetReuseAddress(server_socket, true); |
| 1184 | if (r != dmSocket::RESULT_OK) |
| 1185 | goto bail; |
| 1186 | |
| 1187 | r = dmSocket::GetHostByName(DM_UNIVERSAL_BIND_ADDRESS_IPV4, &bind_address, true, false); |
| 1188 | if (r != dmSocket::RESULT_OK) |
| 1189 | goto bail; |
| 1190 | |
| 1191 | r = dmSocket::Bind(server_socket, bind_address, 0); |
| 1192 | if (r != dmSocket::RESULT_OK) |
| 1193 | goto bail; |
| 1194 | |
| 1195 | r = dmSocket::Listen(server_socket, 8); |
| 1196 | if (r != dmSocket::RESULT_OK) |
| 1197 | goto bail; |
| 1198 | |
| 1199 | r = dmSocket::GetName(server_socket, &server_name, &ctx->m_Port); |
| 1200 | if (r != dmSocket::RESULT_OK) |
| 1201 | goto bail; |
| 1202 | |
| 1203 | r = dmSocket::SetBlocking(server_socket, false); |
| 1204 | if (r != dmSocket::RESULT_OK) |
| 1205 | goto bail; |
| 1206 | |
| 1207 | dmAtomicStore32(&ctx->m_Listening, 1); |
| 1208 | |
| 1209 | for (uint32_t i = 0; i < 500 && !dmAtomicGet32(&ctx->m_Stop); ++i) |
| 1210 | { |
| 1211 | dmSocket::Address client_address; |
| 1212 | r = dmSocket::Accept(server_socket, &client_address, &client_socket); |
| 1213 | if (r == dmSocket::RESULT_WOULDBLOCK) |
| 1214 | { |
| 1215 | dmTime::Sleep(10 * 1000); |
| 1216 | continue; |
| 1217 | } |
| 1218 | if (r != dmSocket::RESULT_OK) |
| 1219 | goto bail; |
| 1220 | |
| 1221 | dmAtomicStore32(&ctx->m_Accepted, 1); |
| 1222 | |
| 1223 | char request[4]; |
| 1224 | int total_read = 0; |
nothing calls this directly
no test coverage detected