|
Server 0.0.1
HTTP/REST server implementation
|
00001 00023 #include <errno.h> 00024 #include <stdlib.h> 00025 #include <unistd.h> 00026 00027 #include "socket.h" 00028 #include "logger.h" 00029 #include "class.h" 00030 00031 static 00032 int 00033 socketCtor(void * _this, va_list * params) 00034 { 00035 Sock this = _this; 00036 int reUse = 1; 00037 int port; 00038 00039 this->log = va_arg(* params, Logger); 00040 port = va_arg(* params, int); 00041 00043 if (-1 == port) { 00044 return 0; 00045 } else { 00046 this->port = port; 00047 } 00048 00050 if (-1 == (this->handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))) { 00051 loggerLog(this->log, LOGGER_CRIT, 00052 "error opening socket: %s - service terminated", 00053 strerror(errno)); 00054 return -1; 00055 } 00056 00058 setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof(reUse)); 00059 00060 return 0; 00061 } 00062 00063 static 00064 void 00065 socketDtor(void * _this) 00066 { 00067 Sock this = _this; 00068 00069 if (STDERR_FILENO < this->handle) { 00070 shutdown(this->handle, SHUT_RDWR); 00071 close(this->handle); 00072 } 00073 } 00074 00075 INIT_IFACE(Class, socketCtor, socketDtor, NULL); 00076 CREATE_CLASS(Sock, NULL, IFACE(Class)); 00077 00078 // vim: set ts=4 sw=4: