Proactive Safety Framework  1.0
posix_socket_comms.h File Reference
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>

Go to the source code of this file.

Classes

union  NvPSFSocketRetCode
 
struct  NvPSFSocketStatus
 

Macros

#define SOCKET_PERMISSIONS   0660
 Default permissions for socket files (when applicable) More...
 
#define MAX_PENDING_CONNECTIONS   10
 Maximum number of pending connections in listen queue. More...
 
#define SOCKET_BUFFER_SIZE   4096
 Default buffer size for socket operations. More...
 

Enumerations

enum  NvPSFSocketType { SOCK_STREAM_TYPE = SOCK_STREAM , SOCK_DGRAM_TYPE = SOCK_DGRAM }
 
enum  NvPSFSocketEndpoint { SOCKET_SERVER = 0 , SOCKET_CLIENT , SOCKET_BIDIRECTIONAL }
 
enum  NvPSFSocketBlockingMode { SOCK_BLOCKING = 0 , SOCK_NON_BLOCKING }
 
enum  NvPSFSocketErr { NvPSFSOCK_SUCCESS = 0 , NvPSFSOCK_FAIL = 1 }
 

Functions

NvPSFSocketStatus NvPSFSocketCreate (int domain, NvPSFSocketType type, NvPSFSocketEndpoint role, NvPSFSocketBlockingMode blocking)
 Create a new socket with specified parameters. More...
 
NvPSFSocketStatus NvPSFSocketBind (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 Bind a socket to a local address. More...
 
NvPSFSocketStatus NvPSFSocketListen (int sockfd)
 Start listening for incoming connections. More...
 
NvPSFSocketStatus NvPSFSocketAccept (int sockfd, struct sockaddr *addr, socklen_t *addrlen)
 Accept an incoming connection. More...
 
NvPSFSocketStatus NvPSFSocketConnect (int sockfd, const struct sockaddr *addr, socklen_t addrlen)
 Connect to a remote socket. More...
 
NvPSFSocketStatus NvPSFSocketSend (int sockfd, const void *buf, size_t len, int flags)
 Send data through a socket. More...
 
NvPSFSocketStatus NvPSFSocketReceive (int sockfd, void *buf, size_t len, int flags)
 Receive data from a socket. More...
 
NvPSFSocketStatus NvPSFSocketClose (int sockfd)
 Close a socket descriptor. More...
 

Macro Definition Documentation

◆ MAX_PENDING_CONNECTIONS

#define MAX_PENDING_CONNECTIONS   10

Maximum number of pending connections in listen queue.

◆ SOCKET_BUFFER_SIZE

#define SOCKET_BUFFER_SIZE   4096

Default buffer size for socket operations.

◆ SOCKET_PERMISSIONS

#define SOCKET_PERMISSIONS   0660

Default permissions for socket files (when applicable)

Enumeration Type Documentation

◆ NvPSFSocketBlockingMode

Enumerator
SOCK_BLOCKING 

Blocking mode

SOCK_NON_BLOCKING 

Non-blocking mode

75  {
76  SOCK_BLOCKING = 0,
NvPSFSocketBlockingMode
Definition: posix_socket_comms.h:75
@ SOCK_BLOCKING
Definition: posix_socket_comms.h:76
@ SOCK_NON_BLOCKING
Definition: posix_socket_comms.h:77

◆ NvPSFSocketEndpoint

Enumerator
SOCKET_SERVER 

Socket acting as server

SOCKET_CLIENT 

Socket acting as client

SOCKET_BIDIRECTIONAL 

Socket used for bidirectional communication

65  {
66  SOCKET_SERVER = 0,
NvPSFSocketEndpoint
Definition: posix_socket_comms.h:65
@ SOCKET_BIDIRECTIONAL
Definition: posix_socket_comms.h:68
@ SOCKET_SERVER
Definition: posix_socket_comms.h:66
@ SOCKET_CLIENT
Definition: posix_socket_comms.h:67

◆ NvPSFSocketErr

Enumerator
NvPSFSOCK_SUCCESS 

Operation successful

NvPSFSOCK_FAIL 

Operation failed

84  {
85  NvPSFSOCK_SUCCESS = 0,
86  NvPSFSOCK_FAIL = 1
NvPSFSocketErr
Definition: posix_socket_comms.h:84
@ NvPSFSOCK_FAIL
Definition: posix_socket_comms.h:86
@ NvPSFSOCK_SUCCESS
Definition: posix_socket_comms.h:85

◆ NvPSFSocketType

Enumerator
SOCK_STREAM_TYPE 

Stream socket (TCP)

SOCK_DGRAM_TYPE 

Datagram socket (UDP)

56  {
57  SOCK_STREAM_TYPE = SOCK_STREAM,
58  SOCK_DGRAM_TYPE = SOCK_DGRAM
NvPSFSocketType
Definition: posix_socket_comms.h:56
@ SOCK_DGRAM_TYPE
Definition: posix_socket_comms.h:58
@ SOCK_STREAM_TYPE
Definition: posix_socket_comms.h:57

Function Documentation

◆ NvPSFSocketAccept()

NvPSFSocketStatus NvPSFSocketAccept ( int  sockfd,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

Accept an incoming connection.

Parameters
sockfdListening socket descriptor
addrPointer to store client address (optional)
addrlenPointer to store client address length (optional)
Returns
Status structure containing:
  • New socket descriptor in retCode.sockfd on success
  • Error code in retCode.errCode on failure

◆ NvPSFSocketBind()

NvPSFSocketStatus NvPSFSocketBind ( int  sockfd,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Bind a socket to a local address.

Parameters
sockfdSocket descriptor to bind
addrPointer to sockaddr structure containing address information
addrlenLength of the address structure
Returns
Status structure with operation result

◆ NvPSFSocketClose()

NvPSFSocketStatus NvPSFSocketClose ( int  sockfd)

Close a socket descriptor.

Parameters
sockfdSocket descriptor to close
Returns
Status structure with operation result

◆ NvPSFSocketConnect()

NvPSFSocketStatus NvPSFSocketConnect ( int  sockfd,
const struct sockaddr *  addr,
socklen_t  addrlen 
)

Connect to a remote socket.

Parameters
sockfdSocket descriptor to use for connection
addrPointer to sockaddr structure with target address
addrlenLength of the address structure
Returns
Status structure with operation result

◆ NvPSFSocketCreate()

NvPSFSocketStatus NvPSFSocketCreate ( int  domain,
NvPSFSocketType  type,
NvPSFSocketEndpoint  role,
NvPSFSocketBlockingMode  blocking 
)

Create a new socket with specified parameters.

Parameters
domainThe protocol family (e.g., AF_INET, AF_INET6)
typeThe socket type (SOCK_STREAM_TYPE or SOCK_DGRAM_TYPE)
roleThe role determining default configurations (server/client/bidirectional)
blockingWhether the socket should operate in blocking or non-blocking mode
Returns
Status structure containing:
  • Socket descriptor in retCode.sockfd on success
  • Error code in retCode.errCode on failure

◆ NvPSFSocketListen()

NvPSFSocketStatus NvPSFSocketListen ( int  sockfd)

Start listening for incoming connections.

Parameters
sockfdSocket descriptor to listen on
Returns
Status structure with operation result

◆ NvPSFSocketReceive()

NvPSFSocketStatus NvPSFSocketReceive ( int  sockfd,
void *  buf,
size_t  len,
int  flags 
)

Receive data from a socket.

Parameters
sockfdConnected socket descriptor
bufPointer to receive buffer
lenMaximum length to receive
flagsAdditional receive flags
Returns
Status structure containing:
  • Number of bytes received in retCode.bytesTransferred on success
  • Error code in retCode.errCode on failure

◆ NvPSFSocketSend()

NvPSFSocketStatus NvPSFSocketSend ( int  sockfd,
const void *  buf,
size_t  len,
int  flags 
)

Send data through a socket.

Parameters
sockfdConnected socket descriptor
bufPointer to data buffer
lenLength of data to send
flagsAdditional send flags
Returns
Status structure containing:
  • Number of bytes sent in retCode.bytesTransferred on success
  • Error code in retCode.errCode on failure