THTTPD now gets past initialization

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2007 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2009-08-02 16:08:20 +00:00
parent 4322c23e43
commit 7c8051a574
5 changed files with 28 additions and 22 deletions

View File

@ -87,9 +87,9 @@ struct in_addr
struct sockaddr_in struct sockaddr_in
{ {
sa_family_t sin_family; /* address family: AF_INET */ sa_family_t sin_family; /* Address family: AF_INET */
uint16 sin_port; /* port in network byte order */ uint16 sin_port; /* Port in network byte order */
struct in_addr sin_addr; /* internet address */ struct in_addr sin_addr; /* Internet address */
}; };
/* IPv6 Internet address */ /* IPv6 Internet address */

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* net/listen.c * net/listen.c
* *
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -43,6 +43,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <errno.h> #include <errno.h>
#include <debug.h>
#include "net_internal.h" #include "net_internal.h"
@ -96,7 +97,7 @@ int listen(int sockfd, int backlog)
if (!psock || psock->s_crefs <= 0) if (!psock || psock->s_crefs <= 0)
{ {
/* It is not a valid socket description. Distinguish between the cases /* It is not a valid socket description. Distinguish between the cases
* where sockfd is a just valid and when it is a valid file descriptor used * where sockfd is a just invalid and when it is a valid file descriptor used
* in the wrong context. * in the wrong context.
*/ */

View File

@ -158,11 +158,11 @@ int net_vfcntl(int sockfd, int cmd, va_list ap)
{ {
if ((mode & O_NONBLOCK) != 0) if ((mode & O_NONBLOCK) != 0)
{ {
psock->s_type |= _SF_NONBLOCK; psock->s_flags |= _SF_NONBLOCK;
} }
else else
{ {
psock->s_type &= ~_SF_NONBLOCK; psock->s_flags &= ~_SF_NONBLOCK;
} }
} }
#endif #endif

View File

@ -202,7 +202,11 @@ static int check_referer(httpd_conn *hc);
#ifdef CONFIG_THTTPD_URLPATTERN #ifdef CONFIG_THTTPD_URLPATTERN
static int really_check_referer(httpd_conn *hc); static int really_check_referer(httpd_conn *hc);
#endif #endif
#ifdef CONFIG_DEBUG
static int sockaddr_check(httpd_sockaddr *saP); static int sockaddr_check(httpd_sockaddr *saP);
#else
# define sockaddr_check(saP) (1)
#endif
static size_t sockaddr_len(httpd_sockaddr *saP); static size_t sockaddr_len(httpd_sockaddr *saP);
/**************************************************************************** /****************************************************************************
@ -295,11 +299,13 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
/* Check sockaddr. */ /* Check sockaddr. */
#ifdef CONFIG_DEBUG
if (!sockaddr_check(saP)) if (!sockaddr_check(saP))
{ {
ndbg("unknown sockaddr family on listen socket\n"); ndbg("unknown sockaddr family on listen socket\n");
return -1; return -1;
} }
#endif
/* Create socket. */ /* Create socket. */
@ -321,7 +327,7 @@ static int initialize_listen_socket(httpd_sockaddr *saP)
/* Bind to it. */ /* Bind to it. */
if (bind(listen_fd, (struct sockaddr*)&saP, sockaddr_len(saP)) < 0) if (bind(listen_fd, (struct sockaddr*)saP, sockaddr_len(saP)) < 0)
{ {
ndbg("bind to %s failed: %d\n", httpd_ntoa(saP), errno); ndbg("bind to %s failed: %d\n", httpd_ntoa(saP), errno);
(void)close(listen_fd); (void)close(listen_fd);
@ -3293,6 +3299,7 @@ static int really_check_referer(httpd_conn *hc)
} }
#endif #endif
#ifdef CONFIG_DEBUG
static int sockaddr_check(httpd_sockaddr *saP) static int sockaddr_check(httpd_sockaddr *saP)
{ {
switch (saP->sin_family) switch (saP->sin_family)
@ -3309,6 +3316,7 @@ static int sockaddr_check(httpd_sockaddr * saP)
return 0; return 0;
} }
} }
#endif
static size_t sockaddr_len(httpd_sockaddr *saP) static size_t sockaddr_len(httpd_sockaddr *saP)
{ {
@ -3382,7 +3390,6 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd)
return NULL; return NULL;
} }
nvdbg("Calling init_mime()\n");
init_mime(); init_mime();
/* Done initializing. */ /* Done initializing. */
@ -3593,6 +3600,7 @@ int httpd_get_conn(httpd_server * hs, int listen_fd, httpd_conn *hc)
return GC_FAIL; return GC_FAIL;
} }
#ifdef CONFIG_DEBUG
if (!sockaddr_check(&sa)) if (!sockaddr_check(&sa))
{ {
ndbg("unknown sockaddr family\n"); ndbg("unknown sockaddr family\n");
@ -3600,6 +3608,7 @@ int httpd_get_conn(httpd_server * hs, int listen_fd, httpd_conn *hc)
hc->conn_fd = -1; hc->conn_fd = -1;
return GC_FAIL; return GC_FAIL;
} }
#endif
hc->hs = hs; hc->hs = hs;
(void)memset(&hc->client_addr, 0, sizeof(hc->client_addr)); (void)memset(&hc->client_addr, 0, sizeof(hc->client_addr));

View File

@ -737,11 +737,7 @@ int thttpd_main(int argc, char **argv)
int cnum; int cnum;
FAR struct connect_s *conn; FAR struct connect_s *conn;
FAR httpd_conn *hc; FAR httpd_conn *hc;
#ifdef CONFIG_NET_IPv6 httpd_sockaddr sa;
struct sockaddr_in6 sa;
#else
struct sockaddr_in sa;
#endif
struct timeval tv; struct timeval tv;
#ifdef CONFIG_THTTPD_DIR #ifdef CONFIG_THTTPD_DIR
int ret; int ret;