playertcp.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00093 #ifndef _PLAYERTCP_H_
00094 #define _PLAYERTCP_H_
00095
00096 #if defined (WIN32)
00097 #if defined (PLAYER_STATIC)
00098 #define PLAYERTCP_EXPORT
00099 #elif defined (playertcp_EXPORTS)
00100 #define PLAYERTCP_EXPORT __declspec (dllexport)
00101 #else
00102 #define PLAYERTCP_EXPORT __declspec (dllimport)
00103 #endif
00104 #else
00105 #define PLAYERTCP_EXPORT
00106 #endif
00107
00108 #if defined (WIN32)
00109 #include <winsock2.h>
00110 #include <ws2tcpip.h>
00111 #else
00112 #include <sys/socket.h>
00113 #include <sys/ioctl.h>
00114 #include <netdb.h>
00115 #include <netinet/in.h>
00116 #endif
00117 #include <sys/types.h>
00118 #include <pthread.h>
00119
00120 #include <libplayercore/playercore.h>
00121
00123 #define PLAYERTCP_DEFAULT_PORT 6665
00124
00127 #define PLAYERTCP_READBUFFER_SIZE 65536
00128
00131 #define PLAYERTCP_WRITEBUFFER_SIZE 65536
00132
00133
00134 struct pollfd;
00135
00136 struct playertcp_listener;
00137 struct playertcp_conn;
00138
00139 class PLAYERTCP_EXPORT PlayerTCP
00140 {
00141 private:
00142 uint32_t host;
00143 int num_listeners;
00144 playertcp_listener* listeners;
00145 struct pollfd* listen_ufds;
00146
00147 pthread_mutex_t clients_mutex;
00148 int size_clients;
00149 int num_clients;
00150 playertcp_conn* clients;
00151 struct pollfd* client_ufds;
00152
00154 char* decode_readbuffer;
00156 int decode_readbuffersize;
00157
00158 public:
00159 PlayerTCP();
00160 ~PlayerTCP();
00161
00162 void Lock();
00163 void Unlock();
00164
00165 static void InitGlobals(void);
00166
00167 pthread_t thread;
00168
00169 int Listen(int* ports, int num_ports, int* new_ports=NULL);
00170 int Listen(int port);
00171 QueuePointer AddClient(struct sockaddr_in* cliaddr,
00172 unsigned int local_host,
00173 unsigned int local_port,
00174 int newsock,
00175 bool send_banner,
00176 int* kill_flag,
00177 bool have_lock);
00178 QueuePointer AddClient(struct sockaddr_in* cliaddr,
00179 unsigned int local_host,
00180 unsigned int local_port,
00181 int newsock,
00182 bool send_banner,
00183 int* kill_flag,
00184 bool have_lock,
00185 QueuePointer queue);
00186 int Update(int timeout);
00187 int Accept(int timeout);
00188 void Close(int cli);
00189 int ReadClient(int cli);
00190 int ReadClient(QueuePointer q);
00191 int Read(int timeout, bool have_lock);
00192 int Write(bool have_lock);
00193 int WriteClient(int cli);
00194 void DeleteClients();
00195 void ParseBuffer(int cli);
00196 int HandlePlayerMessage(int cli, Message* msg);
00197 void DeleteClient(QueuePointer &q, bool have_lock);
00198 bool Listening(int port);
00199 uint32_t GetHost() {return host;};
00200 };
00201
00204 #endif