Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
CC32xxSocket Class Reference

Socket implementation for the CC32xx class WiFi devices. More...

#include <CC32xxSocket.hxx>

Inheritance diagram for CC32xxSocket:
Socket Socket Node Node Device Device FileIO FileIO

Public Member Functions

 ~CC32xxSocket ()
 Destructor.
 
 ~CC32xxSocket ()
 Destructor.
 
- Public Member Functions inherited from Device
 Device (const char *name)
 Constructor.
 
virtual ~Device ()
 Destructor.
 

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 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.
 
 CC32xxSocket ()
 Constructor.
 
 DISALLOW_COPY_AND_ASSIGN (CC32xxSocket)
 
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.
 
 CC32xxSocket ()
 Constructor.
 
 DISALLOW_COPY_AND_ASSIGN (CC32xxSocket)
 

Static Private Member Functions

static CC32xxSocketget_instance_from_sd (int sd)
 Get the CC32xxSocket instance given a specific CC32xx socket descriptor.
 
static CC32xxSocketget_instance_from_fd (int fd)
 Get the CC32xxSocket instance given a file descriptor.
 
static void remove_instance_from_sd (int sd)
 Remove the CC32xxSocket instance from the active CC32xxSocket list.
 
static int reserve_socket ()
 Reserve a location in the cc32xxSockets pool.
 
static CC32xxSocketget_instance_from_sd (int sd)
 Get the CC32xxSocket instance given a specific CC32xx socket descriptor.
 
static CC32xxSocketget_instance_from_fd (int fd)
 Get the CC32xxSocket instance given a file descriptor.
 
static void remove_instance_from_sd (int sd)
 Remove the CC32xxSocket instance from the active CC32xxSocket list.
 
static int reserve_socket ()
 Reserve a location in the cc32xxSockets pool.
 

Private Attributes

int16_t sd
 CC32xx socket descriptor.
 
uint8_t readActive: 1
 indicates our "best guess" at current socket's read active status
 
uint8_t writeActive: 1
 indicates our "best guess" at current socket's write active status
 
uint8_t listenActive: 1
 This is a listen socket.
 

Friends

class CC32xxWiFi
 allow access to private members from CC32xxWiFi
 

Additional Inherited Members

- 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

Socket implementation for the CC32xx class WiFi devices.

Definition at line 44 of file net_cc3220/CC32xxSocket.hxx.

Constructor & Destructor Documentation

◆ ~CC32xxSocket() [1/2]

CC32xxSocket::~CC32xxSocket ( )
inline

Destructor.

This is public only so that smart pointers can be used without having to supply a custom destructor.

Definition at line 165 of file net_cc3220/CC32xxSocket.hxx.

◆ CC32xxSocket() [1/2]

CC32xxSocket::CC32xxSocket ( )
inlineprivate

Constructor.

Definition at line 195 of file net_cc3220/CC32xxSocket.hxx.

◆ ~CC32xxSocket() [2/2]

CC32xxSocket::~CC32xxSocket ( )
inline

Destructor.

This is public only so that smart pointers can be used without having to supply a custom destructor.

Definition at line 165 of file net_cc32xx/CC32xxSocket.hxx.

◆ CC32xxSocket() [2/2]

CC32xxSocket::CC32xxSocket ( )
inlineprivate

Constructor.

Definition at line 195 of file net_cc32xx/CC32xxSocket.hxx.

Member Function Documentation

◆ accept() [1/2]

int CC32xxSocket::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 282 of file net_cc3220/CC32xxSocket.cxx.

◆ accept() [2/2]

static int CC32xxSocket::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

◆ bind() [1/2]

int CC32xxSocket::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 220 of file net_cc3220/CC32xxSocket.cxx.

◆ bind() [2/2]

static int CC32xxSocket::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

◆ close() [1/2]

int CC32xxSocket::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 744 of file net_cc3220/CC32xxSocket.cxx.

◆ close() [2/2]

int CC32xxSocket::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.

◆ connect() [1/2]

int CC32xxSocket::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
Todo:
the return value for a non-blocking connect is supposed to be EINPROGRESS, but the CC32xx returns EALREADY instead.

Definition at line 378 of file net_cc3220/CC32xxSocket.cxx.

◆ connect() [2/2]

static int CC32xxSocket::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

◆ fcntl() [1/2]

int CC32xxSocket::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 911 of file net_cc3220/CC32xxSocket.cxx.

◆ fcntl() [2/2]

int CC32xxSocket::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.

◆ get_instance_from_fd() [1/2]

CC32xxSocket * CC32xxSocket::get_instance_from_fd ( int  fd)
staticprivate

Get the CC32xxSocket instance given a file descriptor.

Parameters
fdfile descriptor we are looking for
Returns
instance pointer to CC32xxSocket belonging to fd, else nullptr with errno set appropriately

Definition at line 841 of file net_cc3220/CC32xxSocket.cxx.

◆ get_instance_from_fd() [2/2]

static CC32xxSocket * CC32xxSocket::get_instance_from_fd ( int  fd)
staticprivate

Get the CC32xxSocket instance given a file descriptor.

Parameters
fdfile descriptor we are looking for
Returns
instance pointer to CC32xxSocket belonging to fd, else nullptr with errno set appropriately

◆ get_instance_from_sd() [1/2]

CC32xxSocket * CC32xxSocket::get_instance_from_sd ( int  sd)
staticprivate

Get the CC32xxSocket instance given a specific CC32xx socket descriptor.

Should only be called within a critical section.

Parameters
sdsocket descriptor we are looking for
Returns
instance pointer to CC32xxSocket belonging to sd, else nullptr

Definition at line 822 of file net_cc3220/CC32xxSocket.cxx.

◆ get_instance_from_sd() [2/2]

static CC32xxSocket * CC32xxSocket::get_instance_from_sd ( int  sd)
staticprivate

Get the CC32xxSocket instance given a specific CC32xx socket descriptor.

Should only be called within a critical section.

Parameters
sdsocket descriptor we are looking for
Returns
instance pointer to CC32xxSocket belonging to sd, else nullptr

◆ getsockopt() [1/2]

int CC32xxSocket::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 624 of file net_cc3220/CC32xxSocket.cxx.

◆ getsockopt() [2/2]

static int CC32xxSocket::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

◆ listen() [1/2]

int CC32xxSocket::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 252 of file net_cc3220/CC32xxSocket.cxx.

◆ listen() [2/2]

static int CC32xxSocket::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

◆ recv() [1/2]

ssize_t CC32xxSocket::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 435 of file net_cc3220/CC32xxSocket.cxx.

◆ recv() [2/2]

static ssize_t CC32xxSocket::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

◆ remove_instance_from_sd() [1/2]

void CC32xxSocket::remove_instance_from_sd ( int  sd)
staticprivate

Remove the CC32xxSocket instance from the active CC32xxSocket list.

Should only be called within a critical section.

Parameters
sdsocket descriptor we are looking for

Definition at line 865 of file net_cc3220/CC32xxSocket.cxx.

◆ remove_instance_from_sd() [2/2]

static void CC32xxSocket::remove_instance_from_sd ( int  sd)
staticprivate

Remove the CC32xxSocket instance from the active CC32xxSocket list.

Should only be called within a critical section.

Parameters
sdsocket descriptor we are looking for

◆ reserve_socket() [1/2]

int CC32xxSocket::reserve_socket ( )
staticprivate

Reserve a location in the cc32xxSockets pool.

Returns
handle to the reserved location in the pool, -1 on error with errno set appropriately

Definition at line 884 of file net_cc3220/CC32xxSocket.cxx.

◆ reserve_socket() [2/2]

static int CC32xxSocket::reserve_socket ( )
staticprivate

Reserve a location in the cc32xxSockets pool.

Returns
handle to the reserved location in the pool, -1 on error with errno set appropriately

◆ select() [1/2]

bool CC32xxSocket::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 775 of file net_cc3220/CC32xxSocket.cxx.

◆ select() [2/2]

bool CC32xxSocket::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.

◆ send() [1/2]

ssize_t CC32xxSocket::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
Todo:
(stbaker): handle errors via the callback.
Todo:
(stbaker): handle errors via the callback.

Definition at line 482 of file net_cc3220/CC32xxSocket.cxx.

◆ send() [2/2]

static ssize_t CC32xxSocket::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

◆ setsockopt() [1/2]

int CC32xxSocket::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 535 of file net_cc3220/CC32xxSocket.cxx.

◆ setsockopt() [2/2]

static int CC32xxSocket::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

◆ socket() [1/2]

int CC32xxSocket::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 76 of file net_cc3220/CC32xxSocket.cxx.

◆ socket() [2/2]

static int CC32xxSocket::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

Friends And Related Symbol Documentation

◆ CC32xxWiFi

CC32xxWiFi
friend

allow access to private members from CC32xxWiFi

Definition at line 245 of file net_cc3220/CC32xxSocket.hxx.

Member Data Documentation

◆ listenActive

uint8_t CC32xxSocket::listenActive
private

This is a listen socket.

Definition at line 242 of file net_cc3220/CC32xxSocket.hxx.

◆ readActive

uint8_t CC32xxSocket::readActive
private

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

Definition at line 235 of file net_cc3220/CC32xxSocket.hxx.

◆ sd

int16_t CC32xxSocket::sd
private

CC32xx socket descriptor.

Definition at line 231 of file net_cc3220/CC32xxSocket.hxx.

◆ writeActive

uint8_t CC32xxSocket::writeActive
private

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

Definition at line 239 of file net_cc3220/CC32xxSocket.hxx.


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