122 lines
3.0 KiB
C++
122 lines
3.0 KiB
C++
|
|
#ifndef __TCPSocket_h__
|
|
#define __TCPSocket_h__
|
|
|
|
#include "Socket.h"
|
|
#include "TLS.h"
|
|
#include "TLSInfo.h"
|
|
#include "IPAddress.h"
|
|
|
|
namespace core {
|
|
|
|
///
|
|
/// TCPSocket
|
|
///
|
|
/// Provides a network TCP socket.
|
|
///
|
|
/// For accessing TCP network functions use this object. The connection oriented nature of TCP
|
|
/// provides a single client persistent connection with data error correction and a durable
|
|
/// synchronous data connection.
|
|
///
|
|
|
|
class TCPSocket : public Socket, public TLS {
|
|
|
|
public:
|
|
|
|
///
|
|
///
|
|
///
|
|
|
|
TCPSocket(EPoll &ePoll);
|
|
|
|
///
|
|
///
|
|
///
|
|
|
|
TCPSocket(EPoll &ePoll, std::string text);
|
|
|
|
///
|
|
///
|
|
///
|
|
|
|
TCPSocket(EPoll &ePoll, TLSInfo *tlsInfo, std::string text);
|
|
|
|
///
|
|
///
|
|
///
|
|
|
|
TCPSocket(EPoll &ePoll, SSL_CTX *ctx, std::string text);
|
|
|
|
///
|
|
///
|
|
///
|
|
|
|
virtual ~TCPSocket();
|
|
|
|
///
|
|
///
|
|
///
|
|
|
|
void connect(IPAddress &address);
|
|
|
|
IPAddress ipAddress;
|
|
|
|
///
|
|
/// The output method is called by a socket session (TCPSession) and
|
|
/// will output the detail information for the client socket. When extending
|
|
/// TCPSocket or TCPSession you can override the method to add attributes
|
|
/// to the list.
|
|
///
|
|
|
|
virtual void output(std::stringstream &out);
|
|
|
|
///
|
|
/// Override this method to receive data directly from the socket as data is
|
|
/// received. If you need data split by line termination characters then
|
|
/// override the onLineReceived method instead.
|
|
///
|
|
|
|
virtual void onDataReceived(coreutils::ZString &data) override;
|
|
|
|
///
|
|
/// Override the onLineReceived method to receive a string of characters that
|
|
/// represents a single line of data terminated by a LF or CRLF. If onDataReceived
|
|
/// was overriden this method will not be called unless the onDataReceived calls
|
|
/// this method explicitly using the class and member name.
|
|
///
|
|
|
|
virtual void onLineReceived(coreutils::ZString &line);
|
|
|
|
///
|
|
/// Override the onBlockReceived method to receive a string of characters that
|
|
/// represents a single block of data of length determined by the block length value. If
|
|
/// onDataReceived was overriden this method will not be called unless the onDataReceived
|
|
/// calls this method explicitly using the class and member name.
|
|
///
|
|
|
|
virtual void onBlockReceived(coreutils::ZString &block);
|
|
|
|
///
|
|
/// Use setBlockSize to set the amount of data that should be read at once from the
|
|
/// session data buffer.
|
|
/// If this value is set to 0 then the data will be retrieved
|
|
///
|
|
|
|
void setBlockSize(int size = 0);
|
|
|
|
protected:
|
|
bool term = false;
|
|
|
|
private:
|
|
char *lineBuffer = NULL;
|
|
int lineBufferSize = 0;
|
|
int lineLength = 0;
|
|
int blockLength = 0;
|
|
int blockSize = 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|