C/C++ Reference
EhConListener Struct Reference

Subclass this class if you want to be notified when a new client connects or a client connection terminates. More...

#include <EvntHndl.h>

List of all members.

Public Member Functions

 EhConListener (EhConListener_New newCon, EhConListener_Terminate termCon)
 Register your callback functions.

Detailed Description

Subclass this class if you want to be notified when a new client connects or a client connection terminates.

You must register an instance of this class with the EventHandler object. See EventHandler::addConListener for more information.

Example:

struct MyListener : public EhConListener
{
      MyListener(EhDir* dir);
private:
      static int newClientCon(EhConListener* l,EventHandler* eh,U32 cid);
      static void clientConTerminated(EhConListener* l,U32 cid);
};

int
MyListener::newClientCon(EhConListener* l, EventHandler* eh, U32 cid)
{
   MyListener* o = (MyListener*)l;
   HttpServer* server = eh->getServer();
   AuthenticatedUser* user = eh->getUser(cid);
   if(user) // If authenticated
      return 0; //Accept connection
   eh->sendErrMsg(cid, "Bugger off");
   return -1; // Connection not accepted
}

void
MyListener::clientConTerminated(EhConListener* l, EventHandler* eh, U32 cid)
{
   MyListener* o = (MyListener*)l;
   .
   .
}

MyListener::MyListener(EhDir* dir) :
   EhConListener(newClientCon, clientConTerminated)
{
   dir->getEventHandler()->addConListener(this);
}