Planeshift
connection.h
Go to the documentation of this file.
1 /*
2  * connection.h by Matze Braun <matze@braunis.de>
3  *
4  * Copyright (C) 2002 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 #ifndef __CONNECTION_H__
20 #define __CONNECTION_H__
21 
22 #include <csutil/threading/thread.h>
23 
24 #include "net/netbase.h"
25 
26 struct iObjectRegistry;
27 
42 class psNetConnection : public NetBase, public CS::Threading::Runnable
43 {
44 public:
46  psNetConnection(int queueLength = 100);
48  virtual ~psNetConnection();
49 
51  bool Initialize(iObjectRegistry* object_reg);
52 
63  bool Connect(const char *server, int port);
64 
67  void DisConnect();
68 
70  virtual void Broadcast (MsgEntry* me, int scope, int guildID);
71 
73  virtual void Multicast (MsgEntry* me, const csArray<PublishDestination>& multi, uint32_t except, float range);
74 
76  virtual void IncRef ()
77  {}
79  virtual void DecRef ()
80  {}
81 
82  virtual int GetRefCount() { return 1; }
83 
84 protected:
86  virtual Connection *GetConnByIP (LPSOCKADDR_IN addr);
88  virtual Connection *GetConnByNum (uint32_t clientnum);
90  virtual bool HandleUnknownClient (LPSOCKADDR_IN addr, MsgEntry *data);
91 
99  void CheckLinkDead (csTicks time);
100 
107 
110  iObjectRegistry* object_reg;
111 
113  bool shouldRun;
114 
116  void Run ();
117 
118 private:
120  csRef<CS::Threading::Thread> thread;
121 };
122 
125 #endif
bool Initialize(iObjectRegistry *object_reg)
Just some basic initialization for the class.
This class holds data for a connection.
Definition: netbase.h:684
void DisConnect()
Kills the thread and closes the socket.
MsgQueue * inQueue
This is the inbound queue to the client.
Definition: connection.h:106
bool shouldRun
When this is false, thread will finish it&#39;s last loop and exit.
Definition: connection.h:113
virtual void IncRef()
Necessary CS definition and stub function.
Definition: connection.h:76
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
#define LPSOCKADDR_IN
Definition: sockuni.h:70
virtual void DecRef()
Necessary CS definition and stub function.
Definition: connection.h:79
Client-side UDP handler.
Definition: connection.h:42
iObjectRegistry * object_reg
Definition: connection.h:110
virtual Connection * GetConnByNum(uint32_t clientnum)
Returns the server connection if the clientnum is 0.
virtual void Multicast(MsgEntry *me, const csArray< PublishDestination > &multi, uint32_t except, float range)
Multicasting makes no sense in a single connection class. Just wraps SendMessage. ...
virtual ~psNetConnection()
Disconnects and terminates the thread.
void Run()
this is the main thread function...
This class acts as a base for client/server net classes.
Definition: netbase.h:116
A queue of smart pointers with locking facilties for multi-threading.
Definition: genrefqueue.h:39
Connection * server
Connection class holds the IP address and port we are using here.
Definition: connection.h:109
psNetConnection(int queueLength=100)
Creates a queue of messages queueLength wide.
virtual int GetRefCount()
Definition: connection.h:82
bool Connect(const char *server, int port)
Connects to the server and starts the thread to poll it.
virtual Connection * GetConnByIP(LPSOCKADDR_IN addr)
Returns the same address back if the address is correct. NULL if not.
virtual bool HandleUnknownClient(LPSOCKADDR_IN addr, MsgEntry *data)
Another overridden function only used by multi-connection class NetManager.
void CheckLinkDead(csTicks time)
This checks the time since the last packet received from the server.
virtual void Broadcast(MsgEntry *me, int scope, int guildID)
Broadcasting makes no sense in a single connection class. Just wraps SendMessage. ...