Skip to content

Commit 10e9a12

Browse files
committed
added EADDRINUSE and printfs (deactivated) for debugging
Signed-off-by: hayati ayguen <[email protected]>
1 parent b5d145a commit 10e9a12

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/SimpleSocket.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@
4545
#ifdef _LINUX
4646
#include <sys/ioctl.h>
4747
#endif
48+
#include <string.h>
4849

49-
#define PRINT_CLOSE 0
50+
#define PRINT_CLOSE 0
51+
#define PRINT_ERRORS 0
5052

5153

5254
CSimpleSocket::CSimpleSocket(CSocketType nType) :
@@ -1502,7 +1504,8 @@ void CSimpleSocket::ClearSystemError(void)
15021504
void CSimpleSocket::TranslateSocketError(void)
15031505
{
15041506
#if defined(_LINUX) || defined(_DARWIN)
1505-
switch (errno)
1507+
int systemErrno = errno;
1508+
switch (systemErrno)
15061509
{
15071510
case EXIT_SUCCESS:
15081511
SetSocketError(CSimpleSocket::SocketSuccess);
@@ -1555,10 +1558,23 @@ void CSimpleSocket::TranslateSocketError(void)
15551558
case ENOPROTOOPT:
15561559
SetSocketError(CSimpleSocket::SocketConnectionReset);
15571560
break;
1561+
case EADDRINUSE:
1562+
SetSocketError(CSimpleSocket::SocketAddressInUse);
1563+
break;
15581564
default:
1565+
#if PRINT_ERRORS
1566+
fprintf( stderr, "\nCSimpleSocket::SocketEunknown: errno=%d: %s\n", systemErrno, strerror(systemErrno) );
1567+
#endif
15591568
SetSocketError(CSimpleSocket::SocketEunknown);
15601569
break;
15611570
}
1571+
#if PRINT_ERRORS
1572+
if ( systemErrno != EXIT_SUCCESS && systemErrno != EWOULDBLOCK )
1573+
{
1574+
fprintf( stderr, "\nCSimpleSocket Error: %s == system %s\n", DescribeError(), strerror(systemErrno) );
1575+
}
1576+
#endif
1577+
15621578
#elif defined(WIN32)
15631579
int32 nError = WSAGetLastError();
15641580
switch (nError)

0 commit comments

Comments
 (0)