tfHttpdUserSendBuffer

Jump to: navigation, search

Table of Contents >> Application Reference >> Web Server


#include <trsocket.h>


int tfHttpdUserSendBuffer (
ttHttpdUserConHandle conHandle,
const char * bufferPtr,
int bufferLen,
int flag,
int * errorCodePtr
);


Function Description

Transmit a user buffer to the HTTPD client through the HTTPD connection. Note that in non-blocking mode, the whole buffer might not be sent out. The user needs to check the return value and call this function again to send the rest, if necessary.

Blocking Mode

In blocking mode, the user should call tfHttpdUserSendBuffer() from a thread other than the web server thread, otherwise other HTTPD connections won't be processed during the duration of the call.

Non-blocking Mode

In non-blocking mode, if the user calls tfHttpdUserSendBuffer() and TM_SOCKET_ERROR is returned with the error code set to TM_EWOULDBLOCK, the web server will call the event handler again with the TM_HTTPD_EVENT_SEND_READY event when there is more room to send data.


Note Note: The user can send the data either in blocking mode or in non-blocking mode, regardless of the HTTP server blocking mode.


Parameters

  • conHandle
    HTTP connection handle.
  • bufferPtr
    Pointer to the buffer to be sent.
  • bufferLen
    Length of the buffer, user can specify –1 to indicate the bufferPtr is a null terminated string.
  • flag
    OR'able flags:
    TM_BLOCKING_ON
    TM_HTTPD_END
    TM_HTTPD_FLUSH
  • errorCodePtr
    Pointer to the error code, output parameter *errorCodePtr.


Returns

  • >0
    The number of bytes sent.
  • TM_SOCKET_ERROR
    Failure. See *errorCodePtr for a more specific error code. This could also indicate that errorCodePtr was NULL.


Possible values for *errorCodePtr

  • TM_ENOERROR
    Success
  • TM_EWOULDBLOCK
    Data is being sent in non-blocking mode, and there is no more room to send it. User needs to wait for a TM_HTTPD_EVENT_SEND_READY event before resending the data.
  • TM_SOCKET_ERROR
    errorCodePtr is NULL.
  • TM_EINVAL
    One of the following:
  • bufferPtr is NULL.
  • One of TM_HTTPD_END or TM_HTTPD_FLUSH is not set in flag.
  • userConHandle is invalid.


Table of Contents >> Application Reference >> Web Server