1
0
Fork 0

Use SG_LOG(&strerror) instead of "perror".

Also clean-up some error messages.
This commit is contained in:
ThorstenB 2011-08-20 23:11:21 +02:00
parent cf2236351c
commit d76a0b09f8

View file

@ -420,24 +420,24 @@ FGMultiplayMgr::init (void)
mTimeUntilSend = 0.0; mTimeUntilSend = 0.0;
mCallsign = fgGetString("/sim/multiplay/callsign"); mCallsign = fgGetString("/sim/multiplay/callsign");
if (!txAddress.empty()) { if ((!txAddress.empty()) && (txAddress!="0")) {
mServer.set(txAddress.c_str(), txPort); mServer.set(txAddress.c_str(), txPort);
if (strncmp (mServer.getHost(), "0.0.0.0", 8) == 0) { if (strncmp (mServer.getHost(), "0.0.0.0", 8) == 0) {
mHaveServer = false; mHaveServer = false;
SG_LOG(SG_NETWORK, SG_WARN, SG_LOG(SG_NETWORK, SG_ALERT,
"FGMultiplayMgr - could not resolve '" "FGMultiplayMgr - Could not resolve '"
<< txAddress << "', Multiplayermode disabled"); << txAddress << "'. Multiplayer mode disabled.");
return; return;
} else { } else {
SG_LOG(SG_NETWORK, SG_INFO, "have server"); SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - have server");
mHaveServer = true; mHaveServer = true;
} }
if (rxPort <= 0) if (rxPort <= 0)
rxPort = txPort; rxPort = txPort;
} }
if (rxPort <= 0) { if (rxPort <= 0) {
SG_LOG(SG_NETWORK, SG_DEBUG, SG_LOG(SG_NETWORK, SG_ALERT,
"FGMultiplayMgr - No receiver port, Multiplayermode disabled"); "FGMultiplayMgr - No receiver port. Multiplayer mode disabled.");
return; return;
} }
if (mCallsign.empty()) if (mCallsign.empty())
@ -451,14 +451,14 @@ FGMultiplayMgr::init (void)
mSocket.reset(new simgear::Socket()); mSocket.reset(new simgear::Socket());
if (!mSocket->open(false)) { if (!mSocket->open(false)) {
SG_LOG( SG_NETWORK, SG_WARN, SG_LOG( SG_NETWORK, SG_WARN,
"FGMultiplayMgr::init - Failed to create data socket" ); "FGMultiplayMgr - Failed to create data socket." );
return; return;
} }
mSocket->setBlocking(false); mSocket->setBlocking(false);
if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) { if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) {
perror("bind"); SG_LOG( SG_NETWORK, SG_ALERT,
SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr - Failed to bind receive socket. Multiplayer mode disabled. "
"FGMultiplayMgr::Open - Failed to bind receive socket" ); << strerror(errno) << "(errno " << errno << ")");
return; return;
} }
@ -856,15 +856,24 @@ FGMultiplayMgr::update(double dt)
////////////////////////////////////////////////// //////////////////////////////////////////////////
if (RecvStatus == 0) if (RecvStatus == 0)
break; break;
// socket error reported? // socket error reported?
if (RecvStatus < 0) // errno isn't thread-safe - so only check its value when
// socket return status < 0 really indicates a failure.
if ((RecvStatus < 0)&&
((errno == EAGAIN) || (errno == 0))) // MSVC output "NoError" otherwise
{ {
// errno isn't thread-safe - so only check its value when // ignore "normal" errors
// socket return status < 0 really indicates a failure. break;
if (errno != EAGAIN && errno != 0) // MSVC output "NoError" otherwise
perror("FGMultiplayMgr::MP_ProcessData");
break;
} }
if (RecvStatus<0)
{
SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::MP_ProcessData - Unable to receive data. "
<< strerror(errno) << "(errno " << errno << ")");
break;
}
// status is positive: bytes received // status is positive: bytes received
bytes = (ssize_t) RecvStatus; bytes = (ssize_t) RecvStatus;
if (bytes <= static_cast<ssize_t>(sizeof(T_MsgHdr))) { if (bytes <= static_cast<ssize_t>(sizeof(T_MsgHdr))) {