Skip to content

Commit eb26348

Browse files
committed
Close #5 - Shutting down the server should now free all resources
1 parent 929e0f8 commit eb26348

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Diff for: https/HTTPSServer.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,25 @@ bool HTTPSServer::isRunning() {
7979
void HTTPSServer::stop() {
8080

8181
if (_running) {
82+
// Set the flag that the server is stopped
83+
_running = false;
84+
85+
// Clean up the connections
86+
for(int i = 0; i < _maxConnections; i++) {
87+
if (_connections[i] != NULL) {
88+
_connections[i]->closeConnection();
89+
delete _connections[i];
90+
}
91+
}
92+
93+
// Close the actual server socket
8294
close(_socket);
8395
_socket = -1;
8496

85-
// Reset the context
97+
// Tear down the SSL context
8698
SSL_CTX_free(_sslctx);
8799
_sslctx = NULL;
88100
}
89-
90-
// Clean up the connections
91-
for(int i = 0; i < _maxConnections; i++) {
92-
if (_connections[i] != NULL) {
93-
94-
}
95-
}
96101
}
97102

98103
/**
@@ -110,6 +115,9 @@ void HTTPSServer::setDefaultHeader(std::string name, std::string value) {
110115
*/
111116
void HTTPSServer::loop() {
112117

118+
// Only handle requests if the server is still running
119+
if(!_running) return;
120+
113121
// Step 1: Process existing connections
114122
// Process open connections and store the index of a free connection
115123
// (we might use that later on)

0 commit comments

Comments
 (0)