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 #include <stdint.h>
00028 #endif
00029
00030 namespace Jack
00031 {
00032
00033 #define E(code, s) { code, s }
00034 #define NET_ERROR_CODE WSAGetLastError()
00035 #define StrError PrintError
00036
00037 typedef uint32_t uint;
00038 typedef int SOCKLEN;
00039 typedef struct _win_net_error win_net_error_t;
00040
00041 struct _win_net_error
00042 {
00043 int code;
00044 const char* msg;
00045 };
00046
00047 SERVER_EXPORT const char* PrintError(int error);
00048
00049
00050 class SERVER_EXPORT JackNetWinSocket
00051 {
00052 private:
00053 int fSockfd;
00054 int fPort;
00055 SOCKADDR_IN fSendAddr;
00056 SOCKADDR_IN fRecvAddr;
00057 public:
00058 JackNetWinSocket();
00059 JackNetWinSocket(const char* ip, int port);
00060 JackNetWinSocket(const JackNetWinSocket&);
00061 ~JackNetWinSocket();
00062
00063 JackNetWinSocket& operator=(const JackNetWinSocket&);
00064
00065
00066 int NewSocket();
00067 int Bind();
00068 int BindWith(const char* ip);
00069 int BindWith(int port);
00070 int Connect();
00071 int ConnectTo(const char* ip);
00072 void Close();
00073 void Reset();
00074 bool IsSocket();
00075
00076
00077 void SetPort(int port);
00078 int GetPort();
00079
00080
00081 int SetAddress(const char* ip, int port);
00082 char* GetSendIP();
00083 char* GetRecvIP();
00084
00085
00086 int GetName(char* name);
00087 int JoinMCastGroup(const char* mcast_ip);
00088
00089
00090 int SetOption(int level, int optname, const void* optval, SOCKLEN optlen);
00091 int GetOption(int level, int optname, void* optval, SOCKLEN* optlen);
00092
00093
00094 int SetTimeOut(int usec);
00095
00096
00097 int SetLocalLoop();
00098
00099 bool IsLocal(char* ip);
00100
00101
00102 int SendTo(const void* buffer, size_t nbytes, int flags);
00103 int SendTo(const void* buffer, size_t nbytes, int flags, const char* ip);
00104 int Send(const void* buffer, size_t nbytes, int flags);
00105 int RecvFrom(void* buffer, size_t nbytes, int flags);
00106 int Recv(void* buffer, size_t nbytes, int flags);
00107 int CatchHost(void* buffer, size_t nbytes, int flags);
00108
00109
00110 net_error_t GetError();
00111 };
00112 }
00113
00114 #endif
00115