1
0
cuberite-2a/source/cSocket.h
faketruth cf94994f8e Abstracted sockets some more to ensure the same behavior over the entire program and on multiple platforms.
MCSocket.h should soon be deprecated and deleted
Do a full rebuild (mine bugged out when I didn't)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@8 0a769ca7-a7f5-676a-18bf-c427514a06d6
2011-10-23 00:18:44 +00:00

68 lines
1.3 KiB
C++

#pragma once
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <WinSock.h>
#ifdef SendMessage
#undef SendMessage
#endif
#endif // _WIN32
class cSocket
{
#ifdef _WIN32
typedef SOCKET xSocket;
#else
typedef int xSocket;
#endif
public:
cSocket() : m_Socket( 0 ) {}
cSocket( xSocket a_Socket );
~cSocket();
bool IsValid();
void CloseSocket();
operator const xSocket() const;
xSocket GetSocket() const;
void SetSocket( xSocket a_Socket );
int SetReuseAddress();
static int WSAStartup();
static const char* GetLastErrorString();
static cSocket CreateSocket();
inline static bool IsSocketError( int a_ReturnedValue )
{
#ifdef _WIN32
return (a_ReturnedValue == SOCKET_ERROR || a_ReturnedValue == 0);
#else
return (a_ReturnedValue <= 0);
#endif
}
struct SockAddr_In
{
short Family;
unsigned short Port;
unsigned long Address;
};
static const short ADDRESS_FAMILY_INTERNET = 2;
static const unsigned long INTERNET_ADDRESS_ANY = 0;
int Bind( SockAddr_In& a_Address );
int Listen( int a_Backlog );
cSocket Accept();
int Receive( char* a_Buffer, unsigned int a_Length, unsigned int a_Flags );
char* GetIPString() { return m_IPString; }
private:
xSocket m_Socket;
char* m_IPString;
};