tfHttpdUserStart

Jump to: navigation, search

Table of Contents >> Application Reference >> Web Server


#include <trsocket.h>


ttHttpdUserSrvHandle tfHttpdUserStart (
int maxConnections,
int maxConnectionsPerIp,
int idleTimeOut,
int flags,
const char * rootNamePtr,
const char * defaultPagePtr,
const char * cgiDirPtr,
struct sockaddr_storage * sockAddrPtr,
int * errorCodePtr
);


Function Description

This function opens an HTTP Server socket, allocates a server structure, copies the information passed in by the user, and then binds to the socket address and port number specified in the sockAddrPtr parameter. Either blocking or non-blocking mode is specified by the flags parameter. The return value is a server handle, and is used in other web server APIs.


Parameters

  • maxConnections
    Maximum total connections allowed.
  • maxConnectionsPerIp
    Maximum connections allowed from the same IP address
  • idleTimeOut
    Timeout value of idle timer
  • flags
    Configuration parameters. See the Flags table below. Values may be OR'd together.
  • rootNamePtr
    Root directory name
  • defaultPagePtr
    Default HTML page, if this parameter is NULL, "index.htm" will be used, must be an absolute path started with '/'
  • cgiDirPtr
    CGI directory, if this parameter is NULL, "cgi-bin" will be used. This must be an absolute path started with '/'
  • sockAddrPtr
    Pointer to a socket address to listen on. Include the address family (AF_INET or AF_INET6), IP address, and port number. If this pointer is NULL, the web server will bind to port 80 and be able to receive on any local IP address.
  • errorCodePtr
    Pointer to the error code


Flags

  • TM_BLOCKING_ON
    Run in blocking mode.
  • TM_BLOCKING_OFF
    Run in non-blocking mode
  • TM_HTTPD_USER_CGI_AUTH
    This will cause the server to ignore the default authentication method (see tfHttpdUserAuthConfig()) for CGI pages. The user credentials will be decoded and saved in the pointer to the ttHttpdUserConEntry returned by tfHttpdUserGetConInfo().
  • TM_HTTPD_FULL_HEADERS
    Return full header strings (e.g. "Host: 192.168.0.1") in the ttHttpdUserConEntry structure.


Returns

  • TM_HTTPD_INVALID_SERVER_HANDLE
    Failed to start an HTTP server, refer to *errorCodePtr for the error code.
  • Other
    Handle to the newly opened web server.


Error Codes

  • TM_ENOERROR
    Successful
  • TM_EMFILE
    Too many web servers started.
  • TM_EINVAL
    Invalid input parameter.
  • TM_ENOBUFS
    Not enough memory.