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 #include <sys/types.h>
00097 #include <sys/socket.h>
00098 #include <netinet/in.h>
00099 #include <pthread.h>
00100
00101 #include <libplayercore/playercore.h>
00102
00104 #define PLAYERTCP_DEFAULT_PORT 6665
00105
00108 #define PLAYERTCP_READBUFFER_SIZE 65536
00109
00112 #define PLAYERTCP_WRITEBUFFER_SIZE 65536
00113
00114
00115 struct pollfd;
00116
00117 struct playertcp_listener;
00118 struct playertcp_conn;
00119
00120 class PlayerTCP
00121 {
00122 private:
00123 uint32_t host;
00124 int num_listeners;
00125 playertcp_listener* listeners;
00126 struct pollfd* listen_ufds;
00127
00128 pthread_mutex_t clients_mutex;
00129 int size_clients;
00130 int num_clients;
00131 playertcp_conn* clients;
00132 struct pollfd* client_ufds;
00133
00135 char* decode_readbuffer;
00137 int decode_readbuffersize;
00138
00139 void Lock();
00140 void Unlock();
00141
00142 public:
00143 PlayerTCP();
00144 ~PlayerTCP();
00145
00146
00147 static void InitGlobals(void);
00148
00149 pthread_t thread;
00150
00151 int Listen(int* ports, int num_ports, int* new_ports=NULL);
00152 int Listen(int port);
00153 QueuePointer AddClient(struct sockaddr_in* cliaddr,
00154 unsigned int local_host,
00155 unsigned int local_port,
00156 int newsock,
00157 bool send_banner,
00158 int* kill_flag,
00159 bool have_lock);
00160 int Update(int timeout);
00161 int Accept(int timeout);
00162 void Close(int cli);
00163 int ReadClient(int cli);
00164 int ReadClient(QueuePointer q);
00165 int Read(int timeout, bool have_lock);
00166 int Write(bool have_lock);
00167 int WriteClient(int cli);
00168 void DeleteClients();
00169 void ParseBuffer(int cli);
00170 int HandlePlayerMessage(int cli, Message* msg);
00171 void DeleteClient(QueuePointer &q, bool have_lock);
00172 bool Listening(int port);
00173 uint32_t GetHost() {return host;};
00174 };
00175
00178 #endif
Last updated 12 September 2005 21:38:45
|