Trippin Cyril
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
trippingcyril::net::Socket Class Reference

General tcp socket class, fully async using libevent. More...

#include <Socket.h>

Inheritance diagram for trippingcyril::net::Socket:
[legend]
Collaboration diagram for trippingcyril::net::Socket:
[legend]

Public Member Functions

 Socket (const Module *module)
 
 Socket (struct bufferevent *event)
 
virtual ~Socket ()
 
void Close () override
 
bool Connect (const String &hostname, uint16_t port, bool ssl=false, double timeout=60.0)
 
bool Connect (const IPAddress *ip, uint16_t port, bool ssl=false, double timeout=60.0)
 
int Write (const char *data, size_t len) override
 
void SetReadLine (bool b)
 
bool IsConnected () const
 
void SetTimeout (double timeout)
 
void DisableTimeout ()
 
const IPAddressGetIP () const
 
- Public Member Functions inherited from trippingcyril::trippingcyril::Event
 Event (const Module *module)
 
virtual ~Event ()
 
const ModuleGetModule () const
 
- Public Member Functions inherited from trippingcyril::Writer
int WriteString (const String &data)
 
virtual bool shouldDelete () const override
 

Protected Member Functions

virtual void Connected ()
 
virtual void Timeout ()
 
virtual void Disconnected ()
 
virtual size_t ReadData (const char *data, size_t len)
 
virtual void ReadLine (const String &line)
 
virtual void OnWrite (size_t bytes_left)
 
bool SetTCPNoDelay (bool enable)
 
bool SetTCPKeepAlive (bool enable, int delay)
 
- Protected Member Functions inherited from trippingcyril::trippingcyril::Event
event_base * GetEventBase () const
 
evdns_base * GetDNSBase () const
 

Protected Attributes

uint8_t read_more: 1
 
size_t next_read
 
- Protected Attributes inherited from trippingcyril::trippingcyril::Event
const Modulemodule
 

Additional Inherited Members

- Static Public Attributes inherited from trippingcyril::Writer
static const int BUFFER_SIZE
 

Detailed Description

General tcp socket class, fully async using libevent.

Constructor & Destructor Documentation

trippingcyril::net::Socket::Socket ( const Module module)

General constructor

Parameters
moduleThe module to register this socket on
trippingcyril::net::Socket::Socket ( struct bufferevent *  event)

Constructor used to create incoming connections

See Also
Listener
virtual trippingcyril::net::Socket::~Socket ( )
virtual

General deconstructor, will close the connection if needed

Member Function Documentation

void trippingcyril::net::Socket::Close ( )
overridevirtual

Close and remove this socket

Implements trippingcyril::Closable.

bool trippingcyril::net::Socket::Connect ( const String hostname,
uint16_t  port,
bool  ssl = false,
double  timeout = 60.0 
)

Connect the actual socket

Parameters
hostnameThe hostname to connect to
portThe port to connect to
sslTrue if you want to use a ssl socket
timeoutConnect/read/write timeout
Returns
False if already connected or trying to connect
bool trippingcyril::net::Socket::Connect ( const IPAddress ip,
uint16_t  port,
bool  ssl = false,
double  timeout = 60.0 
)

Connect the actual socket

Parameters
ipThe ip address to connect to
portThe port to connect to
sslTrue if you want to use a ssl socket
timeoutConnect/read/write timeout
Returns
False if already connected or trying to connect
virtual void trippingcyril::net::Socket::Connected ( )
inlineprotectedvirtual

Connected callback, will be called once the socket is connected.

Reimplemented in trippingcyril::net::http::SimpleHTTPSocket.

void trippingcyril::net::Socket::DisableTimeout ( )
inline

Used to disable the read/write timeouts currently set

virtual void trippingcyril::net::Socket::Disconnected ( )
inlineprotectedvirtual

Disconnected callback, will be called once our socket disconnects.

Reimplemented in trippingcyril::net::http::SimpleHTTPSocket.

const IPAddress* trippingcyril::net::Socket::GetIP ( ) const

Get the ip address of the remote end

bool trippingcyril::net::Socket::IsConnected ( ) const
inline
Returns
True if socket is connected
virtual void trippingcyril::net::Socket::OnWrite ( size_t  bytes_left)
inlineprotectedvirtual

This will get called once it wrote something to the actual socket

Parameters
bytes_leftAmount of bytes left to write in our buffer
virtual size_t trippingcyril::net::Socket::ReadData ( const char *  data,
size_t  len 
)
inlineprotectedvirtual

ReadData callback, will be called if read line mode is off. Return the amount of bytes that should be consumed. In case you are not done yet processing all the data set read_more to 1.

virtual void trippingcyril::net::Socket::ReadLine ( const String line)
inlineprotectedvirtual

ReadLine callback, will be called if read line mode is on. Return data up until a newline from the socket.

void trippingcyril::net::Socket::SetReadLine ( bool  b)
inline

Enable/disable read line mode, decides if ReadLine or ReadData should be called

bool trippingcyril::net::Socket::SetTCPKeepAlive ( bool  enable,
int  delay 
)
protected

Allows you to set a custom tcp keep alive interval, or disable tcp keep alive all together.

bool trippingcyril::net::Socket::SetTCPNoDelay ( bool  enable)
protected

Allows you to determine if the tcp no delay feature should be used or not

void trippingcyril::net::Socket::SetTimeout ( double  timeout)

Used to set a read/write timeout

virtual void trippingcyril::net::Socket::Timeout ( )
inlineprotectedvirtual

Timeout callback, will be called once either a connect, read or write timeout occurs.

Reimplemented in trippingcyril::net::http::SimpleHTTPSocket.

int trippingcyril::net::Socket::Write ( const char *  data,
size_t  len 
)
overridevirtual

Write data to socket

Parameters
dataThe actual data
lenThe length of the data
Returns
Amount of bytes written, should be equal to len

Implements trippingcyril::Writer.

Member Data Documentation

size_t trippingcyril::net::Socket::next_read
protected

Tells the underlying socket how many bytes you need for your next operation using this is not required, but doing so may improve performance. Leaving this at the default (0) will not use this feature. This feature of course only works for the non read line mode

uint8_t trippingcyril::net::Socket::read_more
protected

Determines if ReadData should get called again or not.


The documentation for this class was generated from the following file: