playertcp.h
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2005 -
* Brian Gerkey
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/********************************************************************
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
********************************************************************/
/*
* Interface to libplayertcp
*
* $Id: playertcp.h 7878 2009-06-23 11:14:00Z thjc $
*/
#ifndef _PLAYERTCP_H_
#define _PLAYERTCP_H_
#if defined (WIN32)
#if defined (PLAYER_STATIC)
#define PLAYERTCP_EXPORT
#elif defined (playertcp_EXPORTS)
#define PLAYERTCP_EXPORT __declspec (dllexport)
#else
#define PLAYERTCP_EXPORT __declspec (dllimport)
#endif
#else
#define PLAYERTCP_EXPORT
#endif
#if defined (WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netdb.h>
#include <netinet/in.h>
#endif
#include <sys/types.h>
#include <pthread.h>
#include <libplayercore/playercore.h>
#define PLAYERTCP_DEFAULT_PORT 6665
#define PLAYERTCP_READBUFFER_SIZE 65536
#define PLAYERTCP_WRITEBUFFER_SIZE 65536
// Forward declarations
struct pollfd;
struct playertcp_listener;
struct playertcp_conn;
class PLAYERTCP_EXPORT PlayerTCP
{
private:
uint32_t host;
int num_listeners;
playertcp_listener* listeners;
struct pollfd* listen_ufds;
pthread_mutex_t clients_mutex;
int size_clients;
int num_clients;
playertcp_conn* clients;
struct pollfd* client_ufds;
char* decode_readbuffer;
int decode_readbuffersize;
public:
PlayerTCP();
~PlayerTCP();
void Lock();
void Unlock();
static void InitGlobals(void);
pthread_t thread;
int Listen(int* ports, int num_ports, int* new_ports=NULL);
int Listen(int port);
QueuePointer AddClient(struct sockaddr_in* cliaddr,
unsigned int local_host,
unsigned int local_port,
int newsock,
bool send_banner,
int* kill_flag,
bool have_lock);
QueuePointer AddClient(struct sockaddr_in* cliaddr,
unsigned int local_host,
unsigned int local_port,
int newsock,
bool send_banner,
int* kill_flag,
bool have_lock,
QueuePointer queue);
int Update(int timeout);
int Accept(int timeout);
void Close(int cli);
int ReadClient(int cli);
int ReadClient(QueuePointer q);
int Read(int timeout, bool have_lock);
int Write(bool have_lock);
int WriteClient(int cli);
void DeleteClients();
void ParseBuffer(int cli);
int HandlePlayerMessage(int cli, Message* msg);
void DeleteClient(QueuePointer &q, bool have_lock);
bool Listening(int port);
uint32_t GetHost() {return host;};
};
#endif
Message
Reference-counted message objects.
Definition: message.h:132
QueuePointer
An autopointer for the message queue.
Definition: message.h:73
PlayerTCP::decode_readbuffer
char * decode_readbuffer
Buffer in which to store decoded incoming messages.
Definition: playertcp.h:154
PlayerTCP::decode_readbuffersize
int decode_readbuffersize
Total size of decode_readbuffer.
Definition: playertcp.h:156
PlayerTCP
Definition: playertcp.h:139
PLAYERTCP_EXPORT
#define PLAYERTCP_EXPORT
Default TCP port.
Definition: playertcp.h:105

Last updated 12 September 2005 21:38:45