Proactive Safety Framework  1.0
posix_socket_comms.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11 */
23 #ifndef POSIX_SOCKET_COMMS_H
24 #define POSIX_SOCKET_COMMS_H
25 
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <unistd.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
38 #define SOCKET_PERMISSIONS 0660
39 
44 #define MAX_PENDING_CONNECTIONS 10
45 
50 #define SOCKET_BUFFER_SIZE 4096
51 
56 typedef enum NvPSFSocketType_t {
57  SOCK_STREAM_TYPE = SOCK_STREAM,
58  SOCK_DGRAM_TYPE = SOCK_DGRAM
60 
65 typedef enum NvPSFSocketEndpointType_t {
70 
75 typedef enum NvPSFSocketBlockingMode_t {
79 
84 typedef enum NvPSFSocketErr_t {
86  NvPSFSOCK_FAIL = 1
88 
93 typedef union NvPSFSocketRetCode_t {
94  int sockfd;
95  int errCode;
96  ssize_t bytesTransferred;
98 
103 typedef struct NvPSFSocketStatus_t {
107 
122 
132 NvPSFSocketStatus NvPSFSocketBind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
133 
142 
154 NvPSFSocketStatus NvPSFSocketAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
155 
165 NvPSFSocketStatus NvPSFSocketConnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
166 
179 NvPSFSocketStatus NvPSFSocketSend(int sockfd, const void *buf, size_t len, int flags);
180 
193 NvPSFSocketStatus NvPSFSocketReceive(int sockfd, void *buf, size_t len, int flags);
194 
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif // POSIX_SOCKET_COMMS_H
NvPSFSocketStatus NvPSFSocketReceive(int sockfd, void *buf, size_t len, int flags)
Receive data from a socket.
NvPSFSocketStatus NvPSFSocketConnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
Connect to a remote socket.
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
NvPSFSocketErr
Definition: posix_socket_comms.h:84
@ NvPSFSOCK_FAIL
Definition: posix_socket_comms.h:86
@ NvPSFSOCK_SUCCESS
Definition: posix_socket_comms.h:85
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
NvPSFSocketStatus NvPSFSocketCreate(int domain, NvPSFSocketType type, NvPSFSocketEndpoint role, NvPSFSocketBlockingMode blocking)
Create a new socket with specified parameters.
NvPSFSocketStatus NvPSFSocketBind(int sockfd, const struct sockaddr *addr, socklen_t addrlen)
Bind a socket to a local address.
NvPSFSocketBlockingMode
Definition: posix_socket_comms.h:75
@ SOCK_BLOCKING
Definition: posix_socket_comms.h:76
@ SOCK_NON_BLOCKING
Definition: posix_socket_comms.h:77
NvPSFSocketStatus NvPSFSocketClose(int sockfd)
Close a socket descriptor.
NvPSFSocketStatus NvPSFSocketAccept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
Accept an incoming connection.
NvPSFSocketStatus NvPSFSocketListen(int sockfd)
Start listening for incoming connections.
NvPSFSocketStatus NvPSFSocketSend(int sockfd, const void *buf, size_t len, int flags)
Send data through a socket.
Status structure returned by socket operations.
Definition: posix_socket_comms.h:103
NvPSFSocketRetCode retCode
Definition: posix_socket_comms.h:105
NvPSFSocketErr err
Definition: posix_socket_comms.h:104
Return code from socket operations.
Definition: posix_socket_comms.h:93
int sockfd
Definition: posix_socket_comms.h:94
ssize_t bytesTransferred
Definition: posix_socket_comms.h:96
int errCode
Definition: posix_socket_comms.h:95