server 0.0.1
basicserverinfrastructure

src/server.c

Go to the documentation of this file.
00001 #include <poll.h> /* for select system call and related */
00002 #include <string.h>     /* for memset and stuff */
00003 #include <stdlib.h>     /* for getopt */
00004 
00005 #include "class.h"
00006 #include "server.h"
00007 #include "socket.h"
00008 #include "logger.h"
00009 #include "interface/class.h"
00010 
00011 static
00012 void
00013 ctor(void * _this, va_list * params)
00014 {
00015         Server       this = _this;
00016         in_port_t    port;
00017         unsigned int backlog;
00018 
00019         this->logger = va_arg(* params, Logger);
00020         this->reader = va_arg(* params, void*);
00021         port         = va_arg(* params, int);
00022         backlog      = va_arg(* params, unsigned int);
00023 
00024         this->sock = new(Sock, this->logger, port);
00025         socketListen(this->sock, backlog);
00026 
00027         (this->fds)[0].fd     = this->sock->handle;
00028         (this->fds)[0].events = POLLIN;
00029         this->nfds = 1;
00030 }
00031 
00032 static
00033 void
00034 dtor(void * _this)
00035 {
00036         Server this = _this;
00037     int    i;
00038 
00039     for (i=1; i<this->nfds; i++) {
00040                 /*
00041                  * @TODO do some finalization...buffer handling...etc.
00042                  */
00043                 delete(&(this->conns[i]).sock);
00044                 delete(&(this->conns[i]).reader);
00045     }
00046 
00047         delete(&this->sock);
00048 }
00049 
00050 INIT_IFACE(Class, ctor, dtor, NULL);
00051 CREATE_CLASS(Server, NULL, IFACE(Class));
00052 
00053 // vim: set ts=4 sw=4:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines