mirror of
https://github.com/sigmasternchen/CFloor
synced 2025-03-15 20:28:56 +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");
|
debug("networking: sending headers");
|
||||||
|
|
||||||
struct connection* connection = (struct connection*) request->_private;
|
struct connection* connection = (struct connection*) request->_private;
|
||||||
|
|
||||||
debug("before headers: %d", connection->currentHeaderLength);
|
|
||||||
|
|
||||||
struct headers defaultHeaders = networkingConfig.defaultHeaders;
|
struct headers defaultHeaders = networkingConfig.defaultHeaders;
|
||||||
|
|
||||||
|
@ -728,6 +726,7 @@ void dataHandler(int signo) {
|
||||||
bool handlerStarted = false;
|
bool handlerStarted = false;
|
||||||
char last = 0;
|
char last = 0;
|
||||||
if (connection->currentHeaderLength > 0) {
|
if (connection->currentHeaderLength > 0) {
|
||||||
|
debug("%d, %x", connection->currentHeaderLength, connection->currentHeader);
|
||||||
last = connection->currentHeader[connection->currentHeaderLength - 1];
|
last = connection->currentHeader[connection->currentHeaderLength - 1];
|
||||||
}
|
}
|
||||||
while((tmp = read(connection->readfd, &c, 1)) > 0) {
|
while((tmp = read(connection->readfd, &c, 1)) > 0) {
|
||||||
|
@ -741,17 +740,11 @@ void dataHandler(int signo) {
|
||||||
connection->currentHeaderLength--;
|
connection->currentHeaderLength--;
|
||||||
connection->currentHeader[connection->currentHeaderLength] = '\0';
|
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);
|
updateTiming(connection, false);
|
||||||
|
|
||||||
if (connection->metaData.path == NULL) {
|
if (connection->metaData.path == NULL) {
|
||||||
// protocol line
|
// protocol line
|
||||||
|
|
||||||
// tmp is local and can't cause problems after break
|
|
||||||
tmp = headers_metadata(&(connection->metaData), connection->currentHeader);
|
tmp = headers_metadata(&(connection->metaData), connection->currentHeader);
|
||||||
if (tmp == HEADERS_ALLOC_ERROR) {
|
if (tmp == HEADERS_ALLOC_ERROR) {
|
||||||
error("networking: couldn't allocate memory for meta data: %s", strerror(errno));
|
error("networking: couldn't allocate memory for meta data: %s", strerror(errno));
|
||||||
|
@ -766,8 +759,7 @@ void dataHandler(int signo) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// header line
|
// header line
|
||||||
|
|
||||||
// tmp is local and can't cause problems after break
|
|
||||||
tmp = headers_parse(&(connection->headers), connection->currentHeader, connection->currentHeaderLength);
|
tmp = headers_parse(&(connection->headers), connection->currentHeader, connection->currentHeaderLength);
|
||||||
if (tmp == HEADERS_END) {
|
if (tmp == HEADERS_END) {
|
||||||
connection->currentHeaderLength = 0;
|
connection->currentHeaderLength = 0;
|
||||||
|
@ -804,7 +796,6 @@ void dataHandler(int signo) {
|
||||||
startRequestHandler(connection);
|
startRequestHandler(connection);
|
||||||
|
|
||||||
handlerStarted = true;
|
handlerStarted = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else if (tmp == HEADERS_ALLOC_ERROR) {
|
} else if (tmp == HEADERS_ALLOC_ERROR) {
|
||||||
error("networking: couldn't allocate memory for header: %s", strerror(errno));
|
error("networking: couldn't allocate memory for header: %s", strerror(errno));
|
||||||
|
@ -847,30 +838,35 @@ void dataHandler(int signo) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp < 0) {
|
if (!dropConnection) {
|
||||||
switch(errno) {
|
if (tmp < 0) {
|
||||||
case EAGAIN:
|
switch(errno) {
|
||||||
// no more data to be ready
|
case EAGAIN:
|
||||||
// ignore this error
|
// no more data to be ready
|
||||||
break;
|
// ignore this error
|
||||||
default:
|
break;
|
||||||
dropConnection = true;
|
default:
|
||||||
error("networking: error reading socket: %s", strerror(errno));
|
dropConnection = true;
|
||||||
break;
|
error("networking: error reading socket: %s", strerror(errno));
|
||||||
}
|
break;
|
||||||
} else if (tmp == 0) {
|
}
|
||||||
debug("networking: connection ended");
|
} else if (tmp == 0) {
|
||||||
|
debug("networking: connection ended");
|
||||||
|
|
||||||
buffer[length] = '\0';
|
buffer[length] = '\0';
|
||||||
debug("networking: buffer: '%s'", buffer);
|
debug("networking: buffer: '%s'", buffer);
|
||||||
dropConnection = true;
|
|
||||||
}
|
|
||||||
if (length > 0) {
|
|
||||||
if (dumpHeaderBuffer(&(buffer[0]), length, connection) < 0) {
|
|
||||||
dropConnection = true;
|
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 (dropConnection) {
|
||||||
if (connection->currentHeader != NULL)
|
if (connection->currentHeader != NULL)
|
||||||
free(connection->currentHeader);
|
free(connection->currentHeader);
|
||||||
|
|
Loading…
Reference in a new issue