tcp.c File Reference

TCP (Transmission Control Protocol) More...

#include <string.h>
#include "core/net.h"
#include "core/socket.h"
#include "core/tcp.h"
#include "core/tcp_misc.h"
#include "core/tcp_timer.h"
#include "mibs/mib2_module.h"
#include "mibs/tcp_mib_module.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   TCP_TRACE_LEVEL
 

Functions

error_t tcpInit (void)
 TCP related initialization. More...
 
uint16_t tcpGetDynamicPort (void)
 Get an ephemeral port number. More...
 
error_t tcpConnect (Socket *socket, const IpAddr *remoteIpAddr, uint16_t remotePort)
 Establish a TCP connection. More...
 
error_t tcpListen (Socket *socket, uint_t backlog)
 Place a socket in the listening state. More...
 
SockettcpAccept (Socket *socket, IpAddr *clientIpAddr, uint16_t *clientPort)
 Permit an incoming connection attempt on a TCP socket. More...
 
error_t tcpSend (Socket *socket, const uint8_t *data, size_t length, size_t *written, uint_t flags)
 Send data to a connected socket. More...
 
error_t tcpReceive (Socket *socket, uint8_t *data, size_t size, size_t *received, uint_t flags)
 Receive data from a connected socket. More...
 
error_t tcpShutdown (Socket *socket, uint_t how)
 Shutdown gracefully reception, transmission, or both. More...
 
error_t tcpAbort (Socket *socket)
 Abort an existing TCP connection. More...
 
TcpState tcpGetState (Socket *socket)
 Get the current state of the TCP FSM. More...
 
SockettcpKillOldestConnection (void)
 Kill the oldest socket in the TIME-WAIT state. More...
 

Variables

systime_t tcpTickCounter
 

Detailed Description

TCP (Transmission Control Protocol)

License

Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
1.9.0

Definition in file tcp.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   TCP_TRACE_LEVEL

Definition at line 30 of file tcp.c.

Function Documentation

◆ tcpAbort()

error_t tcpAbort ( Socket socket)

Abort an existing TCP connection.

Parameters
[in]socketHandle identifying the socket to close
Returns
Error code

Definition at line 870 of file tcp.c.

◆ tcpAccept()

Socket* tcpAccept ( Socket socket,
IpAddr clientIpAddr,
uint16_t *  clientPort 
)

Permit an incoming connection attempt on a TCP socket.

Parameters
[in]socketHandle to a socket previously placed in a listening state
[out]clientIpAddrIP address of the client
[out]clientPortPort number used by the client
Returns
Handle to the socket in which the actual connection is made

Definition at line 261 of file tcp.c.

◆ tcpConnect()

error_t tcpConnect ( Socket socket,
const IpAddr remoteIpAddr,
uint16_t  remotePort 
)

Establish a TCP connection.

Parameters
[in]socketHandle to an unconnected socket
[in]remoteIpAddrIP address of the remote host
[in]remotePortRemote port number that will be used to establish the connection
Returns
Error code

Definition at line 113 of file tcp.c.

◆ tcpGetDynamicPort()

uint16_t tcpGetDynamicPort ( void  )

Get an ephemeral port number.

Returns
Ephemeral port

Definition at line 73 of file tcp.c.

◆ tcpGetState()

TcpState tcpGetState ( Socket socket)

Get the current state of the TCP FSM.

Parameters
[in]socketHandle identifying the socket
Returns
TCP FSM state

Definition at line 934 of file tcp.c.

◆ tcpInit()

error_t tcpInit ( void  )

TCP related initialization.

Returns
Error code

Definition at line 58 of file tcp.c.

◆ tcpKillOldestConnection()

Socket* tcpKillOldestConnection ( void  )

Kill the oldest socket in the TIME-WAIT state.

Returns
Handle identifying the oldest TCP connection in the TIME-WAIT state. NULL is returned if no socket is currently in the TIME-WAIT state

Definition at line 958 of file tcp.c.

◆ tcpListen()

error_t tcpListen ( Socket socket,
uint_t  backlog 
)

Place a socket in the listening state.

Place a socket in a state in which it is listening for an incoming connection

Parameters
[in]socketSocket to place in the listening state
[in]backlogbacklog The maximum length of the pending connection queue. If this parameter is zero, then the default backlog value is used instead
Returns
Error code

Definition at line 234 of file tcp.c.

◆ tcpReceive()

error_t tcpReceive ( Socket socket,
uint8_t *  data,
size_t  size,
size_t *  received,
uint_t  flags 
)

Receive data from a connected socket.

Parameters
[in]socketHandle that identifies a connected socket
[out]dataBuffer where to store the incoming data
[in]sizeMaximum number of bytes that can be received
[out]receivedNumber of bytes that have been received
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 571 of file tcp.c.

◆ tcpSend()

error_t tcpSend ( Socket socket,
const uint8_t *  data,
size_t  length,
size_t *  written,
uint_t  flags 
)

Send data to a connected socket.

Parameters
[in]socketHandle that identifies a connected socket
[in]dataPointer to a buffer containing the data to be transmitted
[in]lengthNumber of bytes to be transmitted
[out]writtenActual number of bytes written (optional parameter)
[in]flagsSet of flags that influences the behavior of this function
Returns
Error code

Definition at line 447 of file tcp.c.

◆ tcpShutdown()

error_t tcpShutdown ( Socket socket,
uint_t  how 
)

Shutdown gracefully reception, transmission, or both.

Note that socketShutdown() does not close the socket, and resources attached to the socket will not be freed until socketClose() is invoked

Parameters
[in]socketHandle to a socket
[in]howFlag that describes what types of operation will no longer be allowed
Returns
Error code

Definition at line 719 of file tcp.c.

Variable Documentation

◆ tcpTickCounter

systime_t tcpTickCounter

Definition at line 47 of file tcp.c.