Barracuda Application Server C/C++ Reference
HttpServCon Struct Reference

Detailed Description

Create a server listen object.

The object binds itself to the SoDisp object and makes the web-server listen for new connections on the port specified. The default port is 80. You can create several of these objects and bind to the dispatcher if you want the web-server to listen to more than one port.

#include <HttpServCon.h>

Public Member Functions

 HttpServCon (HttpServer *server, SoDisp *dispatcher, U16 port=80, BaBool setIP6=FALSE, const void *interfaceName=0, HttpServCon_AcceptNewCon userDefinedAccept=0)
 Create a Server Connection. More...
BaBool isValid ()
 Returns true if the constructor successfully opened the listen socket; otherwise, false is returned. More...
int setPort (U16 portNumber, bool setIp6=false, const void *interfaceName=0)
 Change the port number for the "listen" object.

Constructor & Destructor Documentation

◆ HttpServCon()

HttpServCon::HttpServCon ( HttpServer server,
SoDisp dispatcher,
U16  port = 80,
BaBool  setIP6 = FALSE,
const void *  interfaceName = 0,
HttpServCon_AcceptNewCon  userDefinedAccept = 0 

Create a Server Connection.

serveris the web-server object.
dispatcheris SoDisp object.
portthe server port, normally port 80.
setIP6Set protcol version. This parameter is ignored unless the underlying TCP/IP stack is a dual IP V4 and IP V6 stack.
interfaceNamethe name of the interface used for binding the server socket. If this is zero, any available interface will be selected.
userDefinedAcceptThe default (argument is NULL) is to do "accept calls" for the web-server.

A ServerConnection object is normally used for accepting new connections for the web-server. It is possible to redirect new connections to the "userDefinedAccept" callback function. This makes it possible to use the socket dispatcher logic in the web-server for implementing other services such as a telnet server.

The "user defined accept" callback function is called when a new connection is established. The HttpConnection object passed in as the argument to the callback function is a temporary object that will be destroyed as soon as the callback function returns. You must, therefore, copy the data in the connection object.

Example C code:

//Dispatcher calls this function when new data on my connection obj.
static void MyHttpCon_dispatchData(MyHttpCon* o)
char buf[size];
HttpConnection* con = (HttpConnection*)o; // Down cast
int len = HttpConnection_readData(con, buf, size);
if(len < 0)
{ // Socket closed
// handle data
// HttpServCon calls this function for all new connections
static void MyHttpCon_myAccept(HttpConnection* tmpCon)
MyHttpCon* o = // MyHttpCon inherit from HttpConnection
HttpConnection* newCon = (HttpConnection*)o; // Down cast
//Copy connection

Member Function Documentation

◆ isValid()

BaBool HttpServCon::isValid ( )

Returns true if the constructor successfully opened the listen socket; otherwise, false is returned.

Error messages are printed to HttpTrace.

Contains information about the physical socket connection.
Definition: HttpConnection.h:76
void * baMalloc(size_t size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...