LCOV - code coverage report
Current view: top level - opt/gitlab-ci-multi-runner/builds/00e3338d/0/taskrambler/taskrambler/src/server - handle_accept.c (source / functions) Hit Total Coverage
Test: taskrambler 0.1.9 Lines: 22 33 66.7 %
Date: 2016-04-13 23:18:54 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /**
       2                 :            :  * \file
       3                 :            :  *
       4                 :            :  * \author      Georg Hopp
       5                 :            :  *
       6                 :            :  * \copyright
       7                 :            :  * Copyright © 2012  Georg Hopp
       8                 :            :  *
       9                 :            :  * This program is free software: you can redistribute it and/or modify
      10                 :            :  * it under the terms of the GNU General Public License as published by
      11                 :            :  * the Free Software Foundation, either version 3 of the License, or
      12                 :            :  * (at your option) any later version.
      13                 :            :  *
      14                 :            :  * This program is distributed in the hope that it will be useful,
      15                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17                 :            :  * GNU General Public License for more details.
      18                 :            :  *
      19                 :            :  * You should have received a copy of the GNU General Public License
      20                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <errno.h>
      24                 :            : #include <stdio.h>
      25                 :            : #include <stdlib.h>
      26                 :            : 
      27                 :            : #include <openssl/ssl.h>
      28                 :            : 
      29                 :            : #include "http/worker.h"
      30                 :            : #include "server.h"
      31                 :            : #include "class.h"
      32                 :            : #include "logger.h"
      33                 :            : #include "stream.h"
      34                 :            : 
      35                 :            : int
      36                 :          2 : serverHandleAccept(Server this, unsigned int i)
      37                 :            : {
      38                 :          2 :         char   remoteAddr[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
      39                 :          2 :         Sock   acc = NULL;
      40                 :            :         Stream st;
      41                 :            : 
      42                 :          2 :         if (this->nfds >= this->max_fds) {
      43                 :          0 :                 return -1;
      44                 :            :         }
      45                 :            : 
      46                 :          2 :         acc = socketAccept((0 == i)? this->sock : this->sockSSL, &remoteAddr);
      47                 :            : 
      48                 :          2 :         if (NULL != acc && -1 != acc->handle) {
      49                 :          1 :                 socketNonblock(acc);
      50                 :            : 
      51                 :          1 :                 switch(i) {
      52                 :            :                         case 0:
      53                 :            :                                 // no SSL
      54                 :          1 :                                 st = new(Stream, STREAM_FD, acc->handle);
      55                 :          1 :                                 break;
      56                 :            : 
      57                 :            :                         case 1:
      58                 :            :                                 // SSL
      59                 :            :                                 {
      60                 :          0 :                                         SSL * ssl = SSL_new(this->ctx);
      61                 :          0 :                                         SSL_set_fd(ssl, acc->handle);
      62                 :          0 :                                         SSL_accept(ssl);
      63                 :          0 :                                         st = new(Stream, STREAM_SSL, ssl);
      64                 :            :                                 }
      65                 :          0 :                                 break;
      66                 :            : 
      67                 :            :                         default:
      68                 :          0 :                                 st = NULL;
      69                 :          0 :                                 break;
      70                 :            :                 }
      71                 :            : 
      72                 :            :                 // save the socket handle
      73                 :          1 :                 (this->conns)[acc->handle].sock   = acc; 
      74                 :            : 
      75                 :            :                 // clone worker
      76                 :          1 :                 (this->conns)[acc->handle].worker = clone(this->worker);
      77                 :          1 :                 (this->conns)[acc->handle].stream = st;
      78                 :            : 
      79                 :          1 :                 (this->fds)[this->nfds].fd        = acc->handle;
      80                 :          1 :                 (this->fds)[this->nfds].events    = POLLIN;
      81                 :          1 :                 this->nfds++;
      82                 :            :         } else {
      83                 :          1 :                 delete(acc);
      84                 :            : 
      85                 :          1 :                 switch(errno) {
      86                 :            :                         case EAGAIN|EWOULDBLOCK:
      87                 :            :                         case EINTR:
      88                 :          1 :                                 loggerLog(this->logger,
      89                 :            :                                                 LOGGER_DEBUG,
      90                 :            :                                                 "server accept blocks");
      91                 :          1 :                                 return -1;
      92                 :            :                                 break;
      93                 :            : 
      94                 :            :                         default:
      95                 :          0 :                                 loggerLog(this->logger,
      96                 :            :                                                 LOGGER_DEBUG,
      97                 :            :                                                 "server accept error");
      98                 :          0 :                                 return -2;
      99                 :            :                                 break;
     100                 :            :                 }
     101                 :            :         }
     102                 :            : 
     103                 :          1 :         if (0 == this->nfds%200) {
     104                 :          0 :                 loggerLog(this->logger,
     105                 :            :                                 LOGGER_DEBUG, "paralel connections: %lu", this->nfds);
     106                 :            :         }
     107                 :            : 
     108                 :          1 :         return acc->handle;
     109                 :            : }
     110                 :            : 
     111                 :            : // vim: set ts=4 sw=4:

Generated by: LCOV version 1.11