-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPSocket.h
More file actions
48 lines (42 loc) · 2.52 KB
/
TCPSocket.h
File metadata and controls
48 lines (42 loc) · 2.52 KB
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
#ifndef TCPSOCKET_H
#define TCPSOCKET_H
#include "includes.h"
class TCPSocket // TCP Socket Class
{
private:
char remote_address[128]; // Remote IP address of socket connection.
char my_address[128]; // The local IP address of the socket connection.
struct sockaddr_in myAddr; // Socket connection structure.
int port; // TCP socket port number.
int sock; // Socket Descriptor.
bool peerDisconnected; // A flag indicating the socket peer status.
bool rshutdown; // A flag indicating that a read shutdown was performed.
bool wshutdown; // A flag indicating that a write shutdown was performed.
long stream_out_size; // An integer representing the accumulated amount of data sent so far.
public:
// A constructor that allows creating a socket object after socket is created.
TCPSocket (int _sock ,char * _address=NULL,int _port=0,int readBufferSize=65536,int writeBufferSize=65536);
// A constructor that performs all the client connection initialization to a server socket
TCPSocket (char * _address, int port,int readBufferSize=65536,int writeBufferSize=65536);
char * getRemoteAddress(); // Selector returning remote IP address
char * getMyAddress(); // Selector returning local IP address
int readFromSocket (char * buffer, int maxBytes ); // Blocking read data from socket with an upperbound size
// Blocking read data from socket with an upperbound size with a maximum timeout sec.milli-sec
int readFromSocketWithTimeout (char * buffer, int maxBytes, long timeoutSec, long timeoutMilli);
// Write data to a socket with a specified size.
int writeToSocket (const char * buffer, long maxBytes );
// Set the status of the socket peer as disconnected
void setPeerDisconnected(bool value);
// Check if the socket peer is connected
bool isPeerDisconnected();
// Perform a read shutdown
void shutDownRead();
// Perform a write shutdown
void shutDownWrite();
// Perform a bidirectional (Read/Write) shutdown
void shutDown();
// Get the amount of data written to a socket after invoking the writeToSocket method.
long getStreamOutSize();
~TCPSocket ( ); // Destructor: shutdown the target socket and deallocate all its resources
};
#endif // TCPSOCKET_H