Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
server.hpp
1 //////////////////////////////
2 //
3 // File: lxs/network/server.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Feb 14 2013
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __LXS_SERVER_H__
15 #define __LXS_SERVER_H__
16 #include <sys/socket.h>
17 
18 namespace LxS
19 {
20  namespace Network
21  {
22  //! server serving internet connections
23  class Server
24  {
25  bool active;
26  bool stop_ordered;
27  int port;
28  protected:
29  //! if connection is received, thread for it is spawned and fd and addr is given.
30  virtual void ServiceNewConnection(int fd, sockaddr * sa);
31  public:
32  Server();
33  //! port on which to listen
34  void SetTCPPort(int p) {port = p;}
35  //! get port
36  int GetTCPPort() {return port;}
37  //! start server
38  void Listen();
39  //! stop server
40  void StopServer();
41  //! is server running?
42  bool IsRunning() {return active;}
43  //! dtor
44  virtual ~Server();
45  };
46  }
47 }
48 
49 
50 #endif