[Assorted-commits] SF.net SVN: assorted: [472] nano-httpd/trunk/src/nanohttpd.cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-19 07:03:14
|
Revision: 472 http://assorted.svn.sourceforge.net/assorted/?rev=472&view=rev Author: yangzhang Date: 2008-02-18 23:03:19 -0800 (Mon, 18 Feb 2008) Log Message: ----------- ready to run in josmp Modified Paths: -------------- nano-httpd/trunk/src/nanohttpd.cc Modified: nano-httpd/trunk/src/nanohttpd.cc =================================================================== --- nano-httpd/trunk/src/nanohttpd.cc 2008-02-19 06:45:50 UTC (rev 471) +++ nano-httpd/trunk/src/nanohttpd.cc 2008-02-19 07:03:19 UTC (rev 472) @@ -52,33 +52,33 @@ do { \ char b_[4096]; \ int n_ = snprintf(b_, sizeof(b_), __VA_ARGS__); \ - if (send(s, b_, n_, 0) == 0) panic("XXX"); \ + if (lwip_send(s, b_, n_, 0) == -1) panic("XXX"); \ } while (0); #define SERVER "webserver/1.0" #define PROTOCOL "HTTP/1.0" #define RFC1123FMT "%a, %d %b %Y %H:%M:%S GMT" -#define PORT 80 +#define PORT 8000 // XXX void send_headers(int f, int status, char *title, char *extra, char *mime, - int length, time_t date) + int length, int date) { - time_t now; - char timebuf[128]; + //time_t now; + //char timebuf[128]; nprintf(f, "%s %d %s\r\n", PROTOCOL, status, title); nprintf(f, "Server: %s\r\n", SERVER); - now = time(NULL); - strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now)); - nprintf(f, "Date: %s\r\n", timebuf); + //now = time(NULL); + //strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now)); + //nprintf(f, "Date: %s\r\n", timebuf); if (extra) nprintf(f, "%s\r\n", extra); if (mime) nprintf(f, "Content-Type: %s\r\n", mime); if (length >= 0) nprintf(f, "Content-Length: %d\r\n", length); - if (date != -1) - { - strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&date)); - nprintf(f, "Last-Modified: %s\r\n", timebuf); - } + //if (date != -1) + //{ + // strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&date)); + // nprintf(f, "Last-Modified: %s\r\n", timebuf); + //} nprintf(f, "Connection: close\r\n"); nprintf(f, "\r\n"); } @@ -95,6 +95,9 @@ // XXX void send_file(int f, char *path) { + char msg[] = "hello, world!\n"; + send_headers(f, 200, "OK", NULL, "text/plain", sizeof(msg), -1); + if (lwip_send(f, msg, sizeof(msg), 0) == -1) panic("XXX"); // char data[4096]; // int n; // @@ -122,7 +125,7 @@ // char pathbuf[4096]; // int len; - if (recv(f, buf, sizeof(buf), MSG_WAITALL) < 0) return -1; + if (lwip_recv(f, buf, sizeof(buf), 0) < 0) return -1; printf("URL: %s", buf); method = strtok(buf, " "); @@ -200,10 +203,16 @@ int s = lwip_socket(PF_INET, SOCK_STREAM, 0); if (s < 0) panic("XXX"); +#if STANDALONE + int on = 1; + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) + panic("XXX"); +#endif + struct sockaddr_in sa; bzero(&sa, sizeof(sa));; sa.sin_family = AF_INET; - sa.sin_port = htons(8000); + sa.sin_port = htons(PORT); sa.sin_addr.s_addr = htonl(INADDR_ANY); cprintf("bind\n"); @@ -218,6 +227,7 @@ cprintf("processing\n"); if (process(t) < 0) panic("XXX"); + lwip_close(t); } return 0; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |