00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __JackNetUnixSocket__
00021 #define __JackNetUnixSocket__
00022
00023 #include "JackNetSocket.h"
00024 #include <sys/types.h>
00025 #include <sys/socket.h>
00026 #include <netdb.h>
00027 #include <netinet/in.h>
00028 #include <arpa/inet.h>
00029
00030 namespace Jack
00031 {
00032 #define NET_ERROR_CODE errno
00033 #define SOCKET_ERROR -1
00034 #define StrError strerror
00035
00036 typedef struct sockaddr socket_address_t;
00037 typedef struct in_addr address_t;
00038
00039
00040 class SERVER_EXPORT JackNetUnixSocket
00041 {
00042 private:
00043
00044 int fSockfd;
00045 int fPort;
00046 int fTimeOut;
00047
00048 struct sockaddr_in fSendAddr;
00049 struct sockaddr_in fRecvAddr;
00050 #if defined(__sun__) || defined(sun)
00051 int WaitRead();
00052 int WaitWrite();
00053 #endif
00054
00055 public:
00056
00057 JackNetUnixSocket();
00058 JackNetUnixSocket(const char* ip, int port);
00059 JackNetUnixSocket(const JackNetUnixSocket&);
00060 ~JackNetUnixSocket();
00061
00062 JackNetUnixSocket& operator=(const JackNetUnixSocket& socket);
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_t optlen);
00090 int GetOption(int level, int optname, void* optval, socklen_t* optlen);
00091
00092
00093 int SetTimeOut(int us);
00094
00095
00096 int SetLocalLoop();
00097
00098 bool IsLocal(char* ip);
00099
00100
00101 int SendTo(const void* buffer, size_t nbytes, int flags);
00102 int SendTo(const void* buffer, size_t nbytes, int flags, const char* ip);
00103 int Send(const void* buffer, size_t nbytes, int flags);
00104 int RecvFrom(void* buffer, size_t nbytes, int flags);
00105 int Recv(void* buffer, size_t nbytes, int flags);
00106 int CatchHost(void* buffer, size_t nbytes, int flags);
00107
00108
00109 net_error_t GetError();
00110 };
00111 }
00112
00113 #endif