summaryrefslogtreecommitdiff
path: root/lib/server/SocketStream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/server/SocketStream.cpp')
-rw-r--r--lib/server/SocketStream.cpp56
1 files changed, 22 insertions, 34 deletions
diff --git a/lib/server/SocketStream.cpp b/lib/server/SocketStream.cpp
index 7faff8c3..5cb252bd 100644
--- a/lib/server/SocketStream.cpp
+++ b/lib/server/SocketStream.cpp
@@ -150,11 +150,9 @@ void SocketStream::Open(int Type, const char *Name, int Port)
Socket::NameLookupToSockAddr(addr, sockDomain, Type, Name, Port, addrLen);
// Create the socket
- mSocketHandle = ::socket(sockDomain, SOCK_STREAM,
- 0 /* let OS choose protocol */);
+ mSocketHandle = ::socket(sockDomain, SOCK_STREAM, 0 /* let OS choose protocol */);
if(mSocketHandle == INVALID_SOCKET_VALUE)
{
- BOX_LOG_SYS_ERROR("Failed to create a network socket");
THROW_EXCEPTION(ServerException, SocketOpenError)
}
@@ -165,15 +163,22 @@ void SocketStream::Open(int Type, const char *Name, int Port)
#ifdef WIN32
DWORD err = WSAGetLastError();
::closesocket(mSocketHandle);
- BOX_LOG_WIN_ERROR_NUMBER("Failed to connect to socket "
- "(type " << Type << ", name " << Name <<
- ", port " << Port << ")", err);
-#else // !WIN32
- BOX_LOG_SYS_ERROR("Failed to connect to socket (type " <<
- Type << ", name " << Name << ", port " << Port <<
- ")");
+#else
+ int err = errno;
::close(mSocketHandle);
-#endif // WIN32
+#endif
+
+#ifdef WIN32
+ BOX_ERROR("Failed to connect to socket (type " << Type <<
+ ", name " << Name << ", port " << Port << "): " <<
+ GetErrorMessage(err)
+ );
+#else
+ BOX_ERROR("Failed to connect to socket (type " << Type <<
+ ", name " << Name << ", port " << Port << "): " <<
+ strerror(err) << " (" << err << ")"
+ );
+#endif
mSocketHandle = INVALID_SOCKET_VALUE;
THROW_EXCEPTION(ConnectionException, Conn_SocketConnectError)
@@ -215,9 +220,7 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout)
else
{
// Bad!
- BOX_LOG_SYS_ERROR("Failed to poll socket");
- THROW_EXCEPTION(ServerException,
- SocketPollError)
+ THROW_EXCEPTION(ServerException, SocketPollError)
}
break;
@@ -247,12 +250,9 @@ int SocketStream::Read(void *pBuffer, int NBytes, int Timeout)
else
{
// Other error
- BOX_LOG_SYS_ERROR("Failed to read from socket");
- THROW_EXCEPTION(ConnectionException,
- Conn_SocketReadError);
+ THROW_EXCEPTION(ConnectionException, Conn_SocketReadError)
}
}
-
// Closed for reading?
if(r == 0)
{
@@ -297,9 +297,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes)
{
// Error.
mWriteClosed = true; // assume can't write again
- BOX_LOG_SYS_ERROR("Failed to write to socket");
- THROW_EXCEPTION(ConnectionException,
- Conn_SocketWriteError);
+ THROW_EXCEPTION(ConnectionException, Conn_SocketWriteError)
}
// Knock off bytes sent
@@ -312,9 +310,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes)
// Need to wait until it can send again?
if(bytesLeft > 0)
{
- BOX_TRACE("Waiting to send data on socket " <<
- mSocketHandle << " (" << bytesLeft <<
- " of " << NBytes << " bytes left)");
+ TRACE3("Waiting to send data on socket %d, (%d to send of %d)\n", mSocketHandle, bytesLeft, NBytes);
// Wait for data to send.
struct pollfd p;
@@ -327,10 +323,7 @@ void SocketStream::Write(const void *pBuffer, int NBytes)
// Don't exception if it's just a signal
if(errno != EINTR)
{
- BOX_LOG_SYS_ERROR("Failed to poll "
- "socket");
- THROW_EXCEPTION(ServerException,
- SocketPollError)
+ THROW_EXCEPTION(ServerException, SocketPollError)
}
}
}
@@ -357,7 +350,6 @@ void SocketStream::Close()
if(::close(mSocketHandle) == -1)
#endif
{
- BOX_LOG_SYS_ERROR("Failed to close socket");
THROW_EXCEPTION(ServerException, SocketCloseError)
}
mSocketHandle = INVALID_SOCKET_VALUE;
@@ -388,7 +380,6 @@ void SocketStream::Shutdown(bool Read, bool Write)
// Shut it down!
if(::shutdown(mSocketHandle, how) == -1)
{
- BOX_LOG_SYS_ERROR("Failed to shutdown socket");
THROW_EXCEPTION(ConnectionException, Conn_SocketShutdownError)
}
}
@@ -467,15 +458,12 @@ bool SocketStream::GetPeerCredentials(uid_t &rUidOut, gid_t &rGidOut)
struct ucred cred;
socklen_t credLen = sizeof(cred);
- if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred,
- &credLen) == 0)
+ if(::getsockopt(mSocketHandle, SOL_SOCKET, SO_PEERCRED, &cred, &credLen) == 0)
{
rUidOut = cred.uid;
rGidOut = cred.gid;
return true;
}
-
- BOX_LOG_SYS_ERROR("Failed to get peer credentials on socket");
#endif
// Not available