-
Notifications
You must be signed in to change notification settings - Fork 192
Description
Prerequisites
- [X ] Put an X between the brackets on this line if you have checked that your issue isn't already filed: https://github.com/search?l=&q=repo%3Aetr%2Flibhttpserver&type=Issues
Description
I'm trying to play with the library by creating a sample program that has an infinite while loop in its main function. The main goal would be to create a new webserver with the params passed on user input. Unfortunately, it seems that the webserver is not starting in this loop.
Steps to Reproduce
Sample code used :
#include <iostream>
#include <string>
#include <httpserver.hpp>
class hello_world_resource : public httpserver::http_resource {
public:
std::shared_ptr<httpserver::http_response> render(const httpserver::http_request&) {
return std::shared_ptr<httpserver::http_response>(new httpserver::string_response("Hello, World!"));
}
};
int main(){
while(1){
std::string input;
std::cout << "create_webserver> ";
std::getline(std::cin, input);
//parsing user input.... (port, endpoint)
httpserver::webserver result = httpserver::create_webserver(port);
hello_world_resource hwr;
result.register_resource(endpoint, &hwr);
result.start(false);
}
}
}Expected behavior: the webserver starts correctly, and is accessible on endpoint, address and port specified by user input.
Actual behavior: The webserver doesn't start.
Versions
- OS version : Linux devserver 5.15.0-76-generic Do not call abort, throw an exception instead #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
- libhttpserver version : compiled (latest available)
Additional Information
I've noticed that the code provided above works if I declare the webserver object before the while loop (the rest of the code can be executed in the while loop without any problem). However, by doing so, the program loses its interest. I don't know whether this is a bug or an inherent feature of the library, and I'd be interested in possible solutions.