Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
FreeRTOSTCPSocket.cxx File Reference
#include <fcntl.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdio.h>
#include "FreeRTOS.h"
#include "task.h"
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOSTCPSocket.hxx"
#include "FreeRTOSTCP.hxx"

Go to the source code of this file.

Functions

int socket (int domain, int type, int protocol)
 Create an unbound socket in a communications domain.
 
int bind (int socket, const struct sockaddr *address, socklen_t address_len)
 Bind a name to a socket.
 
int listen (int socket, int backlog)
 Mark a connection-mode socket, specified by the socket argument, as accepting connections.
 
int accept (int socket, struct sockaddr *address, socklen_t *address_len)
 Accept a new connection on a socket.
 
int connect (int socket, const struct sockaddr *address, socklen_t address_len)
 Connect a socket.
 
ssize_t recv (int socket, void *buffer, size_t length, int flags)
 Receive a message from a connection-mode or connectionless-mode socket.
 
ssize_t send (int socket, const void *buffer, size_t length, int flags)
 Initiate transmission of a message from the specified socket.
 
int setsockopt (int socket, int level, int option_name, const void *option_value, socklen_t option_len)
 Set the socket options.
 
int getsockopt (int socket, int level, int option_name, void *option_value, socklen_t *option_len)
 Get the socket options.
 
int getsockname (int socket, struct sockaddr &addr, socklen_t &namelen)
 Get the socket name.
 
const char * inet_ntoa (struct in_addr addr)
 Converts internet address into a dotted decimal string.
 
uint32_t inet_addr (const char *name)
 Converts the dotted decmail internet address string into a binary representation.
 

Variables

static FreeRTOSTCPSocketFreeRTOSTCPSockets [MAX_SOCKETS]
 
static char str [32]
 

Detailed Description

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This file provides the sockets interface to the FreeRTOSPlus TCP stack. Based on work by Stuart W. Baker

Author
Sidney McHarg
Date
21 March 2016

Definition in file FreeRTOSTCPSocket.cxx.

Function Documentation

◆ accept()

int accept ( int  socket,
struct sockaddr address,
socklen_t address_len 
)

Accept a new connection on a socket.

Parameters
socketthe socket file descriptor
addresseither a null pointer, or a pointer to a sockaddr structure where the address of the connecting socket shall be returned
address_leneither a null pointer, if address is a null pointer, or a pointer to a socklen_t object which on input specifies the length of the supplied sockaddr structure, and on output specifies the length of the stored address
Returns
shall return the non-negative file descriptor of the accepted socket upon success, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 888 of file FreeRTOSTCPSocket.cxx.

◆ bind()

int bind ( int  socket,
const struct sockaddr address,
socklen_t  address_len 
)

Bind a name to a socket.

Parameters
socketfile descriptor of the socket to be bound
addresspoints to a sockaddr structure containing the address to be bound to the socket
address_lenspecifies the length of the sockaddr structure pointed to by the address argument
Returns
shall return on success, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 855 of file FreeRTOSTCPSocket.cxx.

◆ connect()

int connect ( int  socket,
const struct sockaddr address,
socklen_t  address_len 
)

Connect a socket.

Parameters
socketthe socket file descriptor
addresspoints to a sockaddr structure containing the peer address
address_lenspecifies the length of the sockaddr structure pointed to by the address argument
Returns
shall return 0 upon success, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 901 of file FreeRTOSTCPSocket.cxx.

◆ getsockname()

int getsockname ( int  socket,
struct sockaddr addr,
socklen_t namelen 
)

Get the socket name.

Parameters
socketthe socket file descriptor
addrpoints to a sockaddr structure to receive ane name
namelenpoints to a socklen_t to receive the lenght of the name
Returns
shall return 0 upon success, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 976 of file FreeRTOSTCPSocket.cxx.

◆ getsockopt()

int getsockopt ( int  socket,
int  level,
int  option_name,
void *  option_value,
socklen_t option_len 
)

Get the socket options.

Parameters
socketthe socket file descriptor
levelspecifies the protocol level at which the option resides
option_namespecifies a single option to get
option_valuethe metadata that belongs to the option_name
option_lenthe length of the metadata that belongs to the option_name
Returns
shall return 0 upon success, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 962 of file FreeRTOSTCPSocket.cxx.

◆ inet_addr()

uint32_t inet_addr ( const char *  name)

Converts the dotted decmail internet address string into a binary representation.

Converts a number-and-dot notation internet address to network byte order form.

Parameters
namestring containing dotted decimal representation
Returns
binary address representation

Definition at line 999 of file FreeRTOSTCPSocket.cxx.

◆ inet_ntoa()

const char * inet_ntoa ( struct in_addr  addr)

Converts internet address into a dotted decimal string.

Converts an address to textual representation.

Parameters
addran in_addr structure containing the IP address
Returns
returns a string in dotted decimal representation

Definition at line 987 of file FreeRTOSTCPSocket.cxx.

◆ listen()

int listen ( int  socket,
int  backlog 
)

Mark a connection-mode socket, specified by the socket argument, as accepting connections.

Parameters
socketthe socket file descriptor
backlogprovides a hint to the implementation which the implementation shall use to limit the number of outstanding connections in the socket's listen queue
Returns
shall return 0 upon success, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 869 of file FreeRTOSTCPSocket.cxx.

◆ recv()

ssize_t recv ( int  socket,
void *  buffer,
size_t  length,
int  flags 
)

Receive a message from a connection-mode or connectionless-mode socket.

Parameters
socketthe socket file descriptor
bufferbuffer where the message should be stored
lengthlength in bytes of the buffer pointed to by the buffer argument
flagsSpecifies the type of message reception
Returns
the length of the message in bytes, if no messages are available to be received and the peer has performed an orderly shutdown, recv() shall return 0. Otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 917 of file FreeRTOSTCPSocket.cxx.

◆ send()

ssize_t send ( int  socket,
const void *  buffer,
size_t  length,
int  flags 
)

Initiate transmission of a message from the specified socket.

Parameters
socketthe socket file descriptor
bufferbuffer containing the message to send
lengthlength of the message in bytes
flagsthe type of message transmission
Returns
the number of bytes sent, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 930 of file FreeRTOSTCPSocket.cxx.

◆ setsockopt()

int setsockopt ( int  socket,
int  level,
int  option_name,
const void *  option_value,
socklen_t  option_len 
)

Set the socket options.

Parameters
socketthe socket file descriptor
levelspecifies the protocol level at which the option resides
option_namespecifies a single option to set
option_valuethe metadata that belongs to the option_name
option_lenthe length of the metadata that belongs to the option_name
Returns
shall return 0 upon success, otherwise, -1 shall be returned and errno set to indicate the error

Definition at line 945 of file FreeRTOSTCPSocket.cxx.

◆ socket()

int socket ( int  domain,
int  type,
int  protocol 
)

Create an unbound socket in a communications domain.

Parameters
domainspecifies the communications domain in which a socket is to be created
typespecifies the type of socket to be created
protocolspecifies a particular protocol to be used with the socket, specifying a protocol of 0 causes socket() to use an unspecified default protocol appropriate for the requested socket type
Returns
a non-negative integer on success, the socket file descriptor, otherwise, a value of -1 shall be returned and errno set to indicate the error

Definition at line 841 of file FreeRTOSTCPSocket.cxx.

Variable Documentation

◆ FreeRTOSTCPSockets

FreeRTOSTCPSocket* FreeRTOSTCPSockets[MAX_SOCKETS]
static

Definition at line 53 of file FreeRTOSTCPSocket.cxx.

◆ str

char str[32]
static

Definition at line 981 of file FreeRTOSTCPSocket.cxx.