Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::net::TCPSocket Class Reference

A TCP socket. Allows for sending and receiving data over TCP at a port. More...

#include <tcp.h>

Inheritance diagram for MaxOS::net::TCPSocket:
MaxOS::common::EventManager< TCPPayloadHandlerEvents >

Public Member Functions

 TCPSocket (TransmissionControlProtocolHandler *transmission_control_protocol_handler)
 Construct a new TCP Socket object.
 
virtual void send (uint8_t *data, uint16_t size)
 send data over the socket
 
virtual void disconnect ()
 disconnect the socket
 
void disconnected ()
 Raise the disconnected event.
 
void connected ()
 Raise the connected event.
 
bool handle_transmission_control_protocol_payload (uint8_t *data, uint16_t size)
 Handle the TCP message (socket end)
 
- Public Member Functions inherited from MaxOS::common::EventManager< TCPPayloadHandlerEvents >
void connect_event_handler (EventHandler< TCPPayloadHandlerEvents > *handler)
 connect an event handler to the event manager if it is not already connected
 
void disconnect_event_handler (EventHandler< TCPPayloadHandlerEvents > *handler)
 disconnect an event handler from the event manager if it is connected
 
Vector< Event< TCPPayloadHandlerEvents > * > raise_event (Event< TCPPayloadHandlerEvents > *event)
 Calls the on_event function of all the event m_handlers connected to the event manager and returns a list of the results.
 

Protected Attributes

uint16_t remotePort = 0
 The port on the external device.
 
uint32_t remote_ip = 0
 The IP address of the external device.
 
uint16_t local_port = 0
 The port on this device.
 
uint32_t local_ip = 0
 The IP address of this device.
 
uint32_t sequence_number = 0
 The current order number of the data being sent.
 
uint32_t acknowledgement_number = 0
 The number used to keep track of what has been received, incremented by 1 each time.
 
TransmissionControlProtocolHandlertransmission_control_protocol_handler
 The TCP handler this socket is using.
 
TCPSocketState state
 The state of the socket.
 
- Protected Attributes inherited from MaxOS::common::EventManager< TCPPayloadHandlerEvents >
Vector< EventHandler< TCPPayloadHandlerEvents > * > m_handlers
 

Friends

class TransmissionControlProtocolHandler
 
class TransmissionControlProtocolPortListener
 

Detailed Description

A TCP socket. Allows for sending and receiving data over TCP at a port.

Definition at line 174 of file tcp.h.

Constructor & Destructor Documentation

◆ TCPSocket()

TCPSocket::TCPSocket ( TransmissionControlProtocolHandler transmission_control_protocol_handler)
explicit

Construct a new TCP Socket object.

Parameters
transmission_control_protocol_handlerthe TCP handler the socket is associated with

Definition at line 83 of file tcp.cpp.

83 {
84 //Set the default values
85 this->transmission_control_protocol_handler = transmission_control_protocol_handler;
86
87 //Closed as default
88 state = TCPSocketState::CLOSED;
89}
TransmissionControlProtocolHandler * transmission_control_protocol_handler
The TCP handler this socket is using.
Definition tcp.h:187
TCPSocketState state
The state of the socket.
Definition tcp.h:188

References state, and transmission_control_protocol_handler.

Member Function Documentation

◆ connected()

void TCPSocket::connected ( )

Raise the connected event.

Definition at line 143 of file tcp.cpp.

143 {
144 auto* event = new ConnectedEvent(this);
147
148}
Vector< Event< TCPPayloadHandlerEvents > * > raise_event(Event< TCPPayloadHandlerEvents > *event)
Calls the on_event function of all the event m_handlers connected to the event manager and returns a ...
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
static void kfree(void *pointer)
Frees a block of memory using the kernel memory manager.
Event for when a TCP socket is connected.
Definition tcp.h:136

References MaxOS::memory::MemoryManager::kfree(), and MaxOS::common::EventManager< TCPPayloadHandlerEvents >::raise_event().

Referenced by MaxOS::net::TransmissionControlProtocolHandler::handle_internet_protocol_payload().

◆ disconnect()

void TCPSocket::disconnect ( )
virtual

disconnect the socket

Definition at line 126 of file tcp.cpp.

126 {
128}
void disconnect(TCPSocket *socket)
Begin the disconnect process.
Definition tcp.cpp:537

References MaxOS::net::TransmissionControlProtocolHandler::disconnect(), and transmission_control_protocol_handler.

◆ disconnected()

void TCPSocket::disconnected ( )

Raise the disconnected event.

Definition at line 133 of file tcp.cpp.

133 {
134 auto* event = new DisconnectedEvent(this);
137
138}
Event for when a TCP socket is disconnected.
Definition tcp.h:147

References MaxOS::memory::MemoryManager::kfree(), and MaxOS::common::EventManager< TCPPayloadHandlerEvents >::raise_event().

Referenced by MaxOS::net::TransmissionControlProtocolHandler::handle_internet_protocol_payload().

◆ handle_transmission_control_protocol_payload()

bool TCPSocket::handle_transmission_control_protocol_payload ( uint8_t data,
uint16_t  size 
)

Handle the TCP message (socket end)

Parameters
dataThe datah
sizeThe size of the data
Returns
True if the connection is to be terminated after hadnling or false if not

Definition at line 100 of file tcp.cpp.

100 {
101 auto* event = new DataReceivedEvent(this, data, size);
104 return true;
105}
Event for when data is received on a TCP socket.
Definition tcp.h:123

References MaxOS::memory::MemoryManager::kfree(), and MaxOS::common::EventManager< TCPPayloadHandlerEvents >::raise_event().

Referenced by MaxOS::net::TransmissionControlProtocolHandler::handle_internet_protocol_payload().

◆ send()

void TCPSocket::send ( uint8_t data,
uint16_t  size 
)
virtual

send data over the socket

Parameters
dataThe data to send
sizeThe size of the data

Definition at line 113 of file tcp.cpp.

113 {
114 //Wait for the socket to be connected
115 while(state != TCPSocketState::ESTABLISHED);
116
117 //Pass the data to the backend
119 (uint16_t) TCPFlag::PSH |
120 (uint16_t) TCPFlag::ACK);
121}
void send_transmission_control_protocol_packet(TCPSocket *socket, const uint8_t *data, uint16_t size, uint16_t flags=0)
send a packet (Throught the provider)
Definition tcp.cpp:420

References MaxOS::net::TransmissionControlProtocolHandler::send_transmission_control_protocol_packet(), state, and transmission_control_protocol_handler.

Friends And Related Symbol Documentation

◆ TransmissionControlProtocolHandler

Definition at line 175 of file tcp.h.

◆ TransmissionControlProtocolPortListener

friend class TransmissionControlProtocolPortListener
friend

Definition at line 177 of file tcp.h.

Member Data Documentation

◆ acknowledgement_number

uint32_t MaxOS::net::TCPSocket::acknowledgement_number = 0
protected

The number used to keep track of what has been received, incremented by 1 each time.

Definition at line 185 of file tcp.h.

Referenced by MaxOS::net::TransmissionControlProtocolHandler::handle_internet_protocol_payload(), and MaxOS::net::TransmissionControlProtocolHandler::send_transmission_control_protocol_packet().

◆ local_ip

uint32_t MaxOS::net::TCPSocket::local_ip = 0
protected

The IP address of this device.

Definition at line 183 of file tcp.h.

Referenced by MaxOS::net::TransmissionControlProtocolHandler::send_transmission_control_protocol_packet().

◆ local_port

uint16_t MaxOS::net::TCPSocket::local_port = 0
protected

The port on this device.

Definition at line 182 of file tcp.h.

Referenced by MaxOS::net::TransmissionControlProtocolHandler::send_transmission_control_protocol_packet().

◆ remote_ip

uint32_t MaxOS::net::TCPSocket::remote_ip = 0
protected

◆ remotePort

◆ sequence_number

uint32_t MaxOS::net::TCPSocket::sequence_number = 0
protected

◆ state

◆ transmission_control_protocol_handler

TransmissionControlProtocolHandler* MaxOS::net::TCPSocket::transmission_control_protocol_handler
protected

The TCP handler this socket is using.

Definition at line 187 of file tcp.h.

Referenced by disconnect(), send(), and TCPSocket().


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