Commit 063189e6642b7882a343e371e0c0eee04426a2f3
1 parent
b38d4022
changed /**/ single line comments to //
Showing
16 changed files
with
40 additions
and
76 deletions
1 | +2012-02-20 17:16:44 +0100 Georg Hopp | ||
2 | + | ||
3 | + * changed /**/ single line comments to // (HEAD, master) | ||
4 | + | ||
1 | 2012-02-20 14:55:46 +0100 Georg Hopp | 5 | 2012-02-20 14:55:46 +0100 Georg Hopp |
2 | 6 | ||
3 | - * start documenting this whole stuff...well at least add a copyright information in each file (HEAD, master) | 7 | + * start documenting this whole stuff...well at least add a copyright information in each file (origin/master, origin/HEAD) |
4 | 8 | ||
5 | 2012-02-20 10:10:29 +0100 Georg Hopp | 9 | 2012-02-20 10:10:29 +0100 Georg Hopp |
6 | 10 | ||
7 | - * first very crude, not complete, experimental 304 test implementation (origin/master, origin/HEAD) | 11 | + * first very crude, not complete, experimental 304 test implementation |
8 | 12 | ||
9 | 2012-02-20 07:55:06 +0100 Georg Hopp | 13 | 2012-02-20 07:55:06 +0100 Georg Hopp |
10 | 14 |
@@ -40,6 +40,6 @@ CLASS(HttpRequest) { | @@ -40,6 +40,6 @@ CLASS(HttpRequest) { | ||
40 | 40 | ||
41 | int httpRequestHasValidMethod(HttpRequest); | 41 | int httpRequestHasValidMethod(HttpRequest); |
42 | 42 | ||
43 | -#endif /* __HTTP_REQUEST_H__ */ | 43 | +#endif // __HTTP_REQUEST_H__ |
44 | 44 | ||
45 | // vim: set ts=4 sw=4: | 45 | // vim: set ts=4 sw=4: |
@@ -67,6 +67,6 @@ ssize_t httpRequestParserGetRequestLine(HttpRequestParser, char *); | @@ -67,6 +67,6 @@ ssize_t httpRequestParserGetRequestLine(HttpRequestParser, char *); | ||
67 | ssize_t httpRequestParserGetHeader(HttpRequestParser, char *); | 67 | ssize_t httpRequestParserGetHeader(HttpRequestParser, char *); |
68 | void httpRequestParserGetBody(HttpRequestParser); | 68 | void httpRequestParserGetBody(HttpRequestParser); |
69 | 69 | ||
70 | -#endif /* __HTTP_REQUEST_PARSER_H__ */ | 70 | +#endif // __HTTP_REQUEST_PARSER_H__ |
71 | 71 | ||
72 | // vim: set ts=4 sw=4: | 72 | // vim: set ts=4 sw=4: |
@@ -43,6 +43,6 @@ HttpResponse httpResponse404(); | @@ -43,6 +43,6 @@ HttpResponse httpResponse404(); | ||
43 | HttpResponse httpResponseMe(); | 43 | HttpResponse httpResponseMe(); |
44 | HttpResponse httpResponseImage(int); | 44 | HttpResponse httpResponseImage(int); |
45 | 45 | ||
46 | -#endif /* __HTTP_RESPONSE_H__ */ | 46 | +#endif // __HTTP_RESPONSE_H__ |
47 | 47 | ||
48 | // vim: set ts=4 sw=4: | 48 | // vim: set ts=4 sw=4: |
@@ -37,10 +37,10 @@ void daemonize(void) { | @@ -37,10 +37,10 @@ void daemonize(void) { | ||
37 | exit(EXIT_SUCCESS); | 37 | exit(EXIT_SUCCESS); |
38 | } | 38 | } |
39 | 39 | ||
40 | - /* make new child session leader */ | 40 | + // make new child session leader |
41 | setsid(); | 41 | setsid(); |
42 | 42 | ||
43 | - /* connect all standard streams to /dev/null */ | 43 | + // connect all standard streams to /dev/null |
44 | stderr = freopen("/dev/null", "w", stderr); | 44 | stderr = freopen("/dev/null", "w", stderr); |
45 | stdin = freopen("/dev/null", "r", stdin); | 45 | stdin = freopen("/dev/null", "r", stdin); |
46 | stdout = freopen("/dev/null", "w", stdout); | 46 | stdout = freopen("/dev/null", "w", stdout); |
@@ -48,23 +48,6 @@ httpRequestParserParse(HttpRequestParser this, int fd) | @@ -48,23 +48,6 @@ httpRequestParserParse(HttpRequestParser this, int fd) | ||
48 | } | 48 | } |
49 | 49 | ||
50 | if (NULL != this->incomplete) { | 50 | if (NULL != this->incomplete) { |
51 | - /** | ||
52 | - * i need a way to stop incomplete requests | ||
53 | - * from locking the buffer forever. | ||
54 | - * Maybe this is the position for this... | ||
55 | - * but i must carefully think about the | ||
56 | - * conditions...maybe a rewrite of the | ||
57 | - * parser is neccessary to detect a | ||
58 | - * stale request. | ||
59 | - * The problem here seems to be that i can't | ||
60 | - * say for sure if the request is stale. | ||
61 | - * This is mostly because i work linewise. | ||
62 | - * This MUST be accomplished within | ||
63 | - * request line and header reads. | ||
64 | - * As far as i see the only way it to | ||
65 | - * always empty the buffer completely after | ||
66 | - * every read and release the buffer then. | ||
67 | - */ | ||
68 | cbufSetData(this->buffer, this->incomplete, this->isize); | 51 | cbufSetData(this->buffer, this->incomplete, this->isize); |
69 | free(this->incomplete); | 52 | free(this->incomplete); |
70 | this->incomplete = NULL; | 53 | this->incomplete = NULL; |
@@ -143,7 +143,7 @@ httpResponseWriterWrite(HttpResponseWriter this, int fd) | @@ -143,7 +143,7 @@ httpResponseWriterWrite(HttpResponseWriter this, int fd) | ||
143 | /** | 143 | /** |
144 | * if the message did not have the keep-alive feature | 144 | * if the message did not have the keep-alive feature |
145 | * we don't care about further pipelined messages and | 145 | * we don't care about further pipelined messages and |
146 | - * return to the caller with a 0 indicating that the | 146 | + * return to the caller with a -1 indicating that the |
147 | * underlying connection should be closed. | 147 | * underlying connection should be closed. |
148 | */ | 148 | */ |
149 | cbufRelease(this->buffer); | 149 | cbufRelease(this->buffer); |
@@ -39,10 +39,10 @@ serverHandleAccept(Server this) | @@ -39,10 +39,10 @@ serverHandleAccept(Server this) | ||
39 | acc = socketAccept(this->sock, &remoteAddr); | 39 | acc = socketAccept(this->sock, &remoteAddr); |
40 | 40 | ||
41 | if (-1 != acc->handle) { | 41 | if (-1 != acc->handle) { |
42 | - //* save the socket handle | 42 | + // save the socket handle |
43 | (this->conns)[acc->handle].sock = acc; | 43 | (this->conns)[acc->handle].sock = acc; |
44 | 44 | ||
45 | - //* clone worker | 45 | + // clone worker |
46 | (this->conns)[acc->handle].worker = clone(this->worker); | 46 | (this->conns)[acc->handle].worker = clone(this->worker); |
47 | 47 | ||
48 | /** | 48 | /** |
@@ -27,26 +27,6 @@ | @@ -27,26 +27,6 @@ | ||
27 | #define SWAP(a, b) ((a)^=(b),(b)^=(a),(a)^=(b)) | 27 | #define SWAP(a, b) ((a)^=(b),(b)^=(a),(a)^=(b)) |
28 | 28 | ||
29 | static | 29 | static |
30 | -inline | ||
31 | -int | ||
32 | -sortEvents(const void * a, const void * b) | ||
33 | -{ | ||
34 | - return POLLFD(a)->events > POLLFD(b)->events ? | ||
35 | - -1 : POLLFD(a)->events < POLLFD(b)->events ? | ||
36 | - 1 : 0; | ||
37 | -} | ||
38 | - | ||
39 | -static | ||
40 | -inline | ||
41 | -int | ||
42 | -sortRevents(const void * a, const void * b) | ||
43 | -{ | ||
44 | - return POLLFD(a)->revents > POLLFD(b)->revents ? | ||
45 | - -1 : POLLFD(a)->revents < POLLFD(b)->revents ? | ||
46 | - 1 : 0; | ||
47 | -} | ||
48 | - | ||
49 | -static | ||
50 | int | 30 | int |
51 | serverPoll(Server this) { | 31 | serverPoll(Server this) { |
52 | int events; | 32 | int events; |
@@ -51,7 +51,7 @@ serverRun(Server this) | @@ -51,7 +51,7 @@ serverRun(Server this) | ||
51 | * What we can first do to get some processing between read/write | 51 | * What we can first do to get some processing between read/write |
52 | * cicles is to use the poll timeout. | 52 | * cicles is to use the poll timeout. |
53 | */ | 53 | */ |
54 | - while (!doShutdown) /* until error or signal */ | 54 | + while (!doShutdown) //! until error or signal |
55 | { | 55 | { |
56 | int events; | 56 | int events; |
57 | unsigned int i; | 57 | unsigned int i; |
@@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#include <signal.h> /* for signal() and signal names */ | 23 | +#include <signal.h> // for signal() and signal names |
24 | 24 | ||
25 | volatile int doShutdown; | 25 | volatile int doShutdown; |
26 | 26 |
@@ -34,27 +34,20 @@ void | @@ -34,27 +34,20 @@ void | ||
34 | ctor(void * _this, va_list * params) | 34 | ctor(void * _this, va_list * params) |
35 | { | 35 | { |
36 | Sock this = _this; | 36 | Sock this = _this; |
37 | - int reUse = 1; /* TODO: make this configurable */ | 37 | + int reUse = 1; //! \todo make this configurable |
38 | 38 | ||
39 | this->log = va_arg(* params, Logger); | 39 | this->log = va_arg(* params, Logger); |
40 | this->port = va_arg(* params, int); | 40 | this->port = va_arg(* params, int); |
41 | 41 | ||
42 | - /* Create socket for incoming connections */ | 42 | + //! Create socket for incoming connections |
43 | if (-1 == (this->handle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))) { | 43 | if (-1 == (this->handle = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP))) { |
44 | loggerLog(this->log, LOGGER_CRIT, | 44 | loggerLog(this->log, LOGGER_CRIT, |
45 | "error opening socket: %s - service terminated", | 45 | "error opening socket: %s - service terminated", |
46 | strerror(errno)); | 46 | strerror(errno)); |
47 | - //exit(EXIT_FAILURE); | ||
48 | - /** | ||
49 | - * \todo uhhhh, here we are leaking memory the socket is not | ||
50 | - * initialized correctly and no one notices... | ||
51 | - * Think about a way to prevent this. | ||
52 | - * Well maybe we notice in server.... | ||
53 | - */ | ||
54 | return; | 47 | return; |
55 | } | 48 | } |
56 | 49 | ||
57 | - /* Make the socket REUSE a TIME_WAIT socket */ | 50 | + //! Make the socket REUSE a TIME_WAIT socket |
58 | setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof (reUse)); | 51 | setsockopt(this->handle, SOL_SOCKET, SO_REUSEADDR, &reUse, sizeof (reUse)); |
59 | } | 52 | } |
60 | 53 |
@@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#include <errno.h> /* for errno */ | 23 | +#include <errno.h> // for errno |
24 | #include <unistd.h> | 24 | #include <unistd.h> |
25 | 25 | ||
26 | #include "socket.h" | 26 | #include "socket.h" |
@@ -30,10 +30,10 @@ | @@ -30,10 +30,10 @@ | ||
30 | Sock | 30 | Sock |
31 | socketAccept(Sock this, char (*remoteAddr)[16]) | 31 | socketAccept(Sock this, char (*remoteAddr)[16]) |
32 | { | 32 | { |
33 | - Sock sock; /* Socket for client */ | ||
34 | - unsigned int len; /* Length of client address data structure */ | 33 | + Sock sock; // Socket for client |
34 | + unsigned int len; // Length of client address data structure | ||
35 | 35 | ||
36 | - /* Set the size of the in-out parameter */ | 36 | + // Set the size of the in-out parameter |
37 | len = sizeof(this->addr); | 37 | len = sizeof(this->addr); |
38 | 38 | ||
39 | /** | 39 | /** |
@@ -49,7 +49,7 @@ socketAccept(Sock this, char (*remoteAddr)[16]) | @@ -49,7 +49,7 @@ socketAccept(Sock this, char (*remoteAddr)[16]) | ||
49 | * \todo change port to remote port on success | 49 | * \todo change port to remote port on success |
50 | */ | 50 | */ |
51 | 51 | ||
52 | - /* Wait for a client to connect */ | 52 | + // Wait for a client to connect |
53 | sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len); | 53 | sock->handle = accept(this->handle, (struct sockaddr *) &(sock->addr), &len); |
54 | if (-1 == sock->handle) { | 54 | if (-1 == sock->handle) { |
55 | loggerLog(this->log, LOGGER_WARNING, | 55 | loggerLog(this->log, LOGGER_WARNING, |
@@ -20,8 +20,8 @@ | @@ -20,8 +20,8 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#include <stdlib.h> /* for atoi() and exit() */ | ||
24 | -#include <errno.h> /* for errno */ | 23 | +#include <stdlib.h> // for atoi() and exit() |
24 | +#include <errno.h> // for errno | ||
25 | 25 | ||
26 | #include "socket.h" | 26 | #include "socket.h" |
27 | #include "interface/class.h" | 27 | #include "interface/class.h" |
@@ -32,8 +32,8 @@ void | @@ -32,8 +32,8 @@ void | ||
32 | socketConnect(Sock this, const char * addr) | 32 | socketConnect(Sock this, const char * addr) |
33 | { | 33 | { |
34 | inet_pton(AF_INET, addr, &((this->addr).sin_addr)); | 34 | inet_pton(AF_INET, addr, &((this->addr).sin_addr)); |
35 | - (this->addr).sin_family = AF_INET; /* Internet address family */ | ||
36 | - (this->addr).sin_port = htons(this->port); /* Local port */ | 35 | + (this->addr).sin_family = AF_INET; // Internet address family |
36 | + (this->addr).sin_port = htons(this->port); // Local port | ||
37 | 37 | ||
38 | if (-1 == connect(this->handle, (struct sockaddr*) &(this->addr), sizeof(this->addr))) { | 38 | if (-1 == connect(this->handle, (struct sockaddr*) &(this->addr), sizeof(this->addr))) { |
39 | loggerLog(this->log, LOGGER_CRIT, | 39 | loggerLog(this->log, LOGGER_CRIT, |
@@ -20,8 +20,8 @@ | @@ -20,8 +20,8 @@ | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | -#include <stdlib.h> /* for atoi() and exit() */ | ||
24 | -#include <errno.h> /* for errno */ | 23 | +#include <stdlib.h> // for atoi() and exit() |
24 | +#include <errno.h> // for errno | ||
25 | 25 | ||
26 | #include "socket.h" | 26 | #include "socket.h" |
27 | #include "interface/class.h" | 27 | #include "interface/class.h" |
@@ -31,11 +31,13 @@ | @@ -31,11 +31,13 @@ | ||
31 | void | 31 | void |
32 | socketListen(Sock this, int backlog) | 32 | socketListen(Sock this, int backlog) |
33 | { | 33 | { |
34 | - (this->addr).sin_family = AF_INET; /* Internet address family */ | ||
35 | - (this->addr).sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */ | ||
36 | - (this->addr).sin_port = htons(this->port); /* Local port */ | 34 | + (this->addr).sin_family = AF_INET; // Internet address family |
35 | + (this->addr).sin_addr.s_addr = htonl(INADDR_ANY); // Any incoming interface | ||
36 | + (this->addr).sin_port = htons(this->port); // Local port | ||
37 | 37 | ||
38 | - /* Bind to the local address */ | 38 | + /** |
39 | + * Bind to the local address | ||
40 | + */ | ||
39 | if (-1 == bind(this->handle, (struct sockaddr *) &(this->addr), sizeof(this->addr))) { | 41 | if (-1 == bind(this->handle, (struct sockaddr *) &(this->addr), sizeof(this->addr))) { |
40 | loggerLog(this->log, LOGGER_CRIT, | 42 | loggerLog(this->log, LOGGER_CRIT, |
41 | "error binding socket: %s - service terminated", | 43 | "error binding socket: %s - service terminated", |
@@ -43,7 +45,9 @@ socketListen(Sock this, int backlog) | @@ -43,7 +45,9 @@ socketListen(Sock this, int backlog) | ||
43 | exit(EXIT_FAILURE); | 45 | exit(EXIT_FAILURE); |
44 | } | 46 | } |
45 | 47 | ||
46 | - /* Mark the socket so it will listen for incoming connections */ | 48 | + /** |
49 | + * Mark the socket so it will listen for incoming connections | ||
50 | + */ | ||
47 | if (-1 == listen(this->handle, backlog)) { | 51 | if (-1 == listen(this->handle, backlog)) { |
48 | loggerLog(this->log, LOGGER_CRIT, | 52 | loggerLog(this->log, LOGGER_CRIT, |
49 | "error binding socket: %s - service terminated", | 53 | "error binding socket: %s - service terminated", |
Please
register
or
login
to post a comment