Easy Simple Network Library  0.3.7
Server.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of "esnetwork" library.
4 It is licensed under the terms of the BSD license.
5 For the latest info, see http://esnetwork.sourceforge.net
6 
7 Copyright (c) 2012-2013 Lin Jia Jun (Joe Lam)
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 
13 1. Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 -----------------------------------------------------------------------------
30 */
31 
32 #ifndef _ESN_SERVER_H_INCLUDED_
33 #define _ESN_SERVER_H_INCLUDED_
34 
35 #include <vector>
36 
37 #include "Session.h"
38 #include "IoFilter.h"
39 #include "IoHandler.h"
40 #include "IoBufferManager.h"
41 #include "IoServiceManager.h"
42 
43 namespace esnlib
44 {
45 
47 class Server
48 {
49 public:
50 
51  Server();
52  virtual ~Server();
53 
58  virtual bool Start(int port) = 0;
59 
65  virtual bool Start(const std::string& ipstr, int port) = 0;
66 
68  virtual void Stop() = 0;
69 
73  virtual bool Listening() = 0;
74 
78  virtual int GetCurrentPort() = 0;
79 
83  virtual std::string GetCurrentIp() = 0;
84 
88  virtual std::string GetDefaultLocalIp() = 0;
89 
93  virtual void Broadcast(IoBufferPtr data) = 0;
94 
98  virtual int GetSessionCount() = 0;
99 
104  virtual int GetSessions(std::vector<SessionPtr>& sessions) = 0;
105 
110  virtual SessionPtr GetSessionById(int id) = 0;
111 
116  virtual void SetIdleTime(int idletype, int idletime) = 0;
117 
121  virtual void SetIoHandler(IoHandlerPtr handler) = 0;
122 
126  virtual void SetIoFilter(IoFilterPtr filter) = 0;
127 
131  virtual void SetIoBufferManager(IoBufferManagerPtr manager) = 0;
132 
136  virtual void SetIoServiceManager(IoServiceManagerPtr manager) = 0;
137 
142  virtual IoBufferPtr GetFreeBuffer(int bufsize) = 0;
143 
147  virtual bool HasGlobalData() = 0;
148 
152  virtual CommonDataPtr GetGlobalData() = 0;
153 
161  virtual bool EnableSsl(const std::string& certfile, const std::string& keyfile, const std::string& password, const std::string& verifyfile = std::string()) = 0;
162 
166  virtual bool HasSsl() = 0;
167 
168 };
169 
170 typedef boost::shared_ptr<Server> ServerPtr;
171 
176 ServerPtr CreateServer(int maxConnectQueueSize = 2048, int readBufferSize = 8192, int writeBufferSize = 8192);
183 
186 }
187 
188 #endif // _ESN_SERVER_H_INCLUDED_
189 
virtual void Stop()=0
Stop listening.
virtual int GetSessions(std::vector< SessionPtr > &sessions)=0
virtual void SetIdleTime(int idletype, int idletime)=0
virtual bool Listening()=0
virtual CommonDataPtr GetGlobalData()=0
virtual SessionPtr GetSessionById(int id)=0
ServerPtr CreateServer(int maxConnectQueueSize=2048, int readBufferSize=8192, int writeBufferSize=8192)
virtual void SetIoBufferManager(IoBufferManagerPtr manager)=0
virtual int GetSessionCount()=0
virtual void Broadcast(IoBufferPtr data)=0
virtual void SetIoFilter(IoFilterPtr filter)=0
virtual int GetCurrentPort()=0
virtual void SetIoHandler(IoHandlerPtr handler)=0
virtual std::string GetCurrentIp()=0
virtual bool EnableSsl(const std::string &certfile, const std::string &keyfile, const std::string &password, const std::string &verifyfile=std::string())=0
Server class (interface)
Definition: Server.h:47
virtual std::string GetDefaultLocalIp()=0
virtual void SetIoServiceManager(IoServiceManagerPtr manager)=0
Definition: Buffer.h:37
virtual bool HasSsl()=0
virtual bool Start(int port)=0
virtual bool HasGlobalData()=0
virtual IoBufferPtr GetFreeBuffer(int bufsize)=0