summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2007-06-13 07:21:51 +0000
committerChristian Grothoff <christian@grothoff.org>2007-06-13 07:21:51 +0000
commit67b4004e738e976179272da7e254f6b72887bc94 (patch)
tree9822a4df9051a29c4da961cd847596b69042821b
parent0ddd6fdd1d9dcd52635a8f6244c2093242efe33f (diff)
added essential logging
-rw-r--r--README1
-rw-r--r--src/daemon/daemon.c32
-rw-r--r--src/daemon/session.c27
3 files changed, 38 insertions, 22 deletions
diff --git a/README b/README
index fd046b25..a91c1055 100644
--- a/README
+++ b/README
@@ -10,7 +10,6 @@ In general:
===========
daemon.c:
- MHD_cleanup_session: major memory leaks (headers!)
-- add additional LOG messages for debugging
session.c:
- MHD_session_get_fdset (essentially not implemented)
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 5a7db531..3935832e 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -415,8 +415,6 @@ MHD_start_daemon(unsigned int options,
void * dh_cls) {
struct MHD_Daemon * retVal;
int socket_fd;
- int opt;
- int res;
struct sockaddr_in servaddr;
if ((options & MHD_USE_SSL) != 0)
@@ -430,7 +428,10 @@ MHD_start_daemon(unsigned int options,
return NULL;
socket_fd = socket(AF_INET, SOCK_STREAM, 0);
if (socket_fd < 0) {
- /* FIXME: log error */
+ if ((options & MHD_USE_DEBUG) != 0)
+ fprintf(stderr,
+ "Call to socket failed: %s\n",
+ strerror(errno));
return NULL;
}
memset(&servaddr,
@@ -441,22 +442,22 @@ MHD_start_daemon(unsigned int options,
if (bind(socket_fd,
(struct sockaddr *)&servaddr,
sizeof(struct sockaddr_in)) < 0) {
- /* FIXME: log error */
+ if ( (options & MHD_USE_DEBUG) != 0)
+ fprintf(stderr,
+ "Failed to bind to port %u: %s\n",
+ port,
+ strerror(errno));
close(socket_fd);
return NULL;
}
if (listen(socket_fd, 20) < 0) {
- /* FIXME: log error */
+ if ((options & MHD_USE_DEBUG) != 0)
+ fprintf(stderr,
+ "Failed to listen for connections: %s\n",
+ strerror(errno));
+ close(socket_fd);
return NULL;
}
- opt = fcntl(socket_fd, F_GETFL, 0);
- res = fcntl(socket_fd, F_SETFL, opt | O_NONBLOCK);
- if (res < 0) {
- /* FIXME: log error */
- close(socket_fd);
- return NULL;
- }
-
retVal = malloc(sizeof(struct MHD_Daemon));
memset(retVal,
0,
@@ -476,7 +477,9 @@ MHD_start_daemon(unsigned int options,
NULL,
&MHD_select_thread,
daemon)) ) {
- /* FIXME: log error */
+ MHD_DLOG(retVal,
+ "Failed to create listen thread: %s\n",
+ strerror(errno));
free(retVal);
close(socket_fd);
return NULL;
@@ -512,3 +515,4 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) {
free(daemon);
}
+/* end of daemon.c */
diff --git a/src/daemon/session.c b/src/daemon/session.c
index 9e8afa83..b458cad7 100644
--- a/src/daemon/session.c
+++ b/src/daemon/session.c
@@ -175,7 +175,9 @@ MHD_get_next_header_line(struct MHD_Session * session) {
session->read_buffer_size *= 2;
} else {
/* die, header far too long to be reasonable */
- /* FIXME: log */
+ MHD_DLOG(session->daemon,
+ "Received excessively long header line (>%u), closing connection.\n",
+ 4 * MHD_MAX_BUF_SIZE);
close(session->socket_fd);
session->socket_fd = -1;
}
@@ -251,7 +253,8 @@ MHD_parse_session_headers(struct MHD_Session * session) {
colon = strstr(line, ": ");
if (colon == NULL) {
/* error in header line, die hard */
- /* FIXME: log */
+ MHD_DLOG(session->daemon,
+ "Received malformed line (no colon), closing connection.\n");
goto DIE;
}
/* zero-terminate header */
@@ -297,7 +300,9 @@ MHD_session_handle_read(struct MHD_Session * session) {
unsigned int processed;
if (session->bodyReceived) {
- /* FIXME: LOG: why are we in select set? */
+ MHD_DLOG(session->daemon,
+ "Unexpected call to %s.\n",
+ __FUNCTION__);
return MHD_NO;
}
if (session->readLoc >= session->read_buffer_size) {
@@ -315,7 +320,9 @@ MHD_session_handle_read(struct MHD_Session * session) {
if (bytes_read < 0) {
if (errno == EINTR)
return MHD_NO;
- /* FIXME: log error */
+ MHD_DLOG(session->daemon,
+ "Failed to receive data: %s\n",
+ strerror(errno));
return MHD_NO;
}
if (bytes_read == 0) {
@@ -409,7 +416,9 @@ MHD_session_handle_write(struct MHD_Session * session) {
response = session->response;
if(response == NULL) {
- /* FIXME: LOG: why are we here? */
+ MHD_DLOG(session->daemon,
+ "Unexpected call to %s.\n",
+ __FUNCTION__);
return MHD_NO;
}
if (! session->headersSent) {
@@ -422,7 +431,9 @@ MHD_session_handle_write(struct MHD_Session * session) {
if (ret < 0) {
if (errno == EINTR)
return MHD_YES;
- /* FIXME: log error */
+ MHD_DLOG(session->daemon,
+ "Failed to send data: %s\n",
+ strerror(errno));
close(session->socket_fd);
session->socket_fd = -1;
return MHD_NO;
@@ -480,7 +491,9 @@ MHD_session_handle_write(struct MHD_Session * session) {
if (ret == -1) {
if (errno == EINTR)
return MHD_YES;
- /* FIXME: log */
+ MHD_DLOG(session->daemon,
+ "Failed to send data: %s\n",
+ strerror(errno));
return MHD_NO;
}
session->messagePos += ret;