Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 943531e944a720939fa7b92791e40c32291ce5c2 (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
55
56
57
58
59
/*
   net/tcpclient.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_TCPCLIENT_H__
#define __INCLUDED_NET_TCPCLIENT_H__

#include <string>

namespace net
{

/// A TCP client, connected to a file descriptor
class TCPClient
{
public:
	/// A new TCP client, connected to a file descriptor
	TCPClient(int tcpclientfd);
	
	/// Delete the TCP client
	/// If the file descriptor is still open, it will be closed.
	virtual ~TCPClient();
	
	/// Returns the error state
	bool error() const;
	
	/// Returns true if the TCP client has a valid file descriptor
	bool valid() const;
	
	/// Returns true if the TCP client has an invalid file descriptor
	bool invalid() const;
	
	/// Returns the file descriptor the TCP client is connected to
	int fd() const;
	
	/// Sets the error state
	void abort();
	
	/// Sends outgoing data
	virtual void send(std::string const &msg);

	/// receives incoming data
	virtual void receive(std::string &msg);

protected:	
	/// Called by receive() when the client has disconnected
	/// @see receive
	virtual void client_disconnect();
	
private:
	int			tcpclient_fd;
	bool			tcpclient_error;
};

}

#endif //__INCLUDED_CORE_TCPCLIENT_H__