server 0.0.1
basicserverinfrastructure

src/socket.c

Go to the documentation of this file.
00001 #include <errno.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 
00005 #include "socket.h"
00006 #include "logger.h"
00007 #include "interface/class.h"
00008 #include "interface/logger.h"
00009 
00010 static
00011 void
00012 ctor(void * _this, va_list * params)
00013 {
00014         Sock this = _this;
00015         int reUse   = 1;     /* TODO: make this configurable */
00016 
00017         this->log  = va_arg(* params, Logger);
00018         this->port = va_arg(* params, int);
00019 
00020         /* Create socket for incoming connections */
00021         if (-1 == (this->handle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))) {
00022                 loggerLog(this->log, LOGGER_CRIT,
00023                                 "error opening socket: %s - service terminated",
00024                                 strerror(errno));
00025                 //exit(EXIT_FAILURE);
00032                 return;
00033         }
00034 
00035         /* Make the socket REUSE a TIME_WAIT socket */
00036         setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof (reUse));
00037 }
00038 
00039 static
00040 void
00041 dtor(void * _this)
00042 {
00043         Sock this = _this;
00044 
00045         if (0 != this->handle) {
00046                 shutdown(this->handle, SHUT_RDWR);
00047                 close(this->handle);
00048         }
00049 }
00050 
00051 INIT_IFACE(Class, ctor, dtor, NULL);
00052 CREATE_CLASS(Sock, NULL, IFACE(Class));
00053 
00054 // vim: set ts=4 sw=4:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines