Player
Frontpage
Contents
User
Installation
Quick start
Supported devices
Tutorials
Utilities
Client libraries
FAQ
Help
Developer
Architecture
libplayercore
interfaces
libplayerdrivers
drivers
libplayercommon
libplayerutils
libplayersd
libplayertcp
libplayerxdr
TODO
Online
Homepage
Download
Project
Bugs
Help
libplayertcp
playertcp.h
1
/*
2
* Player - One Hell of a Robot Server
3
* Copyright (C) 2005 -
4
* Brian Gerkey
5
*
6
*
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
*
21
*/
22
/********************************************************************
23
*
24
* This library is free software; you can redistribute it and/or
25
* modify it under the terms of the GNU Lesser General Public
26
* License as published by the Free Software Foundation; either
27
* version 2.1 of the License, or (at your option) any later version.
28
*
29
* This library is distributed in the hope that it will be useful,
30
* but WITHOUT ANY WARRANTY; without even the implied warranty of
31
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32
* Lesser General Public License for more details.
33
*
34
* You should have received a copy of the GNU Lesser General Public
35
* License along with this library; if not, write to the Free Software
36
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37
*
38
********************************************************************/
39
40
/*
41
* Interface to libplayertcp
42
*
43
* $Id: playertcp.h 7878 2009-06-23 11:14:00Z thjc $
44
*/
45
93
#ifndef _PLAYERTCP_H_
94
#define _PLAYERTCP_H_
95
96
#if defined (WIN32)
97
#if defined (PLAYER_STATIC)
98
#define PLAYERTCP_EXPORT
99
#elif defined (playertcp_EXPORTS)
100
#define PLAYERTCP_EXPORT __declspec (dllexport)
101
#else
102
#define PLAYERTCP_EXPORT __declspec (dllimport)
103
#endif
104
#else
105
#define PLAYERTCP_EXPORT
106
#endif
107
108
#if defined (WIN32)
109
#include <winsock2.h>
110
#include <ws2tcpip.h>
111
#else
112
#include <sys/socket.h>
113
#include <sys/ioctl.h>
114
#include <netdb.h>
115
#include <netinet/in.h>
116
#endif
117
#include <sys/types.h>
118
#include <pthread.h>
119
120
#include <libplayercore/playercore.h>
121
123
#define PLAYERTCP_DEFAULT_PORT 6665
124
127
#define PLAYERTCP_READBUFFER_SIZE 65536
128
131
#define PLAYERTCP_WRITEBUFFER_SIZE 65536
132
133
// Forward declarations
134
struct
pollfd;
135
136
struct
playertcp_listener;
137
struct
playertcp_conn;
138
139
class
PLAYERTCP_EXPORT
PlayerTCP
140
{
141
private
:
142
uint32_t host;
143
int
num_listeners;
144
playertcp_listener* listeners;
145
struct
pollfd* listen_ufds;
146
147
pthread_mutex_t clients_mutex;
148
int
size_clients;
149
int
num_clients;
150
playertcp_conn* clients;
151
struct
pollfd* client_ufds;
152
154
char
*
decode_readbuffer
;
156
int
decode_readbuffersize
;
157
158
public
:
159
PlayerTCP
();
160
~
PlayerTCP
();
161
162
void
Lock();
163
void
Unlock();
164
165
static
void
InitGlobals(
void
);
166
167
pthread_t thread;
168
169
int
Listen(
int
* ports,
int
num_ports,
int
* new_ports=NULL);
170
int
Listen(
int
port);
171
QueuePointer
AddClient(
struct
sockaddr_in* cliaddr,
172
unsigned
int
local_host,
173
unsigned
int
local_port,
174
int
newsock,
175
bool
send_banner,
176
int
* kill_flag,
177
bool
have_lock);
178
QueuePointer
AddClient(
struct
sockaddr_in* cliaddr,
179
unsigned
int
local_host,
180
unsigned
int
local_port,
181
int
newsock,
182
bool
send_banner,
183
int
* kill_flag,
184
bool
have_lock,
185
QueuePointer
queue);
186
int
Update(
int
timeout);
187
int
Accept(
int
timeout);
188
void
Close(
int
cli);
189
int
ReadClient(
int
cli);
190
int
ReadClient(
QueuePointer
q);
191
int
Read(
int
timeout,
bool
have_lock);
192
int
Write(
bool
have_lock);
193
int
WriteClient(
int
cli);
194
void
DeleteClients();
195
void
ParseBuffer(
int
cli);
196
int
HandlePlayerMessage(
int
cli,
Message
* msg);
197
void
DeleteClient(
QueuePointer
&q,
bool
have_lock);
198
bool
Listening(
int
port);
199
uint32_t GetHost() {
return
host;};
200
};
201
204
#endif
Last updated 12 September 2005 21:38:45