|
@@ -231,10 +231,14 @@ namespace PlatformNetState
|
|
return Net::UnknownError;
|
|
return Net::UnknownError;
|
|
}
|
|
}
|
|
#else
|
|
#else
|
|
|
|
+ int theError = errno;
|
|
if (errno == EAGAIN)
|
|
if (errno == EAGAIN)
|
|
return Net::WouldBlock;
|
|
return Net::WouldBlock;
|
|
if (errno == 0)
|
|
if (errno == 0)
|
|
return Net::NoError;
|
|
return Net::NoError;
|
|
|
|
+ if (errno == EINPROGRESS)
|
|
|
|
+ return Net::WouldBlock;
|
|
|
|
+
|
|
return Net::UnknownError;
|
|
return Net::UnknownError;
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
@@ -593,7 +597,12 @@ void Net::shutdown()
|
|
Process::remove(&Net::process);
|
|
Process::remove(&Net::process);
|
|
|
|
|
|
while (gPolledSockets.size() > 0)
|
|
while (gPolledSockets.size() > 0)
|
|
- closeConnectTo(gPolledSockets[0]->handleFd);
|
|
|
|
|
|
+ {
|
|
|
|
+ if (gPolledSockets[0] == NULL)
|
|
|
|
+ gPolledSockets.erase(gPolledSockets.begin());
|
|
|
|
+ else
|
|
|
|
+ closeConnectTo(gPolledSockets[0]->handleFd);
|
|
|
|
+ }
|
|
|
|
|
|
closePort();
|
|
closePort();
|
|
PlatformNetState::initCount--;
|
|
PlatformNetState::initCount--;
|
|
@@ -623,7 +632,7 @@ static void NetAddressToIPSocket(const NetAddress *address, struct sockaddr_in *
|
|
dMemset(sockAddr, 0, sizeof(struct sockaddr_in));
|
|
dMemset(sockAddr, 0, sizeof(struct sockaddr_in));
|
|
sockAddr->sin_family = AF_INET;
|
|
sockAddr->sin_family = AF_INET;
|
|
sockAddr->sin_port = htons(address->port);
|
|
sockAddr->sin_port = htons(address->port);
|
|
- #if defined(TORQUE_OS_BSD)
|
|
|
|
|
|
+ #if defined(TORQUE_OS_BSD) || defined(TORQUE_OS_MAC)
|
|
sockAddr->sin_len = sizeof(struct sockaddr_in);
|
|
sockAddr->sin_len = sizeof(struct sockaddr_in);
|
|
#endif
|
|
#endif
|
|
if (address->type == NetAddress::IPBroadcastAddress)
|
|
if (address->type == NetAddress::IPBroadcastAddress)
|
|
@@ -862,10 +871,10 @@ void Net::closeConnectTo(NetSocket handleFd)
|
|
// if this socket is in the list of polled sockets, remove it
|
|
// if this socket is in the list of polled sockets, remove it
|
|
for (S32 i = 0; i < gPolledSockets.size(); ++i)
|
|
for (S32 i = 0; i < gPolledSockets.size(); ++i)
|
|
{
|
|
{
|
|
- if (gPolledSockets[i]->handleFd == handleFd)
|
|
|
|
|
|
+ if (gPolledSockets[i] && gPolledSockets[i]->handleFd == handleFd)
|
|
{
|
|
{
|
|
delete gPolledSockets[i];
|
|
delete gPolledSockets[i];
|
|
- gPolledSockets.erase(i);
|
|
|
|
|
|
+ gPolledSockets[i] = NULL;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1120,12 +1129,21 @@ void Net::process()
|
|
NetAddress out_h_addr;
|
|
NetAddress out_h_addr;
|
|
S32 out_h_length = 0;
|
|
S32 out_h_length = 0;
|
|
RawData readBuff;
|
|
RawData readBuff;
|
|
|
|
+ NetSocket removeSockHandle;
|
|
|
|
|
|
for (S32 i = 0; i < gPolledSockets.size();
|
|
for (S32 i = 0; i < gPolledSockets.size();
|
|
/* no increment, this is done at end of loop body */)
|
|
/* no increment, this is done at end of loop body */)
|
|
{
|
|
{
|
|
removeSock = false;
|
|
removeSock = false;
|
|
currentSock = gPolledSockets[i];
|
|
currentSock = gPolledSockets[i];
|
|
|
|
+
|
|
|
|
+ // Cleanup if we've removed it
|
|
|
|
+ if (currentSock == NULL)
|
|
|
|
+ {
|
|
|
|
+ gPolledSockets.erase(i);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
switch (currentSock->state)
|
|
switch (currentSock->state)
|
|
{
|
|
{
|
|
case PolledSocket::InvalidState:
|
|
case PolledSocket::InvalidState:
|
|
@@ -1143,9 +1161,11 @@ void Net::process()
|
|
#endif
|
|
#endif
|
|
{
|
|
{
|
|
Con::errorf("Error getting socket options: %s", strerror(errno));
|
|
Con::errorf("Error getting socket options: %s", strerror(errno));
|
|
|
|
+
|
|
|
|
+ removeSock = true;
|
|
|
|
+ removeSockHandle = currentSock->handleFd;
|
|
|
|
|
|
smConnectionNotify->trigger(currentSock->handleFd, Net::ConnectFailed);
|
|
smConnectionNotify->trigger(currentSock->handleFd, Net::ConnectFailed);
|
|
- removeSock = true;
|
|
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1167,8 +1187,11 @@ void Net::process()
|
|
{
|
|
{
|
|
// some kind of error
|
|
// some kind of error
|
|
Con::errorf("Error connecting: %s", strerror(errno));
|
|
Con::errorf("Error connecting: %s", strerror(errno));
|
|
- smConnectionNotify->trigger(currentSock->handleFd, Net::ConnectFailed);
|
|
|
|
|
|
+
|
|
removeSock = true;
|
|
removeSock = true;
|
|
|
|
+ removeSockHandle = currentSock->handleFd;
|
|
|
|
+
|
|
|
|
+ smConnectionNotify->trigger(currentSock->handleFd, Net::ConnectFailed);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -1191,18 +1214,22 @@ void Net::process()
|
|
// ack! this shouldn't happen
|
|
// ack! this shouldn't happen
|
|
if (bytesRead < 0)
|
|
if (bytesRead < 0)
|
|
Con::errorf("Unexpected error on socket: %s", strerror(errno));
|
|
Con::errorf("Unexpected error on socket: %s", strerror(errno));
|
|
|
|
+
|
|
|
|
+ removeSock = true;
|
|
|
|
+ removeSockHandle = currentSock->handleFd;
|
|
|
|
|
|
// zero bytes read means EOF
|
|
// zero bytes read means EOF
|
|
smConnectionNotify->trigger(currentSock->handleFd, Net::Disconnected);
|
|
smConnectionNotify->trigger(currentSock->handleFd, Net::Disconnected);
|
|
-
|
|
|
|
- removeSock = true;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (err != Net::NoError && err != Net::WouldBlock)
|
|
else if (err != Net::NoError && err != Net::WouldBlock)
|
|
{
|
|
{
|
|
Con::errorf("Error reading from socket: %s", strerror(errno));
|
|
Con::errorf("Error reading from socket: %s", strerror(errno));
|
|
- smConnectionNotify->trigger(currentSock->handleFd, Net::Disconnected);
|
|
|
|
|
|
+
|
|
removeSock = true;
|
|
removeSock = true;
|
|
|
|
+ removeSockHandle = currentSock->handleFd;
|
|
|
|
+
|
|
|
|
+ smConnectionNotify->trigger(currentSock->handleFd, Net::Disconnected);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case PolledSocket::NameLookupRequired:
|
|
case PolledSocket::NameLookupRequired:
|
|
@@ -1219,6 +1246,7 @@ void Net::process()
|
|
Con::errorf("DNS lookup failed: %s", currentSock->remoteAddr);
|
|
Con::errorf("DNS lookup failed: %s", currentSock->remoteAddr);
|
|
newState = Net::DNSFailed;
|
|
newState = Net::DNSFailed;
|
|
removeSock = true;
|
|
removeSock = true;
|
|
|
|
+ removeSockHandle = currentSock->handleFd;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1269,6 +1297,7 @@ void Net::process()
|
|
currentSock->remoteAddr);
|
|
currentSock->remoteAddr);
|
|
newState = Net::ConnectFailed;
|
|
newState = Net::ConnectFailed;
|
|
removeSock = true;
|
|
removeSock = true;
|
|
|
|
+ removeSockHandle = currentSock->handleFd;
|
|
}
|
|
}
|
|
|
|
|
|
if (ai_addr)
|
|
if (ai_addr)
|
|
@@ -1283,6 +1312,7 @@ void Net::process()
|
|
currentSock->remoteAddr, err);
|
|
currentSock->remoteAddr, err);
|
|
newState = Net::ConnectFailed;
|
|
newState = Net::ConnectFailed;
|
|
removeSock = true;
|
|
removeSock = true;
|
|
|
|
+ removeSockHandle = currentSock->handleFd;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1316,7 +1346,7 @@ void Net::process()
|
|
// only increment index if we're not removing the connection, since
|
|
// only increment index if we're not removing the connection, since
|
|
// the removal will shift the indices down by one
|
|
// the removal will shift the indices down by one
|
|
if (removeSock)
|
|
if (removeSock)
|
|
- closeConnectTo(currentSock->handleFd);
|
|
|
|
|
|
+ closeConnectTo(removeSockHandle);
|
|
else
|
|
else
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|