aboutsummaryrefslogtreecommitdiff
path: root/src/microspdy/daemon.h
blob: 1be6ce5634e5b312863381d23321a376e15d12ea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
    This file is part of libmicrospdy
    Copyright (C) 2012 Andrey Uzunov

    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/>.
*/

/**
 * @file daemon.h
 * @brief  daemon functionality
 * @author Andrey Uzunov
 */

#ifndef DAEMON_H
#define DAEMON_H

#include "platform.h"


/**
 * Global flags containing the initialized IO subsystems.
 */
enum SPDY_IO_SUBSYSTEM spdyf_io_initialized;


/**
 * Start a SPDDY webserver on the given port.
 *
 * @param port port to bind to
 * @param certfile path to the certificate that will be used by server
 * @param keyfile path to the keyfile for the certificate
 * @param nscb callback called when a new SPDY session is
 * 			established	by a client
 * @param sccb callback called when a client closes the session
 * @param nrcb callback called when a client sends request
 * @param npdcb callback called when HTTP POST params are received
 * 			after request
 * @param fnscb callback called when new stream is opened by a client
 * @param fndcb callback called when new data -- within a data frame --
 *        is received by the server
 * @param cls extra argument to all of the callbacks without those
 * 				 specific only for the framing layer
 * @param fcls extra argument to all of the callbacks, specific only for
 * 				the framing layer (those vars starting with 'f').
 * @param valist va_list of options (type-value pairs,
 *        terminated with SPDY_DAEMON_OPTION_END).
 * @return NULL on error, handle to daemon on success
 */
struct SPDY_Daemon *
SPDYF_start_daemon_va (uint16_t port,
					const char *certfile,
					const char *keyfile,
					SPDY_NewSessionCallback nscb,
					SPDY_SessionClosedCallback sccb,
					SPDY_NewRequestCallback nrcb,
					SPDY_NewDataCallback npdcb,
					SPDYF_NewStreamCallback fnscb,
					SPDYF_NewDataCallback fndcb,
					void * cls,
					void * fcls,
					va_list valist);


/**
 * Run webserver operations (without blocking unless
 * in client callbacks). This method must be called in the client event
 * loop.
 *
 * @param daemon daemon to run
 */
void 
SPDYF_run (struct SPDY_Daemon *daemon);


/**
 * Obtain timeout value for select for this daemon. The returned value
 * is how long select
 * should at most block, not the timeout value set for connections.
 *
 * @param daemon daemon to query for timeout
 * @param timeout set to the timeout (in milliseconds)
 * @return SPDY_YES on success, SPDY_NO if no connections exist that
 * 			would necessiate the use of a timeout right now
 */
int
SPDYF_get_timeout (struct SPDY_Daemon *daemon, 
		     unsigned long long *timeout);


/**
 * Obtain the select sets for this daemon. The idea of SPDYF_get_fdset
 * is to return such descriptors that the select in the application can
 * return and SPDY_run can be called only when this is really needed.
 * That means not all sockets will be added to write_fd_set.
 *
 * @param daemon daemon to get sets from
 * @param read_fd_set read set
 * @param write_fd_set write set
 * @param except_fd_set except set
 * @param all add all session's descriptors to write_fd_set or not
 * @return largest FD added
 */
int
SPDYF_get_fdset (struct SPDY_Daemon *daemon,
				fd_set *read_fd_set,
				fd_set *write_fd_set, 
				fd_set *except_fd_set,
				bool all);


/**
 * Shutdown the daemon.
 *
 * @param daemon daemon to stop
 */				
void 
SPDYF_stop_daemon (struct SPDY_Daemon *daemon);

#endif