- nhttpd: use PORT-defines from yconfig.h instead of "hardcoded" ports

Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
svenhoefer
2017-09-06 15:22:43 +02:00
committed by Thilo Graf
parent 4097d07942
commit 0738d2af53
2 changed files with 8 additions and 6 deletions

View File

@@ -88,6 +88,7 @@
#undef HTTPD_NAME #undef HTTPD_NAME
#define HTTPD_NAME "nhttpd" #define HTTPD_NAME "nhttpd"
#define HTTPD_STANDARD_PORT 80 #define HTTPD_STANDARD_PORT 80
#define HTTPD_FALLBACK_PORT 8080
#define HTTPD_MAX_CONNECTIONS 50 #define HTTPD_MAX_CONNECTIONS 50
#define HTTPD_REQUEST_LOG "/tmp/httpd_log" #define HTTPD_REQUEST_LOG "/tmp/httpd_log"
#define SSL_PEMFILE HTTPD_CONFIGDIR "/server.pem" #define SSL_PEMFILE HTTPD_CONFIGDIR "/server.pem"

View File

@@ -51,7 +51,7 @@ CWebserver::CWebserver() {
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
#endif #endif
port = 80; port = HTTPD_STANDARD_PORT;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -118,14 +118,15 @@ CWebserver::~CWebserver() {
bool CWebserver::run(void) { bool CWebserver::run(void) {
set_threadname("ywebsrv::run"); set_threadname("ywebsrv::run");
if (!listenSocket.listen(port, HTTPD_MAX_CONNECTIONS)) { if (!listenSocket.listen(port, HTTPD_MAX_CONNECTIONS)) {
if (port != 80) { if (port != HTTPD_STANDARD_PORT) {
fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d Abort.\n", port); // WebsiteMain.port in nhttpd.conf is changed by user
fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d. Abort.\n", port);
return false; return false;
} }
fprintf(stderr, "[yhttpd] cannot bind and listen on port 80, retrying on port 8080.\n"); fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d. Retrying port %d.\n", HTTPD_STANDARD_PORT, HTTPD_FALLBACK_PORT);
port = 8080; port = HTTPD_FALLBACK_PORT;
if (!listenSocket.listen(port, HTTPD_MAX_CONNECTIONS)) { if (!listenSocket.listen(port, HTTPD_MAX_CONNECTIONS)) {
fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d Abort.\n", port); fprintf(stderr, "[yhttpd] Socket cannot bind and listen on port %d. Abort.\n", HTTPD_FALLBACK_PORT);
return false; return false;
} }
} }