MCPcopy Create free account
hub / github.com/defold/defold / Update

Function Update

engine/dlib/src/dlib/http_server.cpp:584–680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

582 }
583
584 Result Update(HServer server)
585 {
586 if (server->m_Reconnect)
587 {
588 dmLogWarning("Reconnecting http server (%d)", server->m_Port);
589 Connect(server, server->m_Port);
590 server->m_Reconnect = 0;
591 }
592 dmSocket::Selector selector;
593 dmSocket::SelectorSet(&selector, dmSocket::SELECTOR_KIND_READ, server->m_ServerSocket);
594
595 dmSocket::Result r = dmSocket::Select(&selector, 0);
596
597 if (r != dmSocket::RESULT_OK)
598 {
599 return RESULT_SOCKET_ERROR;
600 }
601
602 // Check for new connections
603 if (dmSocket::SelectorIsSet(&selector, dmSocket::SELECTOR_KIND_READ, server->m_ServerSocket))
604 {
605 dmSocket::Address address;
606 dmSocket::Socket client_socket;
607 r = dmSocket::Accept(server->m_ServerSocket, &address, &client_socket);
608 if (r == dmSocket::RESULT_OK)
609 {
610 if (server->m_Connections.Full())
611 {
612 dmLogWarning("Out of client connections in http server (max: %d)", server->m_Connections.Capacity());
613 dmSocket::Shutdown(client_socket, dmSocket::SHUTDOWNTYPE_READWRITE);
614 dmSocket::Delete(client_socket);
615 }
616 else
617 {
618 dmSocket::SetNoDelay(client_socket, true);
619 Connection connection;
620 memset(&connection, 0, sizeof(connection));
621 connection.m_Socket = client_socket;
622 connection.m_ConnectionTimeStart = dmTime::GetMonotonicTime();
623 server->m_Connections.Push(connection);
624 }
625 }
626 else if (r == dmSocket::RESULT_CONNABORTED || r == dmSocket::RESULT_NOTCONN)
627 {
628 server->m_Reconnect = 1;
629 }
630 }
631
632 dmSocket::SelectorZero(&selector);
633
634 uint64_t current_time = dmTime::GetMonotonicTime();
635
636 // Iterate over persistent connections, timeout phase
637 for (uint32_t i = 0; i < server->m_Connections.Size(); ++i)
638 {
639 Connection* connection = &server->m_Connections[i];
640 uint64_t time_diff = current_time - connection->m_ConnectionTimeStart;
641 if (time_diff > server->m_ConnectionTimeout)

Callers

nothing calls this directly

Calls 15

SelectorSetFunction · 0.85
SelectorIsSetFunction · 0.85
SelectorZeroFunction · 0.85
HandleConnectionFunction · 0.85
ConnectFunction · 0.70
SelectFunction · 0.70
AcceptFunction · 0.70
ShutdownFunction · 0.70
DeleteFunction · 0.70
SetNoDelayFunction · 0.70
GetMonotonicTimeFunction · 0.70
FullMethod · 0.45

Tested by

no test coverage detected