aboutsummaryrefslogtreecommitdiff
path: root/src/daemon
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon')
-rw-r--r--src/daemon/EXPORT.sym1
-rw-r--r--src/daemon/connection.c7
-rw-r--r--src/daemon/connection_https.c2
-rw-r--r--src/daemon/connection_https.h2
-rw-r--r--src/daemon/daemon.c30
-rw-r--r--src/daemon/internal.h34
-rw-r--r--src/daemon/response.c22
7 files changed, 58 insertions, 40 deletions
diff --git a/src/daemon/EXPORT.sym b/src/daemon/EXPORT.sym
index 32096ad6..53bd960b 100644
--- a/src/daemon/EXPORT.sym
+++ b/src/daemon/EXPORT.sym
@@ -10,6 +10,7 @@ MHD_lookup_connection_value
10MHD_queue_response 10MHD_queue_response
11MHD_create_response_from_callback 11MHD_create_response_from_callback
12MHD_create_response_from_data 12MHD_create_response_from_data
13MHD_create_response_from_fd
13MHD_destroy_response 14MHD_destroy_response
14MHD_add_response_header 15MHD_add_response_header
15MHD_del_response_header 16MHD_del_response_header
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index dab19472..a56106a4 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007, 2008 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2008, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
@@ -336,7 +336,10 @@ try_ready_normal_body (struct MHD_Connection *connection)
336#if LINUX 336#if LINUX
337 if ( (response->fd != -1) && 337 if ( (response->fd != -1) &&
338 (0 == (connection->daemon->options & MHD_USE_SSL)) ) 338 (0 == (connection->daemon->options & MHD_USE_SSL)) )
339 return MHD_YES; /* will use sendfile */ 339 {
340 /* will use sendfile, no need to bother response crc */
341 return MHD_YES;
342 }
340#endif 343#endif
341 ret = response->crc (response->crc_cls, 344 ret = response->crc (response->crc_cls,
342 connection->response_write_position, 345 connection->response_write_position,
diff --git a/src/daemon/connection_https.c b/src/daemon/connection_https.c
index b00da807..e24da021 100644
--- a/src/daemon/connection_https.c
+++ b/src/daemon/connection_https.c
@@ -198,7 +198,7 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection)
198 * the processing of this secure connection. 198 * the processing of this secure connection.
199 */ 199 */
200void 200void
201MHD_set_https_calbacks (struct MHD_Connection *connection) 201MHD_set_https_callbacks (struct MHD_Connection *connection)
202{ 202{
203 connection->read_handler = &MHD_tls_connection_handle_read; 203 connection->read_handler = &MHD_tls_connection_handle_read;
204 connection->write_handler = &MHD_tls_connection_handle_write; 204 connection->write_handler = &MHD_tls_connection_handle_write;
diff --git a/src/daemon/connection_https.h b/src/daemon/connection_https.h
index ef6f5dc6..8a5cf380 100644
--- a/src/daemon/connection_https.h
+++ b/src/daemon/connection_https.h
@@ -29,7 +29,7 @@
29#include "internal.h" 29#include "internal.h"
30 30
31#if HTTPS_SUPPORT 31#if HTTPS_SUPPORT
32void MHD_set_https_calbacks (struct MHD_Connection *connection); 32void MHD_set_https_callbacks (struct MHD_Connection *connection);
33#endif 33#endif
34 34
35#endif 35#endif
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index f704382d..73a0f163 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007, 2008, 2009 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2008, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
@@ -387,8 +387,8 @@ MHD_init_daemon_certificate (struct MHD_Daemon *daemon)
387 cert.size = strlen (daemon->https_mem_cert); 387 cert.size = strlen (daemon->https_mem_cert);
388 388
389 return gnutls_certificate_set_x509_key_mem (daemon->x509_cred, 389 return gnutls_certificate_set_x509_key_mem (daemon->x509_cred,
390 &cert, &key, 390 &cert, &key,
391 GNUTLS_X509_FMT_PEM); 391 GNUTLS_X509_FMT_PEM);
392 } 392 }
393#if HAVE_MESSAGES 393#if HAVE_MESSAGES
394 MHD_DLOG (daemon, "You need to specify a certificate and key location\n"); 394 MHD_DLOG (daemon, "You need to specify a certificate and key location\n");
@@ -625,21 +625,28 @@ send_param_adapter (struct MHD_Connection *connection,
625#if LINUX 625#if LINUX
626 int fd; 626 int fd;
627 off_t offset; 627 off_t offset;
628 int ret;
628#endif 629#endif
629 if (connection->socket_fd == -1) 630 if (connection->socket_fd == -1)
630 return -1; 631 return -1;
631 if (0 != (connection->daemon->options & MHD_USE_SSL)) 632 if (0 != (connection->daemon->options & MHD_USE_SSL))
632 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL); 633 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL);
633#if LINUX 634#if LINUX
634 if ( (NULL != connection->response) && 635 if ( (connection->write_buffer_append_offset ==
636 connection->write_buffer_send_offset) &&
637 (NULL != connection->response) &&
635 (-1 != (fd = connection->response->fd)) ) 638 (-1 != (fd = connection->response->fd)) )
636 { 639 {
637 /* can use sendfile */ 640 /* can use sendfile */
638 offset = (off_t) connection->response_write_position; 641 offset = (off_t) connection->response_write_position;
639 return sendfile (connection->socket_fd, 642 ret = sendfile (connection->socket_fd,
640 fd, 643 fd,
641 &offset, 644 &offset,
642 i); 645 connection->response->total_size - offset);
646 if ( (ret == -1) &&
647 (errno == EINTR) )
648 return 0;
649 return ret;
643 } 650 }
644#endif 651#endif
645 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL | MSG_DONTWAIT); 652 return SEND (connection->socket_fd, other, i, MSG_NOSIGNAL | MSG_DONTWAIT);
@@ -819,7 +826,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
819 connection->recv_cls = &recv_tls_adapter; 826 connection->recv_cls = &recv_tls_adapter;
820 connection->send_cls = &send_tls_adapter; 827 connection->send_cls = &send_tls_adapter;
821 connection->state = MHD_TLS_CONNECTION_INIT; 828 connection->state = MHD_TLS_CONNECTION_INIT;
822 MHD_set_https_calbacks (connection); 829 MHD_set_https_callbacks (connection);
823 gnutls_init (&connection->tls_session, GNUTLS_SERVER); 830 gnutls_init (&connection->tls_session, GNUTLS_SERVER);
824 gnutls_priority_set (connection->tls_session, 831 gnutls_priority_set (connection->tls_session,
825 daemon->priority_cache); 832 daemon->priority_cache);
@@ -1664,7 +1671,10 @@ MHD_start_daemon_va (unsigned int options,
1664 return NULL; 1671 return NULL;
1665 } 1672 }
1666 } 1673 }
1667 1674 else
1675 {
1676 socket_fd = retVal->socket_fd;
1677 }
1668#ifndef WINDOWS 1678#ifndef WINDOWS
1669 if ( (socket_fd >= FD_SETSIZE) && 1679 if ( (socket_fd >= FD_SETSIZE) &&
1670 (0 == (options & MHD_USE_POLL)) ) 1680 (0 == (options & MHD_USE_POLL)) )
diff --git a/src/daemon/internal.h b/src/daemon/internal.h
index a026eeef..f3f47ce0 100644
--- a/src/daemon/internal.h
+++ b/src/daemon/internal.h
@@ -1,21 +1,21 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2008, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version. 8 version 2.1 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details. 13 Lesser General Public License for more details.
14 14
15 You should have received a copy of the GNU Lesser General Public 15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software 16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 18*/
19 19
20/** 20/**
21 * @file internal.h 21 * @file internal.h
diff --git a/src/daemon/response.c b/src/daemon/response.c
index 0f5501ee..f1379301 100644
--- a/src/daemon/response.c
+++ b/src/daemon/response.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of libmicrohttpd 2 This file is part of libmicrohttpd
3 (C) 2007, 2009 Daniel Pittman and Christian Grothoff 3 (C) 2007, 2009, 2010 Daniel Pittman and Christian Grothoff
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public 6 modify it under the terms of the GNU Lesser General Public
@@ -210,7 +210,7 @@ MHD_create_response_from_callback (uint64_t size,
210 * Given a file descriptor, read data from the file 210 * Given a file descriptor, read data from the file
211 * to generate the response. 211 * to generate the response.
212 * 212 *
213 * @param cls pointer to the file descriptor 213 * @param cls pointer to the response
214 * @param pos offset in the file to access 214 * @param pos offset in the file to access
215 * @param buf where to write the data 215 * @param buf where to write the data
216 * @param max number of bytes to write at most 216 * @param max number of bytes to write at most
@@ -219,10 +219,14 @@ MHD_create_response_from_callback (uint64_t size,
219static int 219static int
220file_reader (void *cls, uint64_t pos, char *buf, int max) 220file_reader (void *cls, uint64_t pos, char *buf, int max)
221{ 221{
222 int *fd = cls; 222 struct MHD_Response *response = cls;
223 int ret;
223 224
224 (void) lseek (*fd, pos, SEEK_SET); 225 pthread_mutex_lock (&response->mutex);
225 return read (*fd, buf, max); 226 (void) lseek (response->fd, pos, SEEK_SET);
227 ret = read (response->fd, buf, max);
228 pthread_mutex_unlock (&response->mutex);
229 return ret;
226} 230}
227 231
228 232
@@ -235,9 +239,9 @@ file_reader (void *cls, uint64_t pos, char *buf, int max)
235static void 239static void
236free_callback (void *cls) 240free_callback (void *cls)
237{ 241{
238 int *fd = cls; 242 struct MHD_Response *response = cls;
239 close (*fd); 243 (void) close (response->fd);
240 *fd = -1; 244 response->fd = -1;
241} 245}
242 246
243 247
@@ -262,7 +266,7 @@ struct MHD_Response *MHD_create_response_from_fd (size_t size,
262 if (ret == NULL) 266 if (ret == NULL)
263 return NULL; 267 return NULL;
264 ret->fd = fd; 268 ret->fd = fd;
265 ret->crc_cls = &ret->fd; 269 ret->crc_cls = ret;
266 return ret; 270 return ret;
267} 271}
268 272