TDME2  1.9.200
TCPSocket.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
8 
9 using std::string;
10 
11 /**
12  * Class representing a TCP socket
13  * @author Andreas Drewke
14  */
16  public:
17  /**
18  * Creates a TCP server socket
19  * @param ip ip
20  * @param port port
21  * @param backlog backlog
22  * @throws tdme::os::network::NetworkSocketException
23  * @return socket
24  */
25  static TCPSocket* createServerSocket(const string& ip, const unsigned int port, const int backlog);
26 
27  // forbid class copy
29 
30  /**
31  * @brief Constructor
32  */
33  TCPSocket();
34 
35  /**
36  * @brief Destructor
37  */
38  virtual ~TCPSocket();
39 
40 
41  /**
42  * Disables nagle's algorithm
43  * @throws tdme::os::network::NetworkSocketException
44  */
45  void setTCPNoDelay();
46 
47  /**
48  * Connects a socket to given remote IP and port
49  * @param ip ip
50  * @param port port
51  * @throws tdme::os::network::NetworkSocketException
52  */
53  virtual void connect(const string& ip, const unsigned int port);
54 
55  /**
56  * Accepts a socket from a server socket
57  * @param _socket socket
58  * @throws tdme::os::network::NetworkSocketException
59  * @return if socket was accepted
60  */
61  virtual bool accept(TCPSocket* _socket);
62 
63  /**
64  * Reads up to "bytes" bytes from socket
65  * @param buf buffer to write to
66  * @param bytes bytes to receive
67  * @throws tdme::os::network::NetworkIOException
68  * @return bytes read
69  */
70  virtual size_t read(void* buf, const size_t bytes);
71 
72  /**
73  * Writes up to "bytes" bytes to socket
74  * @param buf buffer to read from
75  * @param bytes bytes to send
76  * @throws tdme::os::network::NetworkIOException
77  * @return bytes written
78  */
79  virtual size_t write(void* buf, const size_t bytes);
80 
81 };
82 
Base class of network sockets.
Definition: NetworkSocket.h:17
Class representing a TCP socket.
Definition: TCPSocket.h:15
virtual size_t read(void *buf, const size_t bytes)
Reads up to "bytes" bytes from socket.
Definition: TCPSocket.cpp:180
virtual size_t write(void *buf, const size_t bytes)
Writes up to "bytes" bytes to socket.
Definition: TCPSocket.cpp:192
virtual bool accept(TCPSocket *_socket)
Accepts a socket from a server socket.
Definition: TCPSocket.cpp:154
virtual ~TCPSocket()
Destructor.
Definition: TCPSocket.cpp:82
void setTCPNoDelay()
Disables nagle's algorithm.
Definition: TCPSocket.cpp:85
static TCPSocket * createServerSocket(const string &ip, const unsigned int port, const int backlog)
Creates a TCP server socket.
Definition: TCPSocket.cpp:43
virtual void connect(const string &ip, const unsigned int port)
Connects a socket to given remote IP and port.
Definition: TCPSocket.cpp:96
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6