Choco OS
V.0.16.9.0
Join to the chocolate world
|
Module that handles transmission in the TCP IP. More...
Data Structures | |
struct | oC_Tcp_Header_t |
stores TCP header More... | |
union | oC_Tcp_Packet_t |
struct | oC_Tcp_Connection_Config_t |
Typedefs | |
typedef struct Tcp_Connection_t * | oC_Tcp_Connection_t |
stores TCP connection data | |
typedef struct Server_t * | oC_Tcp_Server_t |
stores TCP server object data More... | |
Enumerations |
Functions | |
oC_ErrorCode_t | oC_Tcp_TurnOn (oC_Time_t Timeout) |
turns on TCP module More... | |
oC_ErrorCode_t | oC_Tcp_TurnOff (oC_Time_t Timeout) |
turns off TCP module More... | |
oC_ErrorCode_t | oC_Tcp_CloseProcess (oC_Process_t Process, oC_Time_t Timeout) |
closes all objects related with the process More... | |
oC_ErrorCode_t | oC_Tcp_ReservePort (oC_Tcp_Port_t *Port, oC_Time_t Timeout) |
reserves TCP port More... | |
oC_ErrorCode_t | oC_Tcp_ReleasePort (oC_Tcp_Port_t Port, oC_Time_t Timeout) |
releases TCP port More... | |
bool | oC_Tcp_IsPortReserved (oC_Tcp_Port_t Port) |
checks if the port is reserved | |
bool | oC_Tcp_IsPortReservedBy (oC_Tcp_Port_t Port, oC_Process_t Process) |
checks if the port is reserved by the given process | |
oC_ErrorCode_t | oC_Tcp_Connect (const oC_Net_Address_t *Destination, oC_Tcp_Port_t LocalPort, oC_Tcp_Connection_t *outConnection, oC_Time_t Timeout) |
connects to the remote TCP server More... | |
oC_ErrorCode_t | oC_Tcp_Disconnect (oC_Tcp_Connection_t *Connection, oC_Time_t Timeout) |
disconnects TCP connection More... | |
oC_ErrorCode_t | oC_Tcp_Listen (const oC_Net_Address_t *Source, oC_Tcp_Server_t *outServer, uint32_t MaxConnections, oC_Time_t Timeout) |
starts a server that listen at the given address More... | |
oC_ErrorCode_t | oC_Tcp_StopListen (oC_Tcp_Server_t *Server, oC_Time_t Timeout) |
stops listen at the given TCP port More... | |
oC_ErrorCode_t | oC_Tcp_Accept (oC_Tcp_Server_t Server, oC_Tcp_Connection_t *outConnection, oC_Time_t Timeout) |
waits for new connection and accepts it More... | |
oC_ErrorCode_t | oC_Tcp_Send (oC_Tcp_Connection_t Connection, const void *Buffer, oC_MemorySize_t Size, oC_Time_t Timeout) |
sends data by using TCP connection More... | |
oC_ErrorCode_t | oC_Tcp_Receive (oC_Tcp_Connection_t Connection, void *outBuffer, oC_MemorySize_t Size, oC_Time_t Timeout) |
receives data by using TCP connection More... | |
oC_Tcp_Server_t | oC_Tcp_Server_New (const oC_Net_Address_t *ListenAddress, uint32_t MaxConnections) |
creates TCP server More... | |
bool | oC_Tcp_Server_Delete (oC_Tcp_Server_t *Server, oC_Time_t Timeout) |
deletes TCP server More... | |
bool | oC_Tcp_Server_IsCorrect (oC_Tcp_Server_t Server) |
checks if the TCP server object is correct More... | |
bool | oC_Tcp_Server_IsRunning (oC_Tcp_Server_t Server) |
checks if the TCP server is already running More... | |
oC_ErrorCode_t | oC_Tcp_Server_SetConnectionConfig (oC_Tcp_Server_t Server, const oC_Tcp_Connection_Config_t *Config) |
sets connection configuration More... | |
oC_ErrorCode_t | oC_Tcp_Server_Run (oC_Tcp_Server_t Server) |
starts the TCP server More... | |
oC_ErrorCode_t | oC_Tcp_Server_Stop (oC_Tcp_Server_t Server) |
stops the TCP server More... | |
oC_ErrorCode_t | oC_Tcp_Server_WaitForConnection (oC_Tcp_Server_t Server, oC_Tcp_Connection_t *outConnection, oC_Time_t Timeout) |
Waits for new TCP connection. More... | |
bool | oC_Tcp_Server_ContainsConnection (oC_Tcp_Server_t Server, oC_Tcp_Connection_t Connection) |
checks if the server contains the connection More... | |
oC_ErrorCode_t | oC_Tcp_Server_AcceptConnection (oC_Tcp_Server_t Server, oC_Tcp_Connection_t Connection, oC_Time_t Timeout) |
accepts TCP connection More... | |
oC_ErrorCode_t | oC_Tcp_Server_RejectConnection (oC_Tcp_Server_t Server, oC_Tcp_Connection_t Connection, oC_Time_t Timeout) |
rejects TCP connection More... | |
oC_ErrorCode_t | oC_Tcp_Server_AddConnection (oC_Tcp_Server_t Server, oC_Tcp_Connection_t Connection, oC_Time_t Timeout) |
adds connection to server's connections list More... | |
oC_ErrorCode_t | oC_Tcp_Server_RemoveConnection (oC_Tcp_Server_t Server, oC_Tcp_Connection_t Connection) |
removes connection from server's connections list More... | |
oC_Process_t | oC_Tcp_Server_GetProcess (oC_Tcp_Server_t Server) |
returns process associated with the server More... | |
oC_Tcp_Port_t | oC_Tcp_Server_GetPort (oC_Tcp_Server_t Server) |
returns local port of the server More... | |
oC_ErrorCode_t | oC_Tcp_Server_SetConnectionFinished (oC_Tcp_Server_t Server, oC_Tcp_ConnectionFinishedFunction_t Function, void *Parameter) |
sets a pointer for 'connection finished function' | |
oC_Tcp_Packet_t * | oC_Tcp_Packet_New (const oC_Net_Address_t *Source, const oC_Net_Address_t *Destination, uint16_t HeaderSize, const void *Data, uint16_t Size) |
Allocates memory for a TCP packet. More... | |
bool | oC_Tcp_Packet_Delete (oC_Tcp_Packet_t **outPacket) |
releases memory allocated for a packet More... | |
oC_ErrorCode_t | oC_Tcp_Packet_SetData (oC_Tcp_Packet_t *Packet, const void *Data, uint16_t Size) |
sets data in the TCP packet | |
oC_ErrorCode_t | oC_Tcp_Packet_ReadData (oC_Tcp_Packet_t *Packet, void *outData, oC_MemorySize_t Size) |
reads data of the TCP packet | |
void | oC_Tcp_Packet_SetSize (oC_Tcp_Packet_t *Packet, uint16_t Size) |
sets size of the TCP packet | |
void * | oC_Tcp_Packet_GetDataReference (oC_Tcp_Packet_t *Packet) |
returns pointer to the data inside the packet More... | |
uint16_t | oC_Tcp_Packet_GetDataSize (oC_Tcp_Packet_t *Packet) |
returns size of data section inside TCP packet More... | |
bool | oC_Tcp_Packet_AddOption (oC_Tcp_Packet_t *Packet, oC_Tcp_OptionKind_t OptionKind, const void *Data, uint8_t Size) |
Adds TCP option to the packet. More... | |
oC_ErrorCode_t | oC_Tcp_Packet_ReadOption (oC_Tcp_Packet_t *Packet, oC_Tcp_OptionKind_t OptionKind, void *outData, uint8_t *Size) |
reads option from the TCP packet More... | |
bool | oC_Tcp_Packet_ClearOptions (oC_Tcp_Packet_t *Packet) |
clears options in the TCP packet More... | |
uint16_t | oC_Tcp_Packet_CalculateChecksum (oC_Tcp_Packet_t *Packet) |
calculates checksum for TCP packet | |
oC_Tcp_Header_t * | oC_Tcp_Packet_GetHeaderReference (oC_Tcp_Packet_t *Packet) |
returns TCP header reference | |
bool | oC_Tcp_Packet_ConvertFromNetworkEndianess (oC_Tcp_Packet_t *Packet) |
converts packet from network endianess | |
bool | oC_Tcp_Packet_ConvertToNetworkEndianess (oC_Tcp_Packet_t *Packet) |
converts packet to network endianess | |
oC_Tcp_Connection_t | oC_Tcp_Connection_New (const oC_Tcp_Connection_Config_t *Config) |
allocates memory for a new TCP connection object More... | |
typedef struct Server_t* oC_Tcp_Server_t |
The type is for storing TCP server data. It should be created by using the function oC_Tcp_Server_New and deleted by the function oC_Tcp_Server_Delete. All data inside are private and should be changed only by TCP server interface functions.
enum oC_Tcp_Port_t |
oC_ErrorCode_t oC_Tcp_Accept | ( | oC_Tcp_Server_t | Server, |
oC_Tcp_Connection_t * | outConnection, | ||
oC_Time_t | Timeout | ||
) |
The function waits for the new TCP connection, accepts it and returns it for the user by using outConnection
parameter.
Server | Server object received from the function oC_Tcp_Listen |
outConnection | Destination address for a new TCP connection |
Timeout | Maximum time to wait for a connection |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_ObjectNotCorrect | Server stores incorrect object pointer |
oC_ErrorCode_OutputAddressNotInRAM | outConnection is not correct RAM address |
oC_ErrorCode_TimeNotCorrect | The Timeout is below 0 |
oC_ErrorCode_ModuleBusy | Maximum time to wait has expired and the module is still busy |
oC_ErrorCode_ServerNotStarted | Server has not started yet |
More error codes can be returned by the functions oC_Tcp_Server_WaitForConnection and oC_Tcp_Server_AcceptConnection
oC_ErrorCode_t oC_Tcp_CloseProcess | ( | oC_Process_t | Process, |
oC_Time_t | Timeout | ||
) |
The function is for closing all TCP servers and connections that are related with the given process.
Process | Pointer to the process to close |
Timeout | Maximum time to wait for the closing operation |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_ProcessNotCorrect | Process is not correct or not valid anymore |
oC_ErrorCode_TimeNotCorrect | Timeout is below zero |
oC_ErrorCode_PermissionDenied | You are not logged as root user |
oC_ErrorCode_ModuleBusy | Module is currently in use |
oC_ErrorCode_CannotRemoveObjectFromList | a Server or a Connection cannot be removed from servers or connections list |
oC_ErrorCode_ReleaseError | There was some memory release error |
oC_ErrorCode_t oC_Tcp_Connect | ( | const oC_Net_Address_t * | Destination, |
oC_Tcp_Port_t | LocalPort, | ||
oC_Tcp_Connection_t * | outConnection, | ||
oC_Time_t | Timeout | ||
) |
The function creates new TCP connection object, connects it into the remote TCP server and push it to the local TCP connections list.
Destination | Destination IP address and destination TCP port to connect |
LocalPort | Local TCP port to reserve for this connection or 0 if first free port number should be used |
outConnection | Destination for the connection object |
Timeout | Maximum time to wait for the connection |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_WrongAddress | The Destination does not point to the correct RAM or ROM address |
oC_ErrorCode_IpAddressNotCorrect | The Destination structure stores incorrect IP address (the field Type is not set?) |
oC_ErrorCode_PortNotCorrect | The field Port inside the Destination structure cannot be 0! |
oC_ErrorCode_OutputAddressNotInRAM | The outConnection is not correct RAM address |
oC_ErrorCode_TimeNotCorrect | The Timeout is below 0 |
oC_ErrorCode_ModuleBusy | Maximum time to wait has expired and the module is still busy |
oC_ErrorCode_AllocationError | There was some problem with allocation memory for the connection |
oC_ErrorCode_CannotAddObjectToList | Connection cannot be added to the local connections list |
More error codes can be returned by the function oC_Tcp_ReservePort and #oC_Tcp_Connection_Connect
oC_Tcp_Connection_t oC_Tcp_Connection_New | ( | const oC_Tcp_Connection_Config_t * | Config | ) |
The function is designed for allocating a memory for a TCP connection object. The object is required for handling TCP connection with the remote TCP client or server. The function initializes sub-objects required by the
Definition at line 270 of file oc_tcp_connection.c.
oC_ErrorCode_t oC_Tcp_Disconnect | ( | oC_Tcp_Connection_t * | Connection, |
oC_Time_t | Timeout | ||
) |
The function disconnects TCP connection, removes object from the local TCP connections list (or from TCP servers connection list) and releases memory allocated for the connection. It can be used for connections received from functions oC_Tcp_Connect and oC_Tcp_Accept
Connection | An address to variable with Connection object received from function oC_Tcp_Connect or oC_Tcp_Accept |
Timeout | Maximum time for disconnection process |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_AddressNotInRam | The Connection does not point to the correct RAM address |
oC_ErrorCode_ObjectNotCorrect | The Connection points to incorrect connection object |
oC_ErrorCode_NotConnected | The Connection is currently not connected |
oC_ErrorCode_TimeNotCorrect | The Timeout is below 0 |
oC_ErrorCode_ModuleBusy | Maximum time to wait has expired and the module is still busy |
oC_ErrorCode_ObjectNotFoundOnList | The Connection is not from function oC_Tcp_Connect nor oC_Tcp_Accept |
oC_ErrorCode_CannotRemoveObjectFromList | Connection cannot be removed from the local connections list |
oC_ErrorCode_ReleaseError | The was a problem with releasing memory allocated for the Connection object |
More error codes can be returned by the functions called internally
oC_ErrorCode_t oC_Tcp_Listen | ( | const oC_Net_Address_t * | Source, |
oC_Tcp_Server_t * | outServer, | ||
uint32_t | MaxConnections, | ||
oC_Time_t | Timeout | ||
) |
The function starts a new TCP server that will listen at the given IP address (and the given TCP port). After call of the function it is possible to accept connections by calling the function oC_Tcp_Accept. Remember, that the function also reserves a TCP port for the current process and it has to be closed by function oC_Tcp_StopListen
Source | Source IP address (with the Port field filled) |
outServer | Destination address to return the new created server |
MaxConnections | Maximum number of connections that the server can handle at once |
Timeout | Maximum time for the operation |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_WrongAddress | Source is not correct address of RAM or ROM |
oC_ErrorCode_IpAddressNotCorrect | Source points to incorrect IP address (is Type field filled?) |
oC_ErrorCode_PortNotCorrect | Port in the Source structure is not filled (it is 0!) |
oC_ErrorCode_OutputAddressNotInRAM | The outServer does not point to the correct RAM address |
oC_ErrorCode_MaximumValueNotCorrect | The MaxConnections has to be grower than 0 |
oC_ErrorCode_TimeNotCorrect | The Timeout is below 0 |
oC_ErrorCode_ModuleBusy | Maximum time to wait has expired and the module is still busy |
oC_ErrorCode_AllocationError | There was a problem with memory allocation |
oC_ErrorCode_CannotAddObjectToList | Some error occurred during adding server to the servers list |
More error codes can be returned by the function oC_Tcp_ReservePort
bool oC_Tcp_Packet_AddOption | ( | oC_Tcp_Packet_t * | Packet, |
oC_Tcp_OptionKind_t | OptionKind, | ||
const void * | Data, | ||
uint8_t | Size | ||
) |
The function is for adding options to the TCP packet. Please check TCP RFC 2780 for more informations.
Packet | TCP packet allocated by the function oC_Tcp_Packet_New |
OptionKind | Kind of the option to add |
Data | Pointer to data to put inside the option or NULL if not used (in this case Size must be set to 0) |
Size | Size (Length) of the option's data (please check the RFC to find out what size can be given for the option - the function does not check if the size is correct) |
Definition at line 360 of file oc_tcp_packet.c.
bool oC_Tcp_Packet_ClearOptions | ( | oC_Tcp_Packet_t * | Packet | ) |
The function clears options list in the TCP packet
Packet | TCP packet allocated by the function oC_Tcp_Packet_New |
Definition at line 459 of file oc_tcp_packet.c.
bool oC_Tcp_Packet_Delete | ( | oC_Tcp_Packet_t ** | Packet | ) |
The function is for releasing memory allocated by the function oC_Tcp_Packet_New.
Packet | Pointer to the variable that keeps allocated packet - it will be set to NULL after usage |
Definition at line 170 of file oc_tcp_packet.c.
void* oC_Tcp_Packet_GetDataReference | ( | oC_Tcp_Packet_t * | Packet | ) |
The function returns pointer to the data inside TCP packet.
Packet | TCP packet allocated by the function oC_Tcp_Packet_New |
Definition at line 283 of file oc_tcp_packet.c.
uint16_t oC_Tcp_Packet_GetDataSize | ( | oC_Tcp_Packet_t * | Packet | ) |
The function returns size of the data inside TCP packet
Packet | TCP packet allocated by the function oC_Tcp_Packet_New |
Definition at line 317 of file oc_tcp_packet.c.
oC_Tcp_Packet_t* oC_Tcp_Packet_New | ( | const oC_Net_Address_t * | Source, |
const oC_Net_Address_t * | Destination, | ||
uint16_t | HeaderSize, | ||
const void * | Data, | ||
uint16_t | Size | ||
) |
The function is for creating new TCP packet. It allocates memory for a TCP header, user data and IP header. It also fills basic required fields.
Source | Source IP address (sender) |
Destination | Destination IP address (receiver) |
HeaderSize | Size of the TCP header (minimum sizeof(oC_Tcp_Header_t) ). It is required, because TCP allows for adding options to the header |
Data | NULL if not used or pointer to the buffer with data to copy inside TCP packet |
Size | Size of the data to put inside the TCP packet |
Definition at line 98 of file oc_tcp_packet.c.
oC_ErrorCode_t oC_Tcp_Packet_ReadOption | ( | oC_Tcp_Packet_t * | Packet, |
oC_Tcp_OptionKind_t | OptionKind, | ||
void * | outData, | ||
uint8_t * | Size | ||
) |
The function reads option's data from the TCP packet. Please check TCP RFC 2780 for more informations.
Packet | TCP packet allocated by the function oC_Tcp_Packet_New |
OptionKind | Kind of the TCP option to find |
outData | Destination for option data or NULL if not used |
Size | Destination for the option size on output and size of the outData buffer on input |
oC_ErrorCode_None
if success.Here is the list of standard error codes that can be returned by the function:
ErrorCode | Description |
---|---|
oC_ErrorCode_AddressNotInRam | Packet or Size are not correct RAM address |
oC_ErrorCode_ValueTooBig | OptionKind is too big |
oC_ErrorCode_OptionNotFound | The given OptionKind has not been found in the TCP packet |
oC_ErrorCode_OutputAddressNotInRAM | outData is not in RAM but it is required (size of the option is not 0) |
Definition at line 415 of file oc_tcp_packet.c.
oC_ErrorCode_t oC_Tcp_Receive | ( | oC_Tcp_Connection_t | Connection, |
void * | outBuffer, | ||
oC_MemorySize_t | Size, | ||
oC_Time_t | Timeout | ||
) |
The function is for receiving data by using TCP connection received from functions oC_Tcp_Accept or oC_Tcp_Connect.
Connection | TCP connection object received from oC_Tcp_Accept or oC_Tcp_Connect |
outBuffer | Buffer for received data |
Size | Size of the buffer |
Timeout | Maximum time to wait for sending |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
More error codes can be returned by the function #oC_Tcp_Connection_Receive
oC_ErrorCode_t oC_Tcp_ReleasePort | ( | oC_Tcp_Port_t | Port, |
oC_Time_t | Timeout | ||
) |
The function is for releasing TCP ports that has been previously reserved by the function oC_Tcp_ReservePort and are not required any more.
Port | TCP port to release (reserved by the function #oc_Tcp_ReservePort) |
Timeout | Maximum time to wait for releasing the port |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_PortNotCorrect | The Port is not correct (it cannot be 0) |
oC_ErrorCode_TimeNotCorrect | Timeout is below zero |
More error codes can be returned by the function oC_PortMan_ReleasePort
oC_ErrorCode_t oC_Tcp_ReservePort | ( | oC_Tcp_Port_t * | Port, |
oC_Time_t | Timeout | ||
) |
To prevent using the same TCP port by two different processes at the same time, each process has to reserve the TCP port before using it. This function allows to do by manual. It is also possible to reserve a first available TCP port by setting a Port
variable to 0.
Port | Pointer to the variable where the TCP port is stored. If it points to 0, the module will find a first available TCP port and set it inside this variable |
Timeout | Maximum time for the reservation operation |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_AddressNotInRam | The Port is not correct RAM address |
oC_ErrorCode_TimeNotCorrect | Timeout is below zero |
More error codes can be returned by the function oC_PortMan_ReservePort
oC_ErrorCode_t oC_Tcp_Send | ( | oC_Tcp_Connection_t | Connection, |
const void * | Buffer, | ||
oC_MemorySize_t | Size, | ||
oC_Time_t | Timeout | ||
) |
The function is for sending data by using TCP connection received from functions oC_Tcp_Accept or oC_Tcp_Connect.
Connection | TCP connection object received from oC_Tcp_Accept or oC_Tcp_Connect |
Buffer | Buffer with data to send |
Size | Size of the buffer to send |
Timeout | Maximum time to wait for sending |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
More error codes can be returned by the function #oC_Tcp_Connection_Send
oC_ErrorCode_t oC_Tcp_Server_AcceptConnection | ( | oC_Tcp_Server_t | Server, |
oC_Tcp_Connection_t | Connection, | ||
oC_Time_t | Timeout | ||
) |
The function is for accepting the TCP connections received from the function oC_Tcp_Server_WaitForConnection. After call of this function, data can be sending and receiving by using #oC_Tcp_Connection_Send and #oC_Tcp_Connection_Receive
Server | TCP Server object created by the function oC_Tcp_Server_New |
Connection | TCP Connection object received from the function oC_Tcp_Server_WaitForConnection |
Timeout | Maximum time to wait for the connection |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server or Connection is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_NotRunning | The server is not running (the function oC_Tcp_Server_Run has not been called) |
oC_ErrorCode_TimeNotCorrect | The given Timeout is below zero |
oC_ErrorCode_ConnectionFromDifferentServer | The giv server->Process = getcurprocess();en Connection is not related with the given Server |
oC_ErrorCode_Timeout | Maximum time to wait has expired |
Note, that more error code can be received from the function #oC_Tcp_Connection_Accept
Definition at line 539 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_Server_AddConnection | ( | oC_Tcp_Server_t | Server, |
oC_Tcp_Connection_t | Connection, | ||
oC_Time_t | Timeout | ||
) |
The function is for adding TCP connection to the TCP Sever's connections list.
Server | TCP Server object created by the function oC_Tcp_Server_New |
Connection | TCP Connection object received from the function oC_Tcp_Server_WaitForConnection |
Timeout | Maximum time for operation |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server or Connection is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_FoundOnList | The given Server is already associated with the given Connection |
oC_ErrorCode_NoFreeSlots | There is no more free slots for TCP connections in the server |
Definition at line 646 of file oc_tcp_server.c.
bool oC_Tcp_Server_ContainsConnection | ( | oC_Tcp_Server_t | Server, |
oC_Tcp_Connection_t | Connection | ||
) |
The function is for checking if the given TCP server handles the given TCP connection
Server | TCP Server object created by the function oC_Tcp_Server_New |
Connection | TCP Connection object received from the function oC_Tcp_Server_WaitForConnection |
Definition at line 482 of file oc_tcp_server.c.
bool oC_Tcp_Server_Delete | ( | oC_Tcp_Server_t * | Server, |
oC_Time_t | Timeout | ||
) |
The function release memory allocated for the TCP Server object and deletes all children TCP connections.
Server | Pointer to the variable that stores TCP server (it will be cleared in case of success |
Timeout | Maximum time for operation |
Definition at line 197 of file oc_tcp_server.c.
oC_Tcp_Port_t oC_Tcp_Server_GetPort | ( | oC_Tcp_Server_t | Server | ) |
The function returns local TCP port, that the server listen to.
Server | TCP Server object created by the function oC_Tcp_Server_New |
Definition at line 772 of file oc_tcp_server.c.
oC_Process_t oC_Tcp_Server_GetProcess | ( | oC_Tcp_Server_t | Server | ) |
The function returns process associated with the given TCP server - it is the process, that called the function oC_Tcp_Server_New.
Server | TCP Server object created by the function oC_Tcp_Server_New |
Definition at line 749 of file oc_tcp_server.c.
bool oC_Tcp_Server_IsCorrect | ( | oC_Tcp_Server_t | Server | ) |
The function checks if the TCP server object is correct (if it is allocated by the function oC_Tcp_Server_New and if it has not been deleted by the function oC_Tcp_Server_Delete)
Server | TCP Server object created by the function oC_Tcp_Server_New |
Definition at line 255 of file oc_tcp_server.c.
bool oC_Tcp_Server_IsRunning | ( | oC_Tcp_Server_t | Server | ) |
The function checks if the TCP server is running (if the function oC_Tcp_Server_Run has been called).
Server | TCP Server object created by the function oC_Tcp_Server_New |
Definition at line 271 of file oc_tcp_server.c.
oC_Tcp_Server_t oC_Tcp_Server_New | ( | const oC_Net_Address_t * | ListenAddress, |
uint32_t | MaxConnections | ||
) |
The function is for allocating memory for the new TCP server.
ListenAddress | Address to listen (with with filled field Port ) |
MaxConnections | Maximum number of connections handled by the server |
Definition at line 122 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_Server_RejectConnection | ( | oC_Tcp_Server_t | Server, |
oC_Tcp_Connection_t | Connection, | ||
oC_Time_t | Timeout | ||
) |
The function is for rejecting TCP connection received from the function oC_Tcp_Server_WaitForConnection.
Server | TCP Server object created by the function oC_Tcp_Server_New |
Connection | TCP Connection object received from the function oC_Tcp_Server_WaitForConnection |
Timeout | Maximum time to wait for the connection |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server or Connection is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_NotRunning | The server is not running (the function oC_Tcp_Server_Run has not been called) |
oC_ErrorCode_TimeNotCorrect | The given Timeout is below zero |
oC_ErrorCode_ConnectionFromDifferentServer | The given Connection is not related with the given Server |
oC_ErrorCode_Timeout | Maximum time to wait has expired |
Note, that more error code can be received from the functions #oC_Tcp_Connection_Reject and oC_Tcp_Server_RemoveConnection
Definition at line 595 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_Server_RemoveConnection | ( | oC_Tcp_Server_t | Server, |
oC_Tcp_Connection_t | Connection | ||
) |
The function removes TCP connection from TCP server's connection list.
Server | TCP Server object created by the function oC_Tcp_Server_New |
Connection | TCP Connection object received from the function oC_Tcp_Server_WaitForConnection |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server or Connection is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_ObjectNotFoundOnList | The given Server is not associated with the given Connection |
Definition at line 705 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_Server_Run | ( | oC_Tcp_Server_t | Server | ) |
The function is for running the TCP server. It starts the TCP Server thread.
Server | TCP Server object created by the function oC_Tcp_Server_New |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_AlreadyRunning | The function has been called before and the server is running already |
oC_ErrorCode_CannotRunThread | There was a problem with running the thread |
Definition at line 340 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_Server_SetConnectionConfig | ( | oC_Tcp_Server_t | Server, |
const oC_Tcp_Connection_Config_t * | Config | ||
) |
The function is for changing configuration of the connections related with the server. The change will be applied only to new connections
Server | TCP Server object created by the function oC_Tcp_Server_New |
Config | Pointer to the configuration to copy |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_WrongAddress | Config address is not correct |
oC_ErrorCode_TimeNotCorrect | ConfirmationTimeout field in Config is not correct |
oC_ErrorCode_PortNotCorrect | LocalAddress.Port field in Config is not correct |
oC_ErrorCode_SizeNotCorrect | LocalWindowSize field in Config is not correct |
oC_ErrorCode_PortNotReserved | LocalAddress.Port has to be reserved before |
oC_ErrorCode_PortReservedByDifferentProcess | LocalAddress.Port has been reserved by different process |
Definition at line 300 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_Server_Stop | ( | oC_Tcp_Server_t | Server | ) |
The function is for stopping accepting new connections by the TCP server. After call of the function no new connection will be handled at the server. Connections, that are currently active will work until the server will be deleted by the function oC_Tcp_Server_Delete.
Server | TCP Server object created by the function oC_Tcp_Server_New |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_NotRunning | The server is not running (the function oC_Tcp_Server_Run has not been called) |
oC_ErrorCode_CannotDeleteThread | There was a problem with deleting the thread |
Definition at line 379 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_Server_WaitForConnection | ( | oC_Tcp_Server_t | Server, |
oC_Tcp_Connection_t * | outConnection, | ||
oC_Time_t | Timeout | ||
) |
The function waits for a new TCP connection.
Server | TCP Server object created by the function oC_Tcp_Server_New |
outConnection | Pointer to the variable where new TCP connection should be stored |
Timeout | Maximum time to wait for the connection |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ObjectNotCorrect | Server is not correct (address is not correct or not valid anymore) |
oC_ErrorCode_NotRunning | The server is not running (the function oC_Tcp_Server_Run has not been called) |
oC_ErrorCode_OutputAddressNotInRAM | outConnection is not the correct RAM address |
oC_ErrorCode_TimeNotCorrect | The given Timeout is below zero |
oC_ErrorCode_Timeout | Maximum time to wait has expired |
Definition at line 438 of file oc_tcp_server.c.
oC_ErrorCode_t oC_Tcp_StopListen | ( | oC_Tcp_Server_t * | Server, |
oC_Time_t | Timeout | ||
) |
The function is for stopping listening at the given TCP port. It should be called for servers received from the function oC_Tcp_Listen. The function releases memory allocated for the TCP server and releases port reserved for it.
Server | Pointer to server object received from the function oC_Tcp_Listen, it will be set to NULL on output |
Timeout | Maximum time for server stopping |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - you should enable the module first |
oC_ErrorCode_AddressNotInRam | Server is not correct RAM address |
oC_ErrorCode_ObjectNotCorrect | Server stores incorrect object pointer |
oC_ErrorCode_TimeNotCorrect | The Timeout is below 0 |
oC_ErrorCode_ModuleBusy | Maximum time to wait has expired and the module is still busy |
oC_ErrorCode_ServerNotStarted | Server has not started yet |
oC_ErrorCode_ReleaseError | There was a problem with releasing memory of TCP server |
oC_ErrorCode_CannotRemoveObjectFromList | The given server cannot be removed from servers list |
More error codes can be returned by the functions oC_PortMan_ReleasePort and oC_Tcp_Server_Stop
oC_ErrorCode_t oC_Tcp_TurnOff | ( | oC_Time_t | Timeout | ) |
The function is for turning off the TCP module.
Timeout | Maximum time for the turning off operation |
oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleNotStartedYet | Module is turned off - call of this function is not required. |
oC_ErrorCode_ReleaseError | There was a problem with releasing memory |
oC_ErrorCode_TimeNotCorrect | Timeout is below 0 |
oC_ErrorCode_PermissionDenied | Currently logged user is not root |
oC_ErrorCode_ModuleBusy | Module is busy and maximum time for the operation has expired |
More error codes can be returned by the function oC_PortMan_UnregisterModule
oC_ErrorCode_t oC_Tcp_TurnOn | ( | oC_Time_t | Timeout | ) |
The function is for turning on the TCP module. It has to be called before any other TCP call. The module requires also PortMan
module to work and it should enabled before all of this function.
Timeout | Maximum time for turning on the module |
PortMan
module before!oC_ErrorCode_None
if successList of standard error codes, that can be returned by the function:
Code of error | Description |
---|---|
oC_ErrorCode_ModuleIsTurnedOn | Module is already turned on - please turn it off first if you want to restart it. |
oC_ErrorCode_AllocationError | There is a problem with memory allocation |
oC_ErrorCode_RequiredModuleNotEnabled | PortMan module has not been enabled before |
oC_ErrorCode_PermissionDenied | Only root user can enable the module |
More error codes can be returned by the function oC_PortMan_RegisterModule