taskrambler  0.1.9
Web server and task management solution.
socket.c File Reference
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include "socket.h"
#include "logger.h"
#include "class.h"
+ Include dependency graph for socket.c:

Go to the source code of this file.

Functions

static int socketCtor (void *_this, va_list *params)
 
static void socketDtor (void *_this)
 
 INIT_IFACE (Class, socketCtor, socketDtor, NULL)
 
 CREATE_CLASS (Sock, NULL, IFACE(Class))
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file socket.c.

Function Documentation

CREATE_CLASS ( Sock  ,
NULL  ,
IFACE(Class)   
)
INIT_IFACE ( Class  ,
socketCtor  ,
socketDtor  ,
NULL   
)
static int socketCtor ( void *  _this,
va_list *  params 
)
static
Todo:
make this configurable

if port is -1 do not initialize the socket. (Used with accept)

Create socket for incoming connections

Make the socket REUSE a TIME_WAIT socket

Definition at line 33 of file socket.c.

References LOGGER_CRIT, and loggerLog().

34 {
35  Sock this = _this;
36  int reUse = 1; //! \todo make this configurable
37  int port;
38 
39  this->log = va_arg(* params, Logger);
40  port = va_arg(* params, int);
41 
42  //! if port is -1 do not initialize the socket. (Used with accept)
43  if (-1 == port) {
44  return 0;
45  } else {
46  this->port = port;
47  }
48 
49  //! Create socket for incoming connections
50  if (-1 == (this->handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))) {
51  loggerLog(this->log, LOGGER_CRIT,
52  "error opening socket: %s - service terminated",
53  strerror(errno));
54  return -1;
55  }
56 
57  //! Make the socket REUSE a TIME_WAIT socket
58  setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof(reUse));
59 
60  return 0;
61 }
void loggerLog(void *, logger_level, const char *const,...)
Definition: i_logger.c:38

+ Here is the call graph for this function:

static void socketDtor ( void *  _this)
static

Definition at line 65 of file socket.c.

66 {
67  Sock this = _this;
68 
69  if (STDERR_FILENO < this->handle) {
70  shutdown(this->handle, SHUT_RDWR);
71  close(this->handle);
72  }
73 }