Home |
Function send |
Function sendSend data to a connected socket. int send(SOCKET socket, const char * buffer, int buflen, int flags); ParameterssocketSocket returned by socket or accept. bufferBuffer to send. buflenNumber of bytes to send. flagsThe flags parameter provides options for calls to send. The following options are supported:
return valueThe number of bytes queued for sending or SOCKET_ERROR. If an error occurred, call xn_getlasterror and xn_geterror_string to return the error value. Section Error Codes further describes each error. Possible values for this function are:
This routine sends n data bytes from buffer to the connection. The socket must be connected. If the socket is in blocking mode, it returns after all the data has been sent and acknowledged by the remote host. If the socket is in non-blocking mode, as much data as possible is queued in the output window and as much data as possible is sent according to the remote hosts window size and the MSS. The function then returns. If there is no room in the output window, the function returns an error with the errno EWOULDBLOCK. If the socket is in non-blocking mode, select may be called to wait for any room in the output window. The routine ioctlsocket may be called to determine the number of free bytes in the output window. The data is copied directly to output packets of MTU size if SO_TCP_NO_COPY is set (see setsockopt), and the data is copied only once. For TCP, if a timeout occurs (see CFG_MINRTO and CFG_MAXRTO timeout values), the port is set to the closed state and send returns SOCKET_ERROR. The application must call closesocket to free resources. For UDP and RAW, if the data size exceeds the maximum packet size (see xn_pkt_data_max), only one packet is sent and the data is truncated if fragmentation is disabled. If fragmentation is enabled, one fragmented packet will be sent. send will not block if the socket is in non-blocking mode. send will block until the packet is sent if the socket is in blocking mode. send returns SOCKET_ERROR if it fails due to an ARP timeout or device send failure. For both TCP and UDP, successful completion of sendto does not guarantee successful delivery of the data. For TCP non-blocking mode, successful completion of send indicates that all data is queued in the output window. Call select to receive notification when the data was sent and acknowledged. For TCP blocking mode, successful completion of send indicates that all data has been received by the remote host (see CFG_TCP_SEND_WAIT_ACK). In blocking mode, this function blocks infinitely. Use select for a timeout capability. This function does not support sockets in secure mode. For secure sockets, use function net_send instead.
|