Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Asynchronous sending function, used to send data on a TCP/UDP socket.

Called by the application code when there is outgoing data available required to be sent on a specific socket handler. The only difference between this function and the similar sendto function, is the type of socket the data is sent on and the parameters passed in. send function is most commonly called for sockets in a connected state. After the data is sent, the socket callback function registered using registerSocketCallback(), is expected to receive an event of type SOCKET_MSG_SEND holding information containing the number of data bytes sent.

Functions

NMI_API sint16 send (SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags)
 

NMI_API sint16 send ( SOCKET  sock,
void *  pvSendBuffer,
uint16  u16SendLength,
uint16  flags 
)
Asynchronous sending function, used to send data on a TCP/UDP socket.

Called by the application code when there is outgoing data available required to be sent on a specific socket handler.
The only difference between this function and the similar @ref sendto function, is the type of socket the data is sent on and the parameters passed in.
@ref send function is most commonly called for sockets in a connected state.
After the data is sent, the socket callback function registered using registerSocketCallback(), is expected to receive an event of type
@ref SOCKET_MSG_SEND holding information containing the number of data bytes sent.
Parameters
[in]sockSocket ID, must hold a non negative value. A negative value will return a socket error SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in.
[in]pvSendBufferPointer to a buffer holding data to be transmitted.
[in]u16SendLengthThe buffer size in bytes.
[in]u16FlagsNot used in the current implementation.
Precondition
Sockets must be initialized using socketInit.
For TCP Socket:
Must use a successfully connected Socket (so that the intended recipient address is known ahead of sending the data). Hence this function is expected to be called after a successful socket connect operation(in client case or accept in the the server case).
For UDP Socket:
UDP sockets most commonly use sendto function, where the destination address is defined. However, in-order to send outgoing data using the send function, at least one successful call must be made to the sendto function before consecutive calls to the send function, to ensure that the destination address is saved in the firmware.
See Also
socketInit recv sendto socket connect accept sendto
Warning
u16SendLength must not exceed SOCKET_BUFFER_MAX_LENGTH.
Use a valid socket identifier through the prior call to the socket function. Must use a valid buffer pointer. Successful completion of a call to send() does not guarantee delivery of the message, A negative return value indicates only locally-detected errors
Returns
The function shall return SOCK_ERR_NO_ERROR for successful operation and a negative value otherwise.
Parameters
[in]sockSocket ID, must hold a non negative value. A negative value will return a socket error SOCK_ERR_INVALID_ARG. Indicating that an invalid argument is passed in.
[in]pvSendBufferPointer to a buffer holding data to be transmitted.
[in]u16SendLengthThe buffer size in bytes.
[in]u16FlagsNot used in the current implementation.
Precondition
Sockets must be initialized using socketInit.

For TCP Socket:
Must use a successfully connected Socket (so that the intended recipient address is known ahead of sending the data). Hence this function is expected to be called after a successful socket connect operation(in client case or accept in the the server case).
For UDP Socket:
UDP sockets most commonly use sendto function, where the destination address is defined. However, in-order to send outgoing data using the send function, at least one successful call must be made to the sendto function a priori the consecutive calls to the send function, to ensure that the destination address is saved in the firmware.

Warning
u16SendLength must not exceed SOCKET_BUFFER_MAX_LENGTH.
Use a valid socket identifier through the a prior call to the socket function. Must use a valid buffer pointer. Successful completion of a call to send() does not guarantee delivery of the message, A negative return value indicates only locally-detected errors
See Also
socketInit recv sendto socket connect accept sendto
Returns
The function shall return SOCK_ERR_NO_ERROR for successful operation and a negative value (indicating the error) otherwise.

References M2M_REQ_DATA_PKT, MAX_SOCKET, NM_BSP_B_L_16, NULL, tstrSendCmd::sock, SOCK_ERR_BUFFER_FULL, SOCK_ERR_INVALID_ARG, SOCK_ERR_NO_ERROR, SOCKET_BUFFER_MAX_LENGTH, SOCKET_CMD_SEND, SOCKET_CMD_SSL_SEND, SOCKET_REQUEST, SSL_FLAGS_ACTIVE, SSL_FLAGS_DELAY, TCP_SOCK_MAX, TCP_TX_PACKET_OFFSET, tstrSocket::u16DataOffset, tstrSendCmd::u16DataSize, tstrSocket::u16SessionID, tstrSendCmd::u16SessionID, and UDP_TX_PACKET_OFFSET.

Referenced by _http_client_request(), _http_client_send_wait(), execute_state_machine(), GROWL_APPSocketEventHandler(), handle_input_message(), handle_transaction(), html_handler(), iot_tls_write(), IperfTCP_SendTestPacket(), IperfUDP_SendTestPacket(), IperfUDP_WriteFIN(), run_sample_test_app(), smtpSendRecv(), smtpStateHandler(), socket_cb(), uip_process(), wifi_cb(), and WINC1500_write().