taskrambler  0.1.8
Web server and task management solution.
handle_accept.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <openssl/ssl.h>
#include "http/worker.h"
#include "server.h"
#include "class.h"
#include "logger.h"
#include "stream.h"
+ Include dependency graph for handle_accept.c:

Go to the source code of this file.

Functions

int serverHandleAccept (Server this, unsigned int i)
 

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 handle_accept.c.

Function Documentation

int serverHandleAccept ( Server  this,
unsigned int  i 
)

Definition at line 36 of file handle_accept.c.

References clone, logger, LOGGER_DEBUG, loggerLog(), socketAccept(), socketNonblock(), STREAM_FD, and STREAM_SSL.

Referenced by serverRun().

37 {
38  char remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
39  Sock acc = NULL;
40  Stream st;
41 
42  if (this->nfds >= this->max_fds) {
43  return -1;
44  }
45 
46  acc = socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr);
47 
48  if (NULL != acc && -1 != acc->handle) {
49  socketNonblock(acc);
50 
51  switch(i) {
52  case 0:
53  // no SSL
54  st = new(Stream, STREAM_FD, acc->handle);
55  break;
56 
57  case 1:
58  // SSL
59  {
60  SSL * ssl = SSL_new(this->ctx);
61  SSL_set_fd(ssl, acc->handle);
62  SSL_accept(ssl);
63  st = new(Stream, STREAM_SSL, ssl);
64  }
65  break;
66 
67  default:
68  st = NULL;
69  break;
70  }
71 
72  // save the socket handle
73  (this->conns)[acc->handle].sock = acc;
74 
75  // clone worker
76  (this->conns)[acc->handle].worker = clone(this->worker);
77  (this->conns)[acc->handle].stream = st;
78 
79  (this->fds)[this->nfds].fd = acc->handle;
80  (this->fds)[this->nfds].events = POLLIN;
81  this->nfds++;
82  } else {
83  delete(acc);
84 
85  switch(errno) {
86  case EAGAIN|EWOULDBLOCK:
87  case EINTR:
88  loggerLog(this->logger,
90  "server accept blocks");
91  return -1;
92  break;
93 
94  default:
95  loggerLog(this->logger,
97  "server accept error");
98  return -2;
99  break;
100  }
101  }
102 
103  if (0 == this->nfds%200) {
104  loggerLog(this->logger,
105  LOGGER_DEBUG, "paralel connections: %lu", this->nfds);
106  }
107 
108  return acc->handle;
109 }
Logger logger
Definition: taskrambler.c:66
Sock socketAccept(Sock this, char(*remoteAddr)[16])
Definition: accept.c:32
void socketNonblock(Sock this)
Definition: nonblock.c:32
void loggerLog(void *, logger_level, const char *const,...)
Definition: i_logger.c:38
#define clone(object)
Definition: server.h:39

+ Here is the call graph for this function:

+ Here is the caller graph for this function: