| 206 | } |
| 207 | |
| 208 | static void dmLogUpdateNetwork() |
| 209 | { |
| 210 | dmSocket::Socket server_socket = dmSocket::INVALID_SOCKET_HANDLE; |
| 211 | bool connections_full = false; |
| 212 | { |
| 213 | DM_SPINLOCK_SCOPED_LOCK(g_LogServerLock); |
| 214 | if (!IsServerInitialized()) |
| 215 | return; |
| 216 | server_socket = g_dmLogServer->m_ServerSocket; |
| 217 | connections_full = g_dmLogServer->m_Connections.Full(); |
| 218 | } |
| 219 | |
| 220 | if (server_socket == dmSocket::INVALID_SOCKET_HANDLE) |
| 221 | return; |
| 222 | |
| 223 | dmSocket::Selector selector; |
| 224 | dmSocket::SelectorSet(&selector, dmSocket::SELECTOR_KIND_READ, server_socket); |
| 225 | dmSocket::Result r = dmSocket::Select(&selector, 0); |
| 226 | if (r == dmSocket::RESULT_OK) |
| 227 | { |
| 228 | // Check for new connections |
| 229 | if (dmSocket::SelectorIsSet(&selector, dmSocket::SELECTOR_KIND_READ, server_socket)) |
| 230 | { |
| 231 | dmSocket::Address address; |
| 232 | dmSocket::Socket client_socket; |
| 233 | r = dmSocket::Accept(server_socket, &address, &client_socket); |
| 234 | |
| 235 | if (r == dmSocket::RESULT_OK) |
| 236 | { |
| 237 | if (connections_full) |
| 238 | { |
| 239 | dmLogError("Too many log connections opened"); |
| 240 | const char* resp = "1 Too many log connections opened\n"; |
| 241 | SendAll(client_socket, resp, strlen(resp)); |
| 242 | dmSocket::Shutdown(client_socket, dmSocket::SHUTDOWNTYPE_READWRITE); |
| 243 | dmSocket::Delete(client_socket); |
| 244 | } |
| 245 | else |
| 246 | { |
| 247 | const char* resp = "0 OK\n"; |
| 248 | SendAll(client_socket, resp, strlen(resp)); |
| 249 | dmSocket::SetNoDelay(client_socket, true); |
| 250 | dmLogConnection connection; |
| 251 | memset(&connection, 0, sizeof(connection)); |
| 252 | connection.m_Socket = client_socket; |
| 253 | |
| 254 | DM_SPINLOCK_SCOPED_LOCK(g_LogServerLock); |
| 255 | if (!IsServerInitialized()) |
| 256 | return; |
| 257 | g_dmLogServer->m_Connections.Push(connection); |
| 258 | } |
| 259 | } |
| 260 | else if (r == dmSocket::RESULT_BADF || r == dmSocket::RESULT_CONNABORTED) |
| 261 | { |
| 262 | // reinitalize log socket |
| 263 | dmLogInitSocket(g_dmLogServer->m_ServerSocket); |
| 264 | } |
| 265 | } |
no test coverage detected