Embedded TCP/IP stack: fnet_socket_sendto

FNET

Embedded TCP/IP stack  4.1.0
fnet_ssize_t fnet_socket_sendto ( fnet_socket_t  s,
const void *  buf,
fnet_size_t  len,
fnet_flag_t  flags,
const struct fnet_sockaddr to,
fnet_size_t  tolen 
)

Sends the data to a specific destination.

Parameters
sDescriptor, identifying a socket.
bufBuffer containing the data to be transmitted.
lenLength of the data in buf.
flagsOptional flag specifying the way, in which the call is made. It can be constructed by using the bitwise OR operator with any of the values defined by the fnet_msg_flags_t.
toPointer to the address of the target socket.
tolenSize of the address in to.
Returns
This function returns:
  • The total number of bytes sent, if no error occurs. It can be lesser than the number indicated by len.
  • FNET_ERR if an error occurs.
    The specific error code can be retrieved using the fnet_error_get().
See also
fnet_socket_connect(), fnet_socket_send()

For nonb-locking stream-oriented sockets (SOCK_STREAM), the number of actually sent bytes can be between 1 and the requested length, depending on buffer availability on both client and server machines.

For message-oriented sockets (SOCK_DGRAM), care must be taken not not exceed the maximum datagram size, which can be obtained by using the fnet_socket_getopt() to retrieve the value of the socket option SO_SNDBUF. If the data is too long to pass atomically through the underlying datagram protocol, the error FNET_ERR_MSGSIZE is returned and no data is transmitted.
Calling fnet_socket_sendto() with a zero len parameter is permissible. In such cases, the fnet_socket_sendto() will return zero as a valid value, and for message-oriented sockets (SOCK_DGRAM), a zero-length transport datagram is sent.

The fnet_socket_sendto() function is normally used on a connectionless socket (SOCK_DGRAM) to send a datagram to a specific peer socket identified by the to parameter. Even if the connectionless socket has been previously connected to a specific address, the to parameter overrides the destination address for that particular datagram only.
On a connection-oriented socket (SOCK_STREAM), the to and tolen parameters are ignored, making the fnet_socket_sendto() equivalent to fnet_socket_send().

The flags parameter can be used to influence the behavior of the function invocation beyond the options specified for the associated socket.


© 2005-2018 by Andrey Butok. http://fnet.sourceforge.net