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