Home | History | Annotate | Download | only in microspdy
      1 /*
      2     This file is part of libmicrospdy
      3     Copyright Copyright (C) 2012 Andrey Uzunov
      4 
      5     This program is free software: you can redistribute it and/or modify
      6     it under the terms of the GNU General Public License as published by
      7     the Free Software Foundation, either version 3 of the License, or
      8     (at your option) any later version.
      9 
     10     This program is distributed in the hope that it will be useful,
     11     but WITHOUT ANY WARRANTY; without even the implied warranty of
     12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13     GNU General Public License for more details.
     14 
     15     You should have received a copy of the GNU General Public License
     16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 */
     18 
     19 /**
     20  * @file daemon.h
     21  * @brief  daemon functionality
     22  * @author Andrey Uzunov
     23  */
     24 
     25 #ifndef DAEMON_H
     26 #define DAEMON_H
     27 
     28 #include "platform.h"
     29 
     30 
     31 /**
     32  * Global flags containing the initialized IO subsystems.
     33  */
     34 enum SPDY_IO_SUBSYSTEM spdyf_io_initialized;
     35 
     36 
     37 /**
     38  * Start a SPDDY webserver on the given port.
     39  *
     40  * @param port port to bind to
     41  * @param certfile path to the certificate that will be used by server
     42  * @param keyfile path to the keyfile for the certificate
     43  * @param nscb callback called when a new SPDY session is
     44  * 			established	by a client
     45  * @param sccb callback called when a client closes the session
     46  * @param nrcb callback called when a client sends request
     47  * @param npdcb callback called when HTTP POST params are received
     48  * 			after request
     49  * @param fnscb callback called when new stream is opened by a client
     50  * @param fndcb callback called when new data -- within a data frame --
     51  *        is received by the server
     52  * @param cls extra argument to all of the callbacks without those
     53  * 				 specific only for the framing layer
     54  * @param fcls extra argument to all of the callbacks, specific only for
     55  * 				the framing layer (those vars starting with 'f').
     56  * @param valist va_list of options (type-value pairs,
     57  *        terminated with SPDY_DAEMON_OPTION_END).
     58  * @return NULL on error, handle to daemon on success
     59  */
     60 struct SPDY_Daemon *
     61 SPDYF_start_daemon_va (uint16_t port,
     62 					const char *certfile,
     63 					const char *keyfile,
     64 					SPDY_NewSessionCallback nscb,
     65 					SPDY_SessionClosedCallback sccb,
     66 					SPDY_NewRequestCallback nrcb,
     67 					SPDY_NewDataCallback npdcb,
     68 					SPDYF_NewStreamCallback fnscb,
     69 					SPDYF_NewDataCallback fndcb,
     70 					void * cls,
     71 					void * fcls,
     72 					va_list valist);
     73 
     74 
     75 /**
     76  * Run webserver operations (without blocking unless
     77  * in client callbacks). This method must be called in the client event
     78  * loop.
     79  *
     80  * @param daemon daemon to run
     81  */
     82 void
     83 SPDYF_run (struct SPDY_Daemon *daemon);
     84 
     85 
     86 /**
     87  * Obtain timeout value for select for this daemon. The returned value
     88  * is how long select
     89  * should at most block, not the timeout value set for connections.
     90  *
     91  * @param daemon daemon to query for timeout
     92  * @param timeout set to the timeout (in milliseconds)
     93  * @return SPDY_YES on success, SPDY_NO if no connections exist that
     94  * 			would necessiate the use of a timeout right now
     95  */
     96 int
     97 SPDYF_get_timeout (struct SPDY_Daemon *daemon,
     98 		     unsigned long long *timeout);
     99 
    100 
    101 /**
    102  * Obtain the select sets for this daemon. The idea of SPDYF_get_fdset
    103  * is to return such descriptors that the select in the application can
    104  * return and SPDY_run can be called only when this is really needed.
    105  * That means not all sockets will be added to write_fd_set.
    106  *
    107  * @param daemon daemon to get sets from
    108  * @param read_fd_set read set
    109  * @param write_fd_set write set
    110  * @param except_fd_set except set
    111  * @param all add all session's descriptors to write_fd_set or not
    112  * @return largest FD added
    113  */
    114 int
    115 SPDYF_get_fdset (struct SPDY_Daemon *daemon,
    116 				fd_set *read_fd_set,
    117 				fd_set *write_fd_set,
    118 				fd_set *except_fd_set,
    119 				bool all);
    120 
    121 
    122 /**
    123  * Shutdown the daemon.
    124  *
    125  * @param daemon daemon to stop
    126  */
    127 void
    128 SPDYF_stop_daemon (struct SPDY_Daemon *daemon);
    129 
    130 #endif
    131