NetApp_SockOpen TCP-UDP
Open an application socket, with error handling. See section NetSock_Open() for more information.
Files
net_app.h/net_app.c
Prototype
NET_SOCK_ID NetApp_SockOpen (NET_SOCK_PROTOCOL_FAMILY protocol_family, NET_SOCK_TYPE sock_type, NET_SOCK_PROTOCOL protocol, CPU_INT16U retry_max, CPU_INT32U time_dly_ms, NET_ERR *p_err);
Arguments
protocol_family
This field establishes the socket protocol family domain. Always use NET_SOCK_FAMILY_IP_V4/PF_INET or NET_SOCK_FAMILY_IP_V6/PF_INET6
for TCP/IP sockets.
sock_type
Socket type:
NET_SOCK_TYPE_DATAGRAM/PF_DGRAM
for datagram sockets (i.e., UDP)
NET_SOCK_TYPE_STREAM/PF_STREAM
for stream sockets (i.e., TCP)
NET_SOCK_TYPE_DATAGRAM
sockets preserve message boundaries. Applications that exchange single request and response messages are examples of datagram communication.
NET_SOCK_TYPE_STREAM
sockets provides a reliable byte-stream connection, where bytes are received from the remote application in the same order as they were sent. File transfer and terminal emulation are examples of applications that require this type of protocol.
protocol
Socket protocol:NET_SOCK_PROTOCOL_UDP/IPPROTO_UDP
for UDPNET_SOCK_PROTOCOL_TCP/IPPROTO_TCP
for TCP
0
for default-protocol:
UDP for NET_SOCK_TYPE_DATAGRAM/PF_DGRAM
TCP for NET_SOCK_TYPE_STREAM/PF_STREAM
retry_max
Maximum number of consecutive socket open retries.
time_dly_ms
Socket open delay value, in milliseconds.
p_err
Pointer to variable that will receive the error code from this function:
NET_APP_ERR_NONE
NET_APP_ERR_NONE_AVAIL
NET_APP_ERR_INVALID_ARG
NET_APP_ERR_FAULT
Returned Value
Socket descriptor/handle identifier of new socket, if no errors.
NET_SOCK_BSD_ERR_OPEN
, otherwise.
Required Configuration
None.
Notes / Warnings
Some socket arguments and/or operations are validated only if validation code is enabled (see section Argument Check Configuration).
If a non-zero number of retries is requested (retry_max
) then a non-zero time delay (time_dly_ms
) should also be requested. Otherwise, all retries will likely fail immediately since no time will elapse to wait for and allow socket operations to successfully complete.