mirror of
https://github.com/sigmasternchen/CFloor
synced 2025-03-15 04:18:55 +00:00
made code more readable
This commit is contained in:
parent
bd4072c335
commit
0dcb33fe68
1 changed files with 28 additions and 32 deletions
|
@ -471,8 +471,6 @@ int sendHeader(int statusCode, struct headers* headers, struct request* request)
|
|||
debug("networking: sending headers");
|
||||
|
||||
struct connection* connection = (struct connection*) request->_private;
|
||||
|
||||
debug("before headers: %d", connection->currentHeaderLength);
|
||||
|
||||
struct headers defaultHeaders = networkingConfig.defaultHeaders;
|
||||
|
||||
|
@ -728,6 +726,7 @@ void dataHandler(int signo) {
|
|||
bool handlerStarted = false;
|
||||
char last = 0;
|
||||
if (connection->currentHeaderLength > 0) {
|
||||
debug("%d, %x", connection->currentHeaderLength, connection->currentHeader);
|
||||
last = connection->currentHeader[connection->currentHeaderLength - 1];
|
||||
}
|
||||
while((tmp = read(connection->readfd, &c, 1)) > 0) {
|
||||
|
@ -741,17 +740,11 @@ void dataHandler(int signo) {
|
|||
connection->currentHeaderLength--;
|
||||
connection->currentHeader[connection->currentHeaderLength] = '\0';
|
||||
|
||||
// tmp is local to this block
|
||||
// shouldn't overwrite the return value of read
|
||||
// TODO: find better variable names
|
||||
int tmp;
|
||||
|
||||
updateTiming(connection, false);
|
||||
|
||||
if (connection->metaData.path == NULL) {
|
||||
// protocol line
|
||||
|
||||
// tmp is local and can't cause problems after break
|
||||
|
||||
tmp = headers_metadata(&(connection->metaData), connection->currentHeader);
|
||||
if (tmp == HEADERS_ALLOC_ERROR) {
|
||||
error("networking: couldn't allocate memory for meta data: %s", strerror(errno));
|
||||
|
@ -766,8 +759,7 @@ void dataHandler(int signo) {
|
|||
}
|
||||
} else {
|
||||
// header line
|
||||
|
||||
// tmp is local and can't cause problems after break
|
||||
|
||||
tmp = headers_parse(&(connection->headers), connection->currentHeader, connection->currentHeaderLength);
|
||||
if (tmp == HEADERS_END) {
|
||||
connection->currentHeaderLength = 0;
|
||||
|
@ -804,7 +796,6 @@ void dataHandler(int signo) {
|
|||
startRequestHandler(connection);
|
||||
|
||||
handlerStarted = true;
|
||||
|
||||
break;
|
||||
} else if (tmp == HEADERS_ALLOC_ERROR) {
|
||||
error("networking: couldn't allocate memory for header: %s", strerror(errno));
|
||||
|
@ -847,30 +838,35 @@ void dataHandler(int signo) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (tmp < 0) {
|
||||
switch(errno) {
|
||||
case EAGAIN:
|
||||
// no more data to be ready
|
||||
// ignore this error
|
||||
break;
|
||||
default:
|
||||
dropConnection = true;
|
||||
error("networking: error reading socket: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
} else if (tmp == 0) {
|
||||
debug("networking: connection ended");
|
||||
if (!dropConnection) {
|
||||
if (tmp < 0) {
|
||||
switch(errno) {
|
||||
case EAGAIN:
|
||||
// no more data to be ready
|
||||
// ignore this error
|
||||
break;
|
||||
default:
|
||||
dropConnection = true;
|
||||
error("networking: error reading socket: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
} else if (tmp == 0) {
|
||||
debug("networking: connection ended");
|
||||
|
||||
buffer[length] = '\0';
|
||||
debug("networking: buffer: '%s'", buffer);
|
||||
dropConnection = true;
|
||||
}
|
||||
if (length > 0) {
|
||||
if (dumpHeaderBuffer(&(buffer[0]), length, connection) < 0) {
|
||||
buffer[length] = '\0';
|
||||
debug("networking: buffer: '%s'", buffer);
|
||||
dropConnection = true;
|
||||
}
|
||||
if (length > 0) {
|
||||
if (dumpHeaderBuffer(&(buffer[0]), length, connection) < 0) {
|
||||
dropConnection = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// doesn't work as an else branch
|
||||
// if the connection ends (tmp == 0)
|
||||
// the connection has to be dropped to free resources before the timeout
|
||||
if (dropConnection) {
|
||||
if (connection->currentHeader != NULL)
|
||||
free(connection->currentHeader);
|
||||
|
|
Loading…
Reference in a new issue