Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
ServerSocket.h
1 /*
2  * ServerSocket class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2012, IRIT UPS.
6  *
7  * ELM is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * ELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with ELM; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_NET_SERVERSOCKET_H_
22 #define ELM_NET_SERVERSOCKET_H_
23 
24 #include <elm/io/InStream.h>
25 #include <elm/io/OutStream.h>
26 #include <elm/net/Exception.h>
27 
28 namespace elm { namespace net {
29 
30 class Connection {
31 public:
32  virtual ~Connection(void);
33  virtual io::InStream& in(void) = 0;
34  virtual io::OutStream& out(void) = 0;
35 };
36 
37 class ServerSocket {
38 public:
39  static ServerSocket *make(void);
40  static ServerSocket *make(int port);
41  virtual ~ServerSocket(void);
42  virtual int port(void) const = 0;
43  virtual void open(void) = 0;
44  virtual Connection *listen(void) = 0;
45  virtual void close(void) = 0;
46 };
47 
48 class Server {
49 public:
50  Server(void);
51  Server(int port);
52  virtual ~Server(void);
53  inline int port(void) const { if(sock) return sock->port(); else return -1; }
54  void open(void);
55  void manage(void);
56  void close(void);
57 protected:
58  virtual void onConnection(Connection& connection) = 0;
59 private:
60  int _port;
61  ServerSocket *sock;
62  bool on;
63 };
64 
65 } } // elm::net
66 
67 #endif /* ELM_NET_SERVERSOCKET_H_ */
elm::net::Server::onConnection
virtual void onConnection(Connection &connection)=0
elm::net::Server::manage
void manage(void)
Definition: net_ServerSocket.cpp:448
elm::net::ServerSocket::~ServerSocket
virtual ~ServerSocket(void)
Definition: net_ServerSocket.cpp:360
elm::net::Connection
Definition: ServerSocket.h:30
elm::net::Server::port
int port(void) const
Definition: ServerSocket.h:53
elm::net::ServerSocket
Definition: ServerSocket.h:37
elm::net::Server::open
void open(void)
Definition: net_ServerSocket.cpp:424
elm::net::Connection::~Connection
virtual ~Connection(void)
Definition: net_ServerSocket.cpp:95
elm::net::Server::close
void close(void)
Definition: net_ServerSocket.cpp:437
elm::net::ServerSocket::port
virtual int port(void) const =0
elm
Definition: adapter.h:26
elm::net::Server::Server
Server(void)
Definition: net_ServerSocket.cpp:402
elm::net::Server::~Server
virtual ~Server(void)
Definition: net_ServerSocket.cpp:416
elm::net::Connection::out
virtual io::OutStream & out(void)=0
elm::io::OutStream
Definition: OutStream.h:30
elm::net::ServerSocket::open
virtual void open(void)=0
elm::net::Server
Definition: ServerSocket.h:48
elm::net::ServerSocket::make
static ServerSocket * make(void)
Definition: net_ServerSocket.cpp:343
elm::net::ServerSocket::listen
virtual Connection * listen(void)=0
elm::net::Connection::in
virtual io::InStream & in(void)=0
elm::net::ServerSocket::close
virtual void close(void)=0
elm::io::InStream
Definition: InStream.h:29