mirror of
https://github.com/sigmasternchen/CFloor
synced 2025-03-15 20:28:56 +00:00
restructured cleanup
This commit is contained in:
parent
91ede87e8c
commit
d183fdb3ad
1 changed files with 21 additions and 15 deletions
|
@ -103,10 +103,22 @@ void cleanup() {
|
||||||
|
|
||||||
freed++;
|
freed++;
|
||||||
|
|
||||||
|
if (connection->threads.request != PTHREAD_NULL) {
|
||||||
|
pthread_cancel(connection->threads.request);
|
||||||
|
pthread_join(connection->threads.request, NULL);
|
||||||
|
}
|
||||||
|
if (connection->threads.response != PTHREAD_NULL) {
|
||||||
|
pthread_cancel(connection->threads.response);
|
||||||
|
pthread_join(connection->threads.response, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SSL_SUPPORT
|
#ifdef SSL_SUPPORT
|
||||||
if (connection->sslConnection != NULL)
|
if (connection->sslConnection != NULL)
|
||||||
ssl_closeConnection(connection->sslConnection);
|
ssl_closeConnection(connection->sslConnection);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
close(connection->readfd);
|
||||||
|
close(connection->writefd);
|
||||||
|
|
||||||
if (connection->metaData.path != NULL)
|
if (connection->metaData.path != NULL)
|
||||||
free(connection->metaData.path);
|
free(connection->metaData.path);
|
||||||
|
@ -119,17 +131,6 @@ void cleanup() {
|
||||||
|
|
||||||
headers_free(&(connection->headers));
|
headers_free(&(connection->headers));
|
||||||
|
|
||||||
close(connection->readfd);
|
|
||||||
close(connection->writefd);
|
|
||||||
|
|
||||||
if (connection->threads.request != PTHREAD_NULL) {
|
|
||||||
pthread_cancel(connection->threads.request);
|
|
||||||
pthread_join(connection->threads.request, NULL);
|
|
||||||
}
|
|
||||||
if (connection->threads.response != PTHREAD_NULL) {
|
|
||||||
pthread_cancel(connection->threads.response);
|
|
||||||
pthread_join(connection->threads.response, NULL);
|
|
||||||
}
|
|
||||||
if (connection->peer.name != NULL)
|
if (connection->peer.name != NULL)
|
||||||
free(connection->peer.name);
|
free(connection->peer.name);
|
||||||
|
|
||||||
|
@ -234,7 +235,7 @@ static inline void stopThread(pthread_t self, pthread_t* thread, bool force) {
|
||||||
void safeEndConnection(struct connection* connection, bool force) {
|
void safeEndConnection(struct connection* connection, bool force) {
|
||||||
pthread_t self = pthread_self();
|
pthread_t self = pthread_self();
|
||||||
|
|
||||||
debug("networking: safely shuting down the connection. %d", force);
|
debug("networking: safely shuting down the connection%s.", force ? " (forced)" : "");
|
||||||
|
|
||||||
stopThread(self, &(connection->threads.request), true);
|
stopThread(self, &(connection->threads.request), true);
|
||||||
stopThread(self, &(connection->threads.response), force);
|
stopThread(self, &(connection->threads.response), force);
|
||||||
|
@ -260,9 +261,15 @@ int sendHeader(int statusCode, struct headers* headers, struct request* request)
|
||||||
struct connection* connection = (struct connection*) request->_private;
|
struct connection* connection = (struct connection*) request->_private;
|
||||||
int fd = connection->writefd;
|
int fd = connection->writefd;
|
||||||
|
|
||||||
FILE* stream = fdopen(dup(fd), "w");
|
int tmp = dup(fd);
|
||||||
|
if (tmp < 0) {
|
||||||
|
error("networking: sendHeader: dup: %s", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE* stream = fdopen(tmp, "w");
|
||||||
if (stream == NULL) {
|
if (stream == NULL) {
|
||||||
error("networking: Couldn't send header: %s", strerror(errno));
|
error("networking: sendHeader: fdopen: %s", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +385,6 @@ void dataHandler(int signo) {
|
||||||
debug("networking: data handler got called.");
|
debug("networking: data handler got called.");
|
||||||
|
|
||||||
for(link_t* link = linked_first(&connectionList); link != NULL; link = linked_next(link)) {
|
for(link_t* link = linked_first(&connectionList); link != NULL; link = linked_next(link)) {
|
||||||
debug("networking: connection %p", link);
|
|
||||||
struct connection* connection = link->data;
|
struct connection* connection = link->data;
|
||||||
|
|
||||||
pthread_mutex_lock(&(connection->lock));
|
pthread_mutex_lock(&(connection->lock));
|
||||||
|
|
Loading…
Reference in a new issue