taskrambler  0.1.9
Web server and task management solution.
server.h File Reference
#include <stdio.h>
#include <poll.h>
#include <openssl/ssl.h>
#include "class.h"
#include "socket.h"
#include "logger.h"
#include "stream.h"
+ Include dependency graph for server.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  conns
 

Functions

 CLASS (Server)
 
void serverRun (Server this)
 

Detailed Description

Server class. Handles acceptance and closing of connection and uses a class that has to implement the stream reader and writer interface to handle incoming reads and outgoing writes.

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 server.h.


Data Structure Documentation

struct conns

Definition at line 39 of file server.h.

+ Collaboration diagram for conns:
Data Fields
Sock sock
Stream stream
void * worker

Function Documentation

CLASS ( Server  )

Definition at line 45 of file server.h.

References logger.

45  {
46  Logger logger;
47  Sock sock;
48  Sock sockSSL;
49  SSL_CTX * ctx;
50  void * worker;
51 
52  nfds_t nfds;
53  struct pollfd * fds;
54  long max_fds;
55 
56  struct conns * conns;
57 };
Logger logger
Definition: taskrambler.c:66
Definition: server.h:39
void serverRun ( Server  this)

until error or signal

handle accept

handle accept SSL

handle reads

handle writes

Definition at line 36 of file run.c.

References doShutdown, logger, LOGGER_INFO, loggerLog(), serverCloseConn(), serverHandleAccept(), serverPoll(), serverRead(), and serverWrite().

Referenced by main().

37 {
38  int events = 0;
39 
40  loggerLog(this->logger, LOGGER_INFO, "service started");
41 
42  while (!doShutdown) //! until error or signal
43  {
44  unsigned int i;
45 
46  if (0 <= events) {
47  /*
48  * TODO check why sometimes events is less than 0
49  * There is still a misshandling here.
50  */
51  events = serverPoll(this);
52  }
53 
54  /**
55  * handle accept
56  */
57  if (0 != ((this->fds)[0].revents & POLLIN)) {
58  while (0 < serverHandleAccept(this, 0)) {}
59  events--;
60  }
61 
62  if (events == 0) {
63  continue;
64  }
65 
66  /**
67  * handle accept SSL
68  */
69  if (0 != ((this->fds)[1].revents & POLLIN)) {
70  while (0 < serverHandleAccept(this, 1)) {}
71  events--;
72  }
73 
74  if (events == 0) {
75  continue;
76  }
77 
78  for (i=2; i < this->nfds; i++) {
79  /**
80  * handle reads
81  */
82  if (0 != ((this->fds)[i].revents & POLLIN)) {
83  ssize_t processed = serverRead(this, i);
84 
85  if (0 > processed) {
86  events--;
87 
88  switch (processed) {
89  case -2: // close me...
90  serverCloseConn(this, i);
91 
92  case -1: // poll me again
93  break;
94  }
95  }
96 
97  if (0 < processed) {
98  (this->fds)[i].events |= POLLOUT;
99  }
100  }
101 
102  if (events == 0) {
103  break;
104  }
105 
106  /**
107  * handle writes
108  */
109  if (0 != ((this->fds)[i].revents & POLLOUT)) {
110  ssize_t remaining = serverWrite(this, i);
111 
112  if (0 >= remaining) {
113  /*
114  * 0 means queue was empty...try again next
115  * time...no need to poll again.
116  * Anyway, most likely we need to read again
117  * so lets finish this event for now.
118  */
119  events--;
120 
121  switch (remaining) {
122  case 0: // nothing more to write stop polling
123  (this->fds)[i].events &= ~POLLOUT;
124  break;
125 
126  case -2: // close me...
127  serverCloseConn(this, i);
128 
129  case -1: // poll me again
130  break;
131  }
132  }
133  }
134 
135  if (events == 0) {
136  break; // no more events to handle
137  }
138  }
139  }
140 }
Logger logger
Definition: taskrambler.c:66
ssize_t serverRead(Server, unsigned int)
Definition: server/read.c:31
void loggerLog(void *, logger_level, const char *const,...)
Definition: i_logger.c:38
void serverCloseConn(Server, unsigned int)
Definition: close_conn.c:31
int serverHandleAccept(Server, unsigned int)
Definition: handle_accept.c:36
ssize_t serverWrite(Server, unsigned int)
Definition: server/write.c:30
int serverPoll(Server)
Definition: poll.c:34
volatile int doShutdown

+ Here is the call graph for this function:

+ Here is the caller graph for this function: