tfHttpcUserSendRequestBody

Jump to: navigation, search

Table of Contents >> Application Reference >> Web Client


#include <trsocket.h>


int tfHttpcUserSendRequestBody (
ttHttpcUserConHandle conHandle,
int contentLength,
const char * bufferPtr,
int * bufferLenPtr,
int flags
);




Function Description

Send a buffer of HTTP body to the HTTP server. This API returns the number of bytes sent in *bufferLenPtr.

In blocking mode, this API blocks until the entire buffer has been sent.

In non-blocking mode, this API only sends what the socket send queue allows and returns immediately. The user needs to check the return code for the sending status. If TM_ENOERROR is returned, the requested buffer has been sent out. If TM_EWOULDBLOCK is returned, the requested buffer has been partially sent out.

When TM_EWOULDBLOCK is returned, the user has two choices:

  1. Call this API again and again with the rest of the body to be sent until it returns TM_ENOERROR indicating body buffer has been sent out, or until an error occurs.
  2. Call tfHttpcUserExecute() periodically and wait for the event handler to be notified. This requires a non-NULL event handler to be passed to tfHttpcUserOpen. When TM_HTTPC_EVENT_SEND_READY is notified, user may call this API again to send the rest of the request.

A special note about contentLength: If the user knows the length of the entire body, then it should be passed in the contentLength parameter. If the user doesn’t know the length of the entire body, contentLength should be specified as –1. The request body will then be chunk encoded. Note that chunked encoding can only be used when HTTP version is 1.1. The user is responsible to build the content-length header or the chunked encoding header to pass to a previous call to tfHttpcUserSendRequestHeaders().




Parameters

  • conHandle
    User connection handle
  • contentLength
    Length of the entire body. Specify –1 if unknown.
  • bufferPtr
    Pointer to the buffer to be sent as part of the body.
  • bufferLenPtr
    Points to buffer length. The input value indicates the length of data to be sent, when this API returns, the output value is updated to be the actual data length sent out.
  • flags
    ORable flags:
TM_BLOCKING_ON, blocking mode.
TM_BLOCKING_OFF, non-blocking mode
TM_HTTPC_FLAG_END, set to indicate the end of the request



Returns

  • TM_ENOERROR
    Successful
  • TM_EWOULDBLOCK
    The socket is marked as non-blocking, only some of the headers have been sent out
  • TM_EINVAL
    One of the parameters is invalid.
  • TM_ENOTCONN
    Not connected
  • TM_ESHUTDOWN
    The connection is being closed
  • TM_EPERM
    The operation is not permitted
  • TM_EBADF
    The socket descriptor is invalid
  • TM_ENOBUFS
    There was insufficient user memory available to complete the operation.



Table of Contents >> Application Reference >> Web Client