00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JackNetWinSocket__
00021 #define __JackNetWinSocket__
00022
00023 #include "JackNetSocket.h"
00024 #ifdef __MINGW32__
00025 #include <winsock2.h>
00026 #include <ws2tcpip.h>
00027 #endif
00028
00029
00030 namespace Jack
00031 {
00032 #define E(code, s) { code, s }
00033 #define NET_ERROR_CODE WSAGetLastError()
00034 #define StrError PrintError
00035
00036 typedef uint32_t uint;
00037 typedef int SOCKLEN;
00038 typedef struct _win_net_error win_net_error_t;
00039
00040 struct _win_net_error
00041 {
00042 int code;
00043 const char* msg;
00044 };
00045
00046 SERVER_EXPORT const char* PrintError ( int error );
00047
00048
00049 class SERVER_EXPORT JackNetWinSocket
00050 {
00051 private:
00052 int fSockfd;
00053 int fPort;
00054 SOCKADDR_IN fSendAddr;
00055 SOCKADDR_IN fRecvAddr;
00056 public:
00057 JackNetWinSocket();
00058 JackNetWinSocket ( const char* ip, int port );
00059 JackNetWinSocket ( const JackNetWinSocket& );
00060 ~JackNetWinSocket();
00061
00062 JackNetWinSocket& operator= ( const JackNetWinSocket& );
00063
00064
00065 int NewSocket();
00066 int Bind();
00067 int BindWith ( const char* ip );
00068 int BindWith ( int port );
00069 int Connect();
00070 int ConnectTo ( const char* ip );
00071 void Close();
00072 void Reset();
00073 bool IsSocket();
00074
00075
00076 void SetPort ( int port );
00077 int GetPort();
00078
00079
00080 int SetAddress ( const char* ip, int port );
00081 char* GetSendIP();
00082 char* GetRecvIP();
00083
00084
00085 int GetName ( char* name );
00086 int JoinMCastGroup ( const char* mcast_ip );
00087
00088
00089 int SetOption ( int level, int optname, const void* optval, SOCKLEN optlen );
00090 int GetOption ( int level, int optname, void* optval, SOCKLEN* optlen );
00091
00092
00093 int SetTimeOut ( int usec );
00094
00095
00096 int SetLocalLoop();
00097
00098
00099 int SendTo ( const void* buffer, size_t nbytes, int flags );
00100 int SendTo ( const void* buffer, size_t nbytes, int flags, const char* ip );
00101 int Send ( const void* buffer, size_t nbytes, int flags );
00102 int RecvFrom ( void* buffer, size_t nbytes, int flags );
00103 int Recv ( void* buffer, size_t nbytes, int flags );
00104 int CatchHost ( void* buffer, size_t nbytes, int flags );
00105
00106
00107 net_error_t GetError();
00108 };
00109 }
00110
00111 #endif