aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r--src/daemon/daemon.c76
1 files changed, 38 insertions, 38 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 379e3cf9..8b4d25dd 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -27,7 +27,7 @@
27 27
28#include "internal.h" 28#include "internal.h"
29#include "response.h" 29#include "response.h"
30#include "session.h" 30#include "connection.h"
31 31
32#define MHD_MAX_CONNECTIONS FD_SETSIZE -4 32#define MHD_MAX_CONNECTIONS FD_SETSIZE -4
33 33
@@ -120,7 +120,7 @@ MHD_get_fdset(struct MHD_Daemon * daemon,
120 fd_set * write_fd_set, 120 fd_set * write_fd_set,
121 fd_set * except_fd_set, 121 fd_set * except_fd_set,
122 int * max_fd) { 122 int * max_fd) {
123 struct MHD_Session * pos; 123 struct MHD_Connection * pos;
124 124
125 if ( (daemon == NULL) || 125 if ( (daemon == NULL) ||
126 (read_fd_set == NULL) || 126 (read_fd_set == NULL) ||
@@ -135,7 +135,7 @@ MHD_get_fdset(struct MHD_Daemon * daemon,
135 *max_fd = daemon->socket_fd; 135 *max_fd = daemon->socket_fd;
136 pos = daemon->connections; 136 pos = daemon->connections;
137 while (pos != NULL) { 137 while (pos != NULL) {
138 if (MHD_YES != MHD_session_get_fdset(pos, 138 if (MHD_YES != MHD_connection_get_fdset(pos,
139 read_fd_set, 139 read_fd_set,
140 write_fd_set, 140 write_fd_set,
141 except_fd_set, 141 except_fd_set,
@@ -153,7 +153,7 @@ MHD_get_fdset(struct MHD_Daemon * daemon,
153 */ 153 */
154static void * 154static void *
155MHD_handle_connection(void * data) { 155MHD_handle_connection(void * data) {
156 struct MHD_Session * con = data; 156 struct MHD_Connection * con = data;
157 int num_ready; 157 int num_ready;
158 fd_set rs; 158 fd_set rs;
159 fd_set ws; 159 fd_set ws;
@@ -168,7 +168,7 @@ MHD_handle_connection(void * data) {
168 FD_ZERO(&ws); 168 FD_ZERO(&ws);
169 FD_ZERO(&es); 169 FD_ZERO(&es);
170 max = 0; 170 max = 0;
171 MHD_session_get_fdset(con, 171 MHD_connection_get_fdset(con,
172 &rs, 172 &rs,
173 &ws, 173 &ws,
174 &es, 174 &es,
@@ -184,14 +184,14 @@ MHD_handle_connection(void * data) {
184 break; 184 break;
185 } 185 }
186 if ( ( (FD_ISSET(con->socket_fd, &rs)) && 186 if ( ( (FD_ISSET(con->socket_fd, &rs)) &&
187 (MHD_YES != MHD_session_handle_read(con)) ) || 187 (MHD_YES != MHD_connection_handle_read(con)) ) ||
188 ( (con->socket_fd != -1) && 188 ( (con->socket_fd != -1) &&
189 (FD_ISSET(con->socket_fd, &ws)) && 189 (FD_ISSET(con->socket_fd, &ws)) &&
190 (MHD_YES != MHD_session_handle_write(con)) ) ) 190 (MHD_YES != MHD_connection_handle_write(con)) ) )
191 break; 191 break;
192 if ( (con->headersReceived == 1) && 192 if ( (con->headersReceived == 1) &&
193 (con->response == NULL) ) 193 (con->response == NULL) )
194 MHD_call_session_handler(con); 194 MHD_call_connection_handler(con);
195 } 195 }
196 if (con->socket_fd != -1) { 196 if (con->socket_fd != -1) {
197 CLOSE(con->socket_fd); 197 CLOSE(con->socket_fd);
@@ -202,13 +202,13 @@ MHD_handle_connection(void * data) {
202 202
203 203
204/** 204/**
205 * Accept an incoming connection and create the MHD_Session object for 205 * Accept an incoming connection and create the MHD_Connection object for
206 * it. This function also enforces policy by way of checking with the 206 * it. This function also enforces policy by way of checking with the
207 * accept policy callback. 207 * accept policy callback.
208 */ 208 */
209static int 209static int
210MHD_accept_connection(struct MHD_Daemon * daemon) { 210MHD_accept_connection(struct MHD_Daemon * daemon) {
211 struct MHD_Session * session; 211 struct MHD_Connection * connection;
212 struct sockaddr addr; 212 struct sockaddr addr;
213 socklen_t addrlen; 213 socklen_t addrlen;
214 int s; 214 int s;
@@ -233,50 +233,50 @@ MHD_accept_connection(struct MHD_Daemon * daemon) {
233 CLOSE(s); 233 CLOSE(s);
234 return MHD_YES; 234 return MHD_YES;
235 } 235 }
236 session = malloc(sizeof(struct MHD_Session)); 236 connection = malloc(sizeof(struct MHD_Connection));
237 memset(session, 237 memset(connection,
238 0, 238 0,
239 sizeof(struct MHD_Session)); 239 sizeof(struct MHD_Connection));
240 session->addr = malloc(addrlen); 240 connection->addr = malloc(addrlen);
241 memcpy(session->addr, 241 memcpy(connection->addr,
242 &addr, 242 &addr,
243 addrlen); 243 addrlen);
244 session->addr_len = addrlen; 244 connection->addr_len = addrlen;
245 session->socket_fd = s; 245 connection->socket_fd = s;
246 session->daemon = daemon; 246 connection->daemon = daemon;
247 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) && 247 if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION) ) &&
248 (0 != pthread_create(&session->pid, 248 (0 != pthread_create(&connection->pid,
249 NULL, 249 NULL,
250 &MHD_handle_connection, 250 &MHD_handle_connection,
251 session)) ) { 251 connection)) ) {
252 MHD_DLOG(daemon, 252 MHD_DLOG(daemon,
253 "Failed to create a thread: %s\n", 253 "Failed to create a thread: %s\n",
254 STRERROR(errno)); 254 STRERROR(errno));
255 free(session->addr); 255 free(connection->addr);
256 CLOSE(s); 256 CLOSE(s);
257 free(session); 257 free(connection);
258 return MHD_NO; 258 return MHD_NO;
259 } 259 }
260 session->next = daemon->connections; 260 connection->next = daemon->connections;
261 daemon->connections = session; 261 daemon->connections = connection;
262 return MHD_YES; 262 return MHD_YES;
263} 263}
264 264
265 265
266/** 266/**
267 * Free resources associated with all closed sessions. 267 * Free resources associated with all closed connections.
268 * (destroy responses, free buffers, etc.). A session 268 * (destroy responses, free buffers, etc.). A connection
269 * is known to be closed if the socket_fd is -1. 269 * is known to be closed if the socket_fd is -1.
270 * 270 *
271 * Also performs session actions that need to be run 271 * Also performs connection actions that need to be run
272 * even if the session is not selectable (such as 272 * even if the connection is not selectable (such as
273 * calling the application again with upload data when 273 * calling the application again with upload data when
274 * the upload data buffer is full). 274 * the upload data buffer is full).
275 */ 275 */
276static void 276static void
277MHD_cleanup_sessions(struct MHD_Daemon * daemon) { 277MHD_cleanup_connections(struct MHD_Daemon * daemon) {
278 struct MHD_Session * pos; 278 struct MHD_Connection * pos;
279 struct MHD_Session * prev; 279 struct MHD_Connection * prev;
280 struct MHD_HTTP_Header * hpos; 280 struct MHD_HTTP_Header * hpos;
281 void * unused; 281 void * unused;
282 282
@@ -320,7 +320,7 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) {
320 320
321 if ( (pos->headersReceived == 1) && 321 if ( (pos->headersReceived == 1) &&
322 (pos->response == NULL) ) 322 (pos->response == NULL) )
323 MHD_call_session_handler(pos); 323 MHD_call_connection_handler(pos);
324 324
325 prev = pos; 325 prev = pos;
326 pos = pos->next; 326 pos = pos->next;
@@ -337,7 +337,7 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) {
337static int 337static int
338MHD_select(struct MHD_Daemon * daemon, 338MHD_select(struct MHD_Daemon * daemon,
339 int may_block) { 339 int may_block) {
340 struct MHD_Session * pos; 340 struct MHD_Connection * pos;
341 int num_ready; 341 int num_ready;
342 fd_set rs; 342 fd_set rs;
343 fd_set ws; 343 fd_set ws;
@@ -397,9 +397,9 @@ MHD_select(struct MHD_Daemon * daemon,
397 continue; 397 continue;
398 } 398 }
399 if (FD_ISSET(ds, &rs)) 399 if (FD_ISSET(ds, &rs))
400 MHD_session_handle_read(pos); 400 MHD_connection_handle_read(pos);
401 if (FD_ISSET(ds, &ws)) 401 if (FD_ISSET(ds, &ws))
402 MHD_session_handle_write(pos); 402 MHD_connection_handle_write(pos);
403 pos = pos->next; 403 pos = pos->next;
404 } 404 }
405 } 405 }
@@ -424,7 +424,7 @@ MHD_run(struct MHD_Daemon * daemon) {
424 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) ) 424 (0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
425 return MHD_NO; 425 return MHD_NO;
426 MHD_select(daemon, MHD_NO); 426 MHD_select(daemon, MHD_NO);
427 MHD_cleanup_sessions(daemon); 427 MHD_cleanup_connections(daemon);
428 return MHD_YES; 428 return MHD_YES;
429} 429}
430 430
@@ -438,7 +438,7 @@ MHD_select_thread(void * cls) {
438 struct MHD_Daemon * daemon = cls; 438 struct MHD_Daemon * daemon = cls;
439 while (daemon->shutdown == 0) { 439 while (daemon->shutdown == 0) {
440 MHD_select(daemon, MHD_YES); 440 MHD_select(daemon, MHD_YES);
441 MHD_cleanup_sessions(daemon); 441 MHD_cleanup_connections(daemon);
442 } 442 }
443 return NULL; 443 return NULL;
444} 444}
@@ -559,7 +559,7 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) {
559 CLOSE(daemon->connections->socket_fd); 559 CLOSE(daemon->connections->socket_fd);
560 daemon->connections->socket_fd = -1; 560 daemon->connections->socket_fd = -1;
561 } 561 }
562 MHD_cleanup_sessions(daemon); 562 MHD_cleanup_connections(daemon);
563 } 563 }
564 free(daemon); 564 free(daemon);
565} 565}