Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
FreeRTOSTCPSocket Class Reference
Inheritance diagram for FreeRTOSTCPSocket:
Socket Node Device FileIO

Static Public Member Functions

static int socket (int domain, int type, int protocol)
 Create an unbound socket in a communications domain.
 
static int bind (int socket, const struct sockaddr *address, socklen_t address_len)
 Bind a name to a socket.
 
static int listen (int socket, int backlog)
 Mark a connection-mode socket, specified by the socket argument, as accepting connections.
 
static int accept (int socket, struct sockaddr *address, socklen_t *address_len)
 Accept a new connection on a socket.
 
static int connect (int socket, const struct sockaddr *address, socklen_t address_len)
 Connect a socket.
 
static ssize_t recv (int socket, void *buffer, size_t length, int flags)
 Receive a message from a connection-mode or connectionless-mode socket.
 
static ssize_t send (int socket, const void *buffer, size_t length, int flags)
 Initiate transmission of a message from the specified socket.
 
static int setsockopt (int socket, int level, int option_name, const void *option_value, socklen_t option_len)
 Set the socket options.
 
static int getsockopt (int socket, int level, int option_name, void *option_value, socklen_t *option_len)
 Get the socket options.
 
- Static Public Member Functions inherited from Device
static int open (struct _reent *reent, const char *path, int flags, int mode)
 Open a file or device.
 
static int close (struct _reent *reent, int fd)
 Close a file or device.
 
static int stat (struct _reent *reent, const char *path, struct stat *stat)
 Get the status information of a file or device.
 
static int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, long long timeout)
 POSIX select().
 
static void select_clear ()
 Clears the current thread's select bits.
 
- Static Public Member Functions inherited from FileIO
static ssize_t read (struct _reent *reent, int fd, void *buf, size_t count)
 Read from a file or device.
 
static ssize_t write (struct _reent *reent, int fd, const void *buf, size_t count)
 Write to a file or device.
 
static _off_t lseek (struct _reent *reent, int fd, _off_t offset, int whence)
 Change the offset index of a file or device.
 
static int fstat (struct _reent *reent, int fd, struct stat *stat)
 Get the status information of a file or device.
 
static int ioctl (int fd, unsigned long int key, unsigned long data)
 Request and ioctl transaction.
 
static int fcntl (int fd, int cmd, unsigned long data)
 Manipulate a file descriptor.
 
static bool is_device (int fd)
 Test if the file descriptor belongs to a device.
 

Private Member Functions

int close (File *file) override
 Close method.
 
bool select (File *file, int mode) override
 Device select method.
 
int fcntl (File *file, int cmd, unsigned long data) override
 Manipulate a file descriptor.
 
 FreeRTOSTCPSocket ()
 Constructor.
 
 ~FreeRTOSTCPSocket ()
 Destructor.
 
 DISALLOW_COPY_AND_ASSIGN (FreeRTOSTCPSocket)
 

Static Private Member Functions

static FreeRTOSTCPSocketget_sd_by_index (int inx)
 Get the socket descriptor assoicated with socket index.
 
static int alloc_instance (Socket_t sd)
 Allocate a new FreeRTOSTCPSocket and related structures.
 
static FreeRTOSTCPSocketget_instance_from_sd (Socket_t sd)
 Get the FreeRTOSTCP instance given a specific socket descriptor.
 
static void remove_instance_from_sd (Socket_t sd)
 Remove the FreeRTOSTCP instance from the active FreeRTOSTCP list.
 

Private Attributes

Socket_t sd
 FreeRTOS socket descriptor.
 
bool readActive
 indicates our "best guess" at current socket's read active status
 
bool writeActive
 indicates our "best guess" at current socket's write active status
 
bool listenActive
 This is a listen socket.
 

Friends

class FreeRTOSTCP
 allow access to private members from FreeRTOSTCP
 

Additional Inherited Members

- Public Member Functions inherited from Device
 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 
- Protected Member Functions inherited from Socket
 Socket (const char *name)
 Constructor.
 
 ~Socket ()
 Destructor.
 
int ioctl (File *file, unsigned long int key, unsigned long data) override
 Request an ioctl transaction.
 
bool select (File *file, int mode) override
 Device select method.
 
- Protected Member Functions inherited from Node
 Node (const char *name)
 Constructor.
 
virtual ~Node ()
 Destructor.
 
int open (File *, const char *, int, int) OVERRIDE
 Open method.
 
int close (File *) OVERRIDE
 Close method.
 
virtual int fstat (File *file, struct stat *stat) override
 Get the status information of a file or device.
 
- Protected Member Functions inherited from FileIO
 FileIO (const char *name)
 Constructor.
 
virtual ~FileIO ()
 Destructor.
 
- Static Protected Member Functions inherited from Device
static void select_insert (SelectInfo *info)
 Add client to list of clients needing woken.
 
static void select_wakeup (SelectInfo *info)
 Wakeup the list of clients needing woken.
 
static void select_wakeup_from_isr (SelectInfo *info, int *woken)
 Wakeup the list of clients needing woken.
 
- Static Protected Member Functions inherited from FileIO
static int fd_alloc (void)
 Allocate a free file descriptor.
 
static void fd_free (int fd)
 Free up a file descriptor.
 
static Filefile_lookup (int fd)
 Looks up a reference to a File corresponding to a given file descriptor.
 
static int fd_lookup (File *file)
 Looks up a file descriptor corresponding to a given File reference.
 
- Protected Attributes inherited from Socket
SelectInfo selInfoRd
 select wakeup metadata for read active
 
SelectInfo selInfoWr
 select wakeup metadata for write active
 
- Protected Attributes inherited from Node
OSMutex lock_
 protects internal structures.
 
mode_t mode_
 File open mode, such as O_NONBLOCK.
 
unsigned int references_
 number of open references
 
- Protected Attributes inherited from FileIO
const char * name
 device name
 
- Static Protected Attributes inherited from FileIO
static const unsigned int numOpenFiles = 20
 
static File files []
 File descriptor pool.
 
static OSMutex mutex
 mutual exclusion for fileio
 

Detailed Description

Definition at line 47 of file FreeRTOSTCPSocket.hxx.

Constructor & Destructor Documentation

◆ FreeRTOSTCPSocket()

FreeRTOSTCPSocket::FreeRTOSTCPSocket ( )
inlineprivate

Constructor.

Definition at line 198 of file FreeRTOSTCPSocket.hxx.

◆ ~FreeRTOSTCPSocket()

FreeRTOSTCPSocket::~FreeRTOSTCPSocket ( )
inlineprivate

Destructor.

Definition at line 209 of file FreeRTOSTCPSocket.hxx.

Member Function Documentation

◆ accept()

int FreeRTOSTCPSocket::accept ( int  socket,
struct sockaddr address,
socklen_t address_len 
)
static

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 250 of file FreeRTOSTCPSocket.cxx.

◆ alloc_instance()

int FreeRTOSTCPSocket::alloc_instance ( Socket_t  sd)
staticprivate

Allocate a new FreeRTOSTCPSocket and related structures.

Parameters
sdFreeRTOS socket descriptor
Returns
assigned fd

Definition at line 727 of file FreeRTOSTCPSocket.cxx.

◆ bind()

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

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 154 of file FreeRTOSTCPSocket.cxx.

◆ close()

int FreeRTOSTCPSocket::close ( File file)
overrideprivatevirtual

Close method.

Returns negative errno on failure.

Parameters
filereference to close
Returns
0 upon success or negative error number upon error.

Implements FileIO.

Definition at line 642 of file FreeRTOSTCPSocket.cxx.

◆ connect()

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

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 325 of file FreeRTOSTCPSocket.cxx.

◆ fcntl()

int FreeRTOSTCPSocket::fcntl ( File file,
int  cmd,
unsigned long  data 
)
overrideprivatevirtual

Manipulate a file descriptor.

Parameters
filefile reference for this device
cmdoperation to perform
dataparameter to the cmd operation
Returns
dependent on the operation (POSIX compliant where applicable) or negative error number upon error.

Reimplemented from FileIO.

Definition at line 797 of file FreeRTOSTCPSocket.cxx.

◆ get_instance_from_sd()

FreeRTOSTCPSocket * FreeRTOSTCPSocket::get_instance_from_sd ( Socket_t  sd)
staticprivate

Get the FreeRTOSTCP instance given a specific socket descriptor.

Should only be called within a critical section.

Parameters
sdsocket descriptor we are looking for
Returns
fd allocated for sd, otherwise -1 and errno set appropriately

Definition at line 765 of file FreeRTOSTCPSocket.cxx.

◆ get_sd_by_index()

FreeRTOSTCPSocket * FreeRTOSTCPSocket::get_sd_by_index ( int  inx)
staticprivate

Get the socket descriptor assoicated with socket index.

Parameters
inxthe socket index
Returns
pointer to socket associated with the given index

Definition at line 715 of file FreeRTOSTCPSocket.cxx.

◆ getsockopt()

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

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 615 of file FreeRTOSTCPSocket.cxx.

◆ listen()

int FreeRTOSTCPSocket::listen ( int  socket,
int  backlog 
)
static

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 210 of file FreeRTOSTCPSocket.cxx.

◆ recv()

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

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 394 of file FreeRTOSTCPSocket.cxx.

◆ remove_instance_from_sd()

void FreeRTOSTCPSocket::remove_instance_from_sd ( Socket_t  sd)
staticprivate

Remove the FreeRTOSTCP instance from the active FreeRTOSTCP list.

Should only be called within a critical section.

Parameters
sdsocket descriptor we are looking for

Definition at line 781 of file FreeRTOSTCPSocket.cxx.

◆ select()

bool FreeRTOSTCPSocket::select ( File file,
int  mode 
)
overrideprivatevirtual

Device select method.

Default impementation returns true.

Parameters
filereference to the file
modeFREAD for read active, FWRITE for write active, 0 for exceptions
Returns
true if active, false if inactive

Reimplemented from FileIO.

Definition at line 667 of file FreeRTOSTCPSocket.cxx.

◆ send()

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

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 460 of file FreeRTOSTCPSocket.cxx.

◆ setsockopt()

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

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 519 of file FreeRTOSTCPSocket.cxx.

◆ socket()

int FreeRTOSTCPSocket::socket ( int  domain,
int  type,
int  protocol 
)
static

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 58 of file FreeRTOSTCPSocket.cxx.

Friends And Related Symbol Documentation

◆ FreeRTOSTCP

friend class FreeRTOSTCP
friend

allow access to private members from FreeRTOSTCP

Definition at line 247 of file FreeRTOSTCPSocket.hxx.

Member Data Documentation

◆ listenActive

bool FreeRTOSTCPSocket::listenActive
private

This is a listen socket.

Definition at line 244 of file FreeRTOSTCPSocket.hxx.

◆ readActive

bool FreeRTOSTCPSocket::readActive
private

indicates our "best guess" at current socket's read active status

Definition at line 237 of file FreeRTOSTCPSocket.hxx.

◆ sd

Socket_t FreeRTOSTCPSocket::sd
private

FreeRTOS socket descriptor.

Definition at line 233 of file FreeRTOSTCPSocket.hxx.

◆ writeActive

bool FreeRTOSTCPSocket::writeActive
private

indicates our "best guess" at current socket's write active status

Definition at line 241 of file FreeRTOSTCPSocket.hxx.


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