diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-13 22:53:01 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-13 22:53:01 +0000 |
commit | 83e8023c5e46635753a609329cf9805a3520001e (patch) | |
tree | 23df93da350bb5e9bf084b5e64b506d8831fa013 /src/net/tcpserver.h | |
parent | 4c915658355ae3eeee195ef929fdf7453397edd5 (diff) |
network subsystem initial import
Diffstat (limited to 'src/net/tcpserver.h')
-rw-r--r-- | src/net/tcpserver.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/net/tcpserver.h b/src/net/tcpserver.h new file mode 100644 index 0000000..dd87689 --- /dev/null +++ b/src/net/tcpserver.h @@ -0,0 +1,51 @@ +/* + 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 incoming connections + 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__ |