Cuberite
A lightweight, fast and extensible game server for Minecraft
ServerHandleImpl.h
Go to the documentation of this file.
1 
2 // ServerHandleImpl.h
3 
4 // Declares the cServerHandleImpl class implementing the TCP server functionality
5 
6 // This is an internal header, no-one outside OSSupport should need to include it; use Network.h instead
7 
8 
9 
10 
11 
12 #pragma once
13 
14 #include "Network.h"
15 #include <event2/listener.h>
16 #include "CriticalSection.h"
17 
18 
19 
20 
21 
22 // fwd:
24 typedef std::shared_ptr<cTCPLinkImpl> cTCPLinkImplPtr;
25 typedef std::vector<cTCPLinkImplPtr> cTCPLinkImplPtrs;
27 typedef std::shared_ptr<cServerHandleImpl> cServerHandleImplPtr;
28 typedef std::vector<cServerHandleImplPtr> cServerHandleImplPtrs;
29 
30 
31 
32 
33 
35  public cServerHandle
36 {
38  friend class cTCPLinkImpl;
39 
40 public:
42  virtual ~cServerHandleImpl() override;
43 
48  UInt16 a_Port,
49  cNetwork::cListenCallbacksPtr a_ListenCallbacks
50  );
51 
52  // cServerHandle overrides:
53  virtual void Close(void) override;
54  virtual bool IsListening(void) const override { return m_IsListening; }
55 
56 protected:
59 
61  evconnlistener * m_ConnListener;
62 
64  evconnlistener * m_SecondaryConnListener;
65 
68 
71 
74 
77 
80 
83 
84 
85 
89 
92  bool Listen(UInt16 a_Port);
93 
95  static void Callback(evconnlistener * a_Listener, evutil_socket_t a_Socket, sockaddr * a_Addr, int a_Len, void * a_Self);
96 
99  void RemoveLink(const cTCPLinkImpl * a_Link);
100 };
101 
102 
103 
104 
105 
cTCPLinkImplPtrs m_Connections
Container for all currently active connections on this server.
virtual ~cServerHandleImpl() override
Closes the server, dropping all the connections.
std::vector< cServerHandleImplPtr > cServerHandleImplPtrs
virtual bool IsListening(void) const override
Returns true if the server has been started correctly and is currently listening for incoming connect...
int m_ErrorCode
Contains the error code for the failure to listen.
cServerHandleImpl(cNetwork::cListenCallbacksPtr a_ListenCallbacks)
Creates a new instance with the specified callbacks.
Interface that provides the methods available on a listening server socket.
Definition: Network.h:145
static cServerHandleImplPtr Listen(UInt16 a_Port, cNetwork::cListenCallbacksPtr a_ListenCallbacks)
Creates a new server instance listening on the specified port.
cServerHandle super
cServerHandleImplPtr m_SelfPtr
The SharedPtr to self, so that it can be passed to created links.
evconnlistener * m_ConnListener
The LibEvent handle representing the main listening socket.
static void Callback(evconnlistener *a_Listener, evutil_socket_t a_Socket, sockaddr *a_Addr, int a_Len, void *a_Self)
The callback called by LibEvent upon incoming connection.
std::shared_ptr< cTCPLinkImpl > cTCPLinkImplPtr
void RemoveLink(const cTCPLinkImpl *a_Link)
Removes the specified link from m_Connections.
virtual void Close(void) override
Stops the server, no more incoming connections will be accepted.
std::shared_ptr< cServerHandleImpl > cServerHandleImplPtr
cNetwork::cListenCallbacksPtr m_ListenCallbacks
The callbacks used to notify about incoming connections.
unsigned short UInt16
Definition: Globals.h:114
std::string AString
Definition: StringUtils.h:13
std::vector< cTCPLinkImplPtr > cTCPLinkImplPtrs
bool m_IsListening
Set to true when the server is initialized successfully and is listening for incoming connections...
evconnlistener * m_SecondaryConnListener
The LibEvent handle representing the secondary listening socket (only when side-by-side listening is ...
cCriticalSection m_CS
Mutex protecting m_Connections againt multithreaded access.
AString m_ErrorMsg
Contains the error message for the failure to listen.
std::shared_ptr< cListenCallbacks > cListenCallbacksPtr
Definition: Network.h:264