3es  0.7
3esserver.h
1 //
2 // author: Kazys Stepanas
3 //
4 #ifndef _3ESSERVER_H_
5 #define _3ESSERVER_H_
6 
7 #include "3es-core.h"
8 
9 #include "3esconnection.h"
10 
11 #include <cstdint>
12 
13 namespace tes
14 {
15  class CollatedPacket;
16  class Connection;
17  class ConnectionMonitor;
18  class PacketWriter;
19  class Shape;
20  struct ServerInfoMessage;
21 
24  {
26  SF_Collate = (1<<1),
29  SF_Compress = (1<<2),
30  };
31 
32  struct _3es_coreAPI ServerSettings
33  {
35  uint16_t listenPort;
37  unsigned flags;
39  uint16_t clientBufferSize;
40 
41  // TODO: Allowed client IPs.
42 
43  inline ServerSettings(unsigned flags = SF_Collate, uint16_t port = 33500u, uint16_t bufferSize = 0xffe0)
44  : listenPort(port), flags(flags), clientBufferSize(bufferSize) {}
45  };
46 
53  class _3es_coreAPI Server : public Connection
54  {
55  public:
64  static Server *create(const ServerSettings &settings = ServerSettings(), const ServerInfoMessage *serverInfo = nullptr);
65 
67  virtual void dispose() = 0;
68 
69  protected:
71  virtual ~Server() {}
72 
73  public:
74 
76  virtual unsigned flags() const = 0;
77 
78  //---------------------
79  // Connection methods.
80  //---------------------
81 
82  using Connection::create;
83  using Connection::send;
84 
90  virtual int send(const PacketWriter &packet) = 0;
91 
105  virtual int send(const CollatedPacket &collated) = 0;
106 
109  virtual ConnectionMonitor *connectionMonitor() = 0;
110 
113  virtual unsigned connectionCount() const = 0;
114 
120  virtual Connection *connection(unsigned index) = 0;
121 
123  virtual const Connection *connection(unsigned index) const = 0;
124  };
125 }
126 
127 #endif // _3ESSERVER_H_
Definition: 3esserver.h:32
Set to compress collated outgoing packets using GZip compression.
Definition: 3esserver.h:29
Set to collate outgoing messages into larger packets.
Definition: 3esserver.h:26
Defines the interfaces for a client connection.
Definition: 3esconnection.h:19
Information about the server.
Definition: 3esmessages.h:160
virtual ~Server()
Hidden virtual destructor.
Definition: 3esserver.h:71
Defines the interface for managing a 3es server.
Definition: 3esserver.h:53
ServerFlag
Server option flags.
Definition: 3esserver.h:23
uint16_t listenPort
Port to listen on.
Definition: 3esserver.h:35
Definition: 3esbounds.h:13
uint16_t clientBufferSize
Size of the client packet buffers.
Definition: 3esserver.h:39
virtual int send(const uint8_t *data, int byteCount)=0
Send pre-prepared message data to all connections.
A utility class which generates a MtCollatedPacket message by appending multiple other messages...
Definition: 3escollatedpacket.h:51
unsigned flags
ServerFlag values.
Definition: 3esserver.h:37
virtual int create(const Shape &shape)=0
Sends a create message for the given shape.
A utility class for writing payload data to a PacketHeader.
Definition: 3espacketwriter.h:34
A utility class for monitoring new connections for a Server.
Definition: 3esconnectionmonitor.h:70