#include <TcpConnection.h>

Inheritance diagram for TcpConnection:
Collaboration diagram for TcpConnection:

Public Member Functions

 TcpConnection (bool autoDestruct)
 
 TcpConnection (tcp_pcb *connection, bool autoDestruct)
 
virtual ~TcpConnection ()
 
virtual bool connect (const String &server, int port, bool useSsl=false)
 
virtual bool connect (IpAddress addr, uint16_t port, bool useSsl=false)
 
virtual void close ()
 
void setAutoSelfDestruct (bool state)
 
int writeString (const char *data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Writes string data directly to the TCP buffer. More...
 
int writeString (const String &data, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Writes string data directly to the TCP buffer. More...
 
virtual int write (const char *data, int len, uint8_t apiflags=TCP_WRITE_FLAG_COPY)
 Base write operation. More...
 
int write (IDataSourceStream *stream)
 Writes stream data directly to the TCP buffer. More...
 
uint16_t getAvailableWriteSize ()
 
void flush ()
 
void setTimeOut (uint16_t waitTimeOut)
 
IpAddress getRemoteIp () const
 
uint16_t getRemotePort () const
 
void setDestroyedDelegate (TcpConnectionDestroyedDelegate destroyedDelegate)
 Sets a callback to be called when the object instance is destroyed. More...
 
void setSslInitHandler (Ssl::Session::InitDelegate handler)
 Set the SSL session initialisation callback. More...
 
bool setSslConnection (Ssl::Connection *connection)
 
Ssl::SessiongetSsl ()
 Get a pointer to the current SSL session object. More...
 
- Public Member Functions inherited from IpConnection
bool joinMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to add a local network interface to multicast group. More...
 
bool joinMulticastGroup (IpAddress multicastIp)
 Uses IGMP to add all local network interfaces to multicast group. More...
 
bool leaveMulticastGroup (IpAddress localIp, IpAddress multicastIp)
 Uses IGMP to remove a local network interface from multicast group. More...
 
bool leaveMulticastGroup (IpAddress multicastIp)
 Uses IGMP to remove all local network interfaces from multicast group. More...
 

Protected Member Functions

void initialize (tcp_pcb *pcb)
 
bool internalConnect (IpAddress addr, uint16_t port)
 
bool sslCreateSession ()
 
virtual void sslInitSession (Ssl::Session &session)
 Override in inherited classes to perform custom session initialisation. More...
 
virtual err_t onConnected (err_t err)
 
virtual err_t onReceive (pbuf *buf)
 
virtual err_t onSent (uint16_t len)
 
virtual err_t onPoll ()
 
virtual void onError (err_t err)
 
virtual void onReadyToSendData (TcpConnectionEvent sourceEvent)
 
virtual void onClosed ()
 Gets called when there is/was a tcp connection, the latter does not have to be established, that is closed due to error or normal disconnect. More...
 
void trySend (TcpConnectionEvent event)
 
err_t internalOnConnected (err_t err)
 
err_t internalOnReceive (pbuf *p, err_t err)
 
err_t internalOnSent (uint16_t len)
 
err_t internalOnPoll ()
 
void internalOnError (err_t err)
 
void internalOnDnsResponse (const char *name, LWIP_IP_ADDR_T *ipaddr, int port)
 

Protected Attributes

tcp_pcb * tcp = nullptr
 
uint16_t sleep = 0
 
uint16_t timeOut = USHRT_MAX
 By default a TCP connection does not have a time out. More...
 
bool canSend = true
 
bool autoSelfDestruct = true
 
Ssl::Sessionssl = nullptr
 
Ssl::Session::InitDelegate sslInit
 
bool useSsl = false
 

Constructor & Destructor Documentation

◆ TcpConnection() [1/2]

TcpConnection::TcpConnection ( bool  autoDestruct)
inline

◆ TcpConnection() [2/2]

TcpConnection::TcpConnection ( tcp_pcb *  connection,
bool  autoDestruct 
)
inline

◆ ~TcpConnection()

virtual TcpConnection::~TcpConnection ( )
virtual

Member Function Documentation

◆ close()

virtual void TcpConnection::close ( )
virtual

Reimplemented in TcpClient.

◆ connect() [1/2]

virtual bool TcpConnection::connect ( const String server,
int  port,
bool  useSsl = false 
)
virtual

Reimplemented in TcpClient, and HttpClientConnection.

◆ connect() [2/2]

virtual bool TcpConnection::connect ( IpAddress  addr,
uint16_t  port,
bool  useSsl = false 
)
virtual

Reimplemented in TcpClient.

◆ flush()

void TcpConnection::flush ( )

◆ getAvailableWriteSize()

uint16_t TcpConnection::getAvailableWriteSize ( )
inline

◆ getRemoteIp()

IpAddress TcpConnection::getRemoteIp ( ) const
inline

◆ getRemotePort()

uint16_t TcpConnection::getRemotePort ( ) const
inline

◆ getSsl()

Ssl::Session* TcpConnection::getSsl ( )
inline

Get a pointer to the current SSL session object.

Note that this is typically used so we can query properties of an established session. If you need to change session parameters this must be done via setSslInitHandler.

◆ initialize()

void TcpConnection::initialize ( tcp_pcb *  pcb)
protected

◆ internalConnect()

bool TcpConnection::internalConnect ( IpAddress  addr,
uint16_t  port 
)
protected

◆ internalOnConnected()

err_t TcpConnection::internalOnConnected ( err_t  err)
protected

◆ internalOnDnsResponse()

void TcpConnection::internalOnDnsResponse ( const char *  name,
LWIP_IP_ADDR_T ipaddr,
int  port 
)
protected

◆ internalOnError()

void TcpConnection::internalOnError ( err_t  err)
protected

◆ internalOnPoll()

err_t TcpConnection::internalOnPoll ( )
protected

◆ internalOnReceive()

err_t TcpConnection::internalOnReceive ( pbuf *  p,
err_t  err 
)
protected

◆ internalOnSent()

err_t TcpConnection::internalOnSent ( uint16_t  len)
protected

◆ onClosed()

virtual void TcpConnection::onClosed ( )
inlineprotectedvirtual

Gets called when there is/was a tcp connection, the latter does not have to be established, that is closed due to error or normal disconnect.

Note
This method can be used to trigger reconnects

Reimplemented in TcpClient, and HttpClientConnection.

◆ onConnected()

virtual err_t TcpConnection::onConnected ( err_t  err)
protectedvirtual

Reimplemented in TcpClient, HttpClientConnection, and FtpDataStream.

◆ onError()

virtual void TcpConnection::onError ( err_t  err)
protectedvirtual

Reimplemented in TcpClient, and HttpConnection.

◆ onPoll()

virtual err_t TcpConnection::onPoll ( )
protectedvirtual

◆ onReadyToSendData()

virtual void TcpConnection::onReadyToSendData ( TcpConnectionEvent  sourceEvent)
protectedvirtual

◆ onReceive()

virtual err_t TcpConnection::onReceive ( pbuf *  buf)
protectedvirtual

◆ onSent()

virtual err_t TcpConnection::onSent ( uint16_t  len)
protectedvirtual

Reimplemented in TcpClient, and FtpServerConnection.

◆ setAutoSelfDestruct()

void TcpConnection::setAutoSelfDestruct ( bool  state)
inline

◆ setDestroyedDelegate()

void TcpConnection::setDestroyedDelegate ( TcpConnectionDestroyedDelegate  destroyedDelegate)
inline

Sets a callback to be called when the object instance is destroyed.

Parameters
destroyedDelegate

◆ setSslConnection()

bool TcpConnection::setSslConnection ( Ssl::Connection connection)
inline

◆ setSslInitHandler()

void TcpConnection::setSslInitHandler ( Ssl::Session::InitDelegate  handler)
inline

Set the SSL session initialisation callback.

Parameters
handler

◆ setTimeOut()

void TcpConnection::setTimeOut ( uint16_t  waitTimeOut)

◆ sslCreateSession()

bool TcpConnection::sslCreateSession ( )
protected

◆ sslInitSession()

virtual void TcpConnection::sslInitSession ( Ssl::Session session)
inlineprotectedvirtual

Override in inherited classes to perform custom session initialisation.

Called when TCP connection is established before initiating handshake.

Reimplemented in HttpClientConnection.

◆ trySend()

void TcpConnection::trySend ( TcpConnectionEvent  event)
inlineprotected

◆ write() [1/2]

virtual int TcpConnection::write ( const char *  data,
int  len,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
virtual

Base write operation.

Parameters
data
len
apiflagsTCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
Return values
intnegative on error, 0 when retry is needed or positive on success

◆ write() [2/2]

int TcpConnection::write ( IDataSourceStream stream)

Writes stream data directly to the TCP buffer.

Parameters
stream
apiflagsTCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
Return values
intnegative on error, 0 when retry is needed or positive on success

◆ writeString() [1/2]

int TcpConnection::writeString ( const char *  data,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
inline

Writes string data directly to the TCP buffer.

Parameters
datanull terminated string
apiflagsTCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
Return values
intnegative on error, 0 when retry is needed or positive on success

◆ writeString() [2/2]

int TcpConnection::writeString ( const String data,
uint8_t  apiflags = TCP_WRITE_FLAG_COPY 
)
inline

Writes string data directly to the TCP buffer.

Parameters
data
apiflagsTCP_WRITE_FLAG_COPY, TCP_WRITE_FLAG_MORE
Return values
intnegative on error, 0 when retry is needed or positive on success

Member Data Documentation

◆ autoSelfDestruct

bool TcpConnection::autoSelfDestruct = true
protected

◆ canSend

bool TcpConnection::canSend = true
protected

◆ sleep

uint16_t TcpConnection::sleep = 0
protected

◆ ssl

Ssl::Session* TcpConnection::ssl = nullptr
protected

◆ sslInit

Ssl::Session::InitDelegate TcpConnection::sslInit
protected

◆ tcp

tcp_pcb* TcpConnection::tcp = nullptr
protected

◆ timeOut

uint16_t TcpConnection::timeOut = USHRT_MAX
protected

By default a TCP connection does not have a time out.

◆ useSsl

bool TcpConnection::useSsl = false
protected

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