mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
implement timeouts via non-blocking connects
This commit is contained in:
parent
3f591aabc8
commit
00a3bd8462
@ -147,8 +147,8 @@ PT(Connection) ConnectionManager::
|
|||||||
open_TCP_client_connection(const NetAddress &address, int timeout_ms) {
|
open_TCP_client_connection(const NetAddress &address, int timeout_ms) {
|
||||||
Socket_TCP *socket = new Socket_TCP;
|
Socket_TCP *socket = new Socket_TCP;
|
||||||
|
|
||||||
#if defined(HAVE_THREADS) && defined(SIMPLE_THREADS)
|
// We always open the connection with non-blocking mode first, so we
|
||||||
// In the simple-threads case, use a non-blocking connect.
|
// can implement the timeout.
|
||||||
bool okflag = socket->ActiveOpenNonBlocking(address.get_addr());
|
bool okflag = socket->ActiveOpenNonBlocking(address.get_addr());
|
||||||
if (okflag && socket->GetLastError() == LOCAL_CONNECT_BLOCKING) {
|
if (okflag && socket->GetLastError() == LOCAL_CONNECT_BLOCKING) {
|
||||||
// Now wait for the socket to connect.
|
// Now wait for the socket to connect.
|
||||||
@ -171,12 +171,6 @@ open_TCP_client_connection(const NetAddress &address, int timeout_ms) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
// In the normal case, we can just do a blocking connect.
|
|
||||||
bool okflag = socket->ActiveOpen(address.get_addr(), false);
|
|
||||||
|
|
||||||
#endif // SIMPLE_THREADS
|
|
||||||
|
|
||||||
if (!okflag) {
|
if (!okflag) {
|
||||||
net_cat.error()
|
net_cat.error()
|
||||||
<< "Unable to open TCP connection to server "
|
<< "Unable to open TCP connection to server "
|
||||||
@ -185,6 +179,14 @@ open_TCP_client_connection(const NetAddress &address, int timeout_ms) {
|
|||||||
return PT(Connection)();
|
return PT(Connection)();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(HAVE_THREADS) || !defined(SIMPLE_THREADS)
|
||||||
|
// Now we have opened the socket in nonblocking mode. Unless we're
|
||||||
|
// using SIMPLE_THREADS, though, we really want the socket in
|
||||||
|
// blocking mode (since that's what we support here). Change it.
|
||||||
|
socket->SetBlocking();
|
||||||
|
|
||||||
|
#endif // SIMPLE_THREADS
|
||||||
|
|
||||||
net_cat.info()
|
net_cat.info()
|
||||||
<< "Opened TCP connection to server " << address.get_ip_string() << " "
|
<< "Opened TCP connection to server " << address.get_ip_string() << " "
|
||||||
<< " on port " << address.get_port() << "\n";
|
<< " on port " << address.get_port() << "\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user