2003-11-25 03:11:50 +01:00
|
|
|
#ifndef _NetworkInternal_H
|
|
|
|
#define _NetworkInternal_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
2005-08-09 17:55:44 +02:00
|
|
|
#if !OS_WIN
|
2003-11-25 03:11:50 +01:00
|
|
|
|
|
|
|
#define Network_GetErrorString(_error, _buf, _buflen) strerror_r(_error, _buf, _buflen)
|
|
|
|
|
|
|
|
#define Network_LastError errno
|
|
|
|
|
|
|
|
#define closesocket(_fd) close(_fd)
|
2005-08-09 17:55:44 +02:00
|
|
|
|
|
|
|
#else // i.e. #if OS_WIN
|
2003-11-25 03:11:50 +01:00
|
|
|
|
|
|
|
#define Network_GetErrorString(_error, _buf, _buflen) \
|
|
|
|
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, _error+WSABASEERR, 0, _buf, _buflen, NULL)
|
|
|
|
#define Network_LastError (WSAGetLastError() - WSABASEERR)
|
|
|
|
// These are defined so that WSAGLE - WSABASEERR = E*
|
|
|
|
// i.e. the same error name can be used in winsock and posix
|
|
|
|
#define WSABASEERR 10000
|
|
|
|
|
|
|
|
#define EWOULDBLOCK (35)
|
|
|
|
#define ENETDOWN (50)
|
|
|
|
#define ENETUNREACH (51)
|
|
|
|
#define ENETRESET (52)
|
|
|
|
#define ENOTCONN (57)
|
|
|
|
#define ESHUTDOWN (58)
|
|
|
|
#define ENOTCONN (57)
|
|
|
|
#define ECONNABORTED (53)
|
|
|
|
#define ECONNRESET (54)
|
|
|
|
#define ETIMEDOUT (60)
|
|
|
|
#define EADDRINUSE (48)
|
|
|
|
#define EADDRNOTAVAIL (49)
|
|
|
|
#define ECONNREFUSED (61)
|
|
|
|
#define EHOSTUNREACH (65)
|
|
|
|
|
|
|
|
#define MSG_SOCKET_READY WM_USER
|
|
|
|
|
2005-08-09 17:55:44 +02:00
|
|
|
#endif // #if OS_WIN
|
2003-11-25 03:11:50 +01:00
|
|
|
|
|
|
|
typedef int socket_t;
|
|
|
|
|
|
|
|
class CSocketInternal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
socket_t m_fd;
|
2004-03-08 03:06:38 +01:00
|
|
|
CSocketAddress m_RemoteAddr;
|
2003-11-25 03:11:50 +01:00
|
|
|
|
|
|
|
socket_t m_AcceptFd;
|
2004-03-08 03:06:38 +01:00
|
|
|
CSocketAddress m_AcceptAddr;
|
2003-11-25 03:11:50 +01:00
|
|
|
|
|
|
|
// Bitwise OR of all operations to listen for.
|
|
|
|
// See READ and WRITE
|
|
|
|
uint m_Ops;
|
|
|
|
|
|
|
|
char *m_pConnectHost;
|
|
|
|
int m_ConnectPort;
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
u64 m_SentBytes;
|
|
|
|
u64 m_RecvBytes;
|
2003-11-25 03:11:50 +01:00
|
|
|
|
|
|
|
inline CSocketInternal():
|
|
|
|
m_fd(-1),
|
2003-11-30 17:43:42 +01:00
|
|
|
m_AcceptFd(-1),
|
|
|
|
m_Ops(0),
|
|
|
|
m_pConnectHost(NULL),
|
2005-02-21 18:13:31 +01:00
|
|
|
m_ConnectPort(-1),
|
|
|
|
m_SentBytes(0),
|
|
|
|
m_RecvBytes(0)
|
2003-11-25 03:11:50 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CSocketSetInternal
|
|
|
|
{
|
|
|
|
// Any access to the global variables should be protected using m_Mutex
|
|
|
|
pthread_mutex_t m_Mutex;
|
|
|
|
pthread_t m_Thread;
|
2005-01-29 17:51:13 +01:00
|
|
|
|
|
|
|
uint m_NumSockets;
|
2003-11-25 03:11:50 +01:00
|
|
|
|
2004-07-04 17:41:17 +02:00
|
|
|
std::map <socket_t, CSocketBase * > m_HandleMap;
|
2005-08-09 17:55:44 +02:00
|
|
|
#if OS_WIN
|
2003-11-25 03:11:50 +01:00
|
|
|
HWND m_hWnd;
|
|
|
|
#else
|
|
|
|
// [0] is for use by RunWaitLoop, [1] for SendWaitLoopAbort and SendWaitLoopUpdate
|
|
|
|
int m_Pipe[2];
|
|
|
|
#endif
|
|
|
|
|
2005-02-21 18:13:31 +01:00
|
|
|
u64 m_GlobalSentBytes;
|
|
|
|
u64 m_GlobalRecvBytes;
|
|
|
|
|
2003-11-25 03:11:50 +01:00
|
|
|
public:
|
|
|
|
inline CSocketSetInternal()
|
|
|
|
{
|
2005-08-09 17:55:44 +02:00
|
|
|
#if OS_WIN
|
2003-11-25 03:11:50 +01:00
|
|
|
m_hWnd=NULL;
|
|
|
|
#else
|
|
|
|
m_Pipe[0]=-1;
|
|
|
|
m_Pipe[1]=-1;
|
|
|
|
#endif
|
|
|
|
pthread_mutex_init(&m_Mutex, NULL);
|
|
|
|
m_Thread=0;
|
2005-01-29 17:51:13 +01:00
|
|
|
m_NumSockets=0;
|
2005-02-21 18:13:31 +01:00
|
|
|
m_GlobalSentBytes=0;
|
|
|
|
m_GlobalRecvBytes=0;
|
2003-11-25 03:11:50 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|