blob: 99639eb2640ed33674e14851f4e47239dfe2c0c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*
net/tcpserver.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_NET_TCPSERVER_H__
#define __INCLUDED_NET_TCPSERVER_H__
namespace net
{
#include <string>
/// A TCP server, listening on a port
class TCPServer
{
public:
/// Create a new TCP server, listening on a port
TCPServer(std::string const host, unsigned int const port);
/// Delete the TCP server. If the file descriptor is still open, it will be closed
virtual ~TCPServer();
/// Returns true if the TCP server has a valid file descriptor
bool valid() const;
/// Returns true if the TCP server has an invalid file descriptor
bool invalid() const;
/// Returns the error state of the TCP server
bool error() const;
protected:
/// accept an incoming connection
void accept();
/// Set the error state
void abort();
/// Returns the file descriptor the TCP server is listening on
int fd() const;
/// Called by accept() whenever a new client connects
virtual void client_connect(int const clientfd, std::string const host, int const port) = 0;
private:
bool tcpserver_error;
int tcpserver_fd;
};
}
#endif // __INCLUDED_NET_TCPSERVER_H__
|