diff --git a/mongoose.c b/mongoose.c index 021b4ae4..a6760062 100644 --- a/mongoose.c +++ b/mongoose.c @@ -960,10 +960,11 @@ static void printdirentry(struct mg_connection *c, struct mg_http_message *hm, strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime(&stp->st_mtime)); // mg_escape(file_name, path, sizeof(path)); // href = mg_url_encode(mg_mk_str(file_name)); - mg_http_printf_chunk( - c, - "%s%s%s%s", - (int) hm->uri.len, hm->uri.ptr, name, slash, name, slash, mod, size); + mg_http_printf_chunk(c, + " %s%s" + "%s%s\n", + (int) hm->uri.len, hm->uri.ptr, name, slash, name, slash, + mod, size); // free((void *) href.p); } @@ -983,7 +984,7 @@ static void listdir(struct mg_connection *c, struct mg_http_message *hm, "font-family: monospace; }" "

Index of %.*s

" "" - "", + "\n", (int) hm->uri.len, hm->uri.ptr, (int) hm->uri.len, hm->uri.ptr); while ((dp = readdir(dirp)) != NULL) { struct stat st; @@ -1000,7 +1001,7 @@ static void listdir(struct mg_connection *c, struct mg_http_message *hm, mg_http_printf_chunk( c, "" - "
NameModifiedSize



Mongoose v.%s
", + "
Mongoose v.%s
\n", MG_VERSION); mg_http_write_chunk(c, "", 0); } else { @@ -1244,6 +1245,7 @@ void mg_iobuf_free(struct mg_iobuf *io) { static void mg_log_stdout(const void *buf, int len, void *userdata) { (void) userdata; fwrite(buf, 1, len, stdout); + fflush(stdout); } static const char *s_spec = "2"; @@ -1251,7 +1253,7 @@ static void (*s_fn)(const void *, int, void *) = mg_log_stdout; static void *s_fn_param = NULL; void mg_log_set(const char *spec) { - LOG(LL_INFO, ("Setting log level to %s", spec)); + LOG(LL_DEBUG, ("Setting log level to %s", spec)); s_spec = spec; } @@ -2460,6 +2462,9 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url, #if defined(_WIN32) #define MG_SOCK_ERRNO WSAGetLastError() #define FD(C_) ((SOCKET)(C_)->fd) +#ifndef SO_EXCLUSIVEADDRUSE +#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR)) +#endif #elif MG_ARCH == MG_ARCH_FREERTOS #define MG_SOCK_ERRNO errno typedef Socket_t SOCKET; @@ -2652,9 +2657,10 @@ SOCKET mg_open_listener(const char *url) { #endif #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE) // "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" + //! setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on)) + //! && !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on, sizeof(on)) && - !setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on)) && #endif bind(fd, &usa.sa, slen) == 0 && // NOTE(lsm): FreeRTOS uses backlog value as a connection limit diff --git a/mongoose.h b/mongoose.h index 78744d12..c5566732 100644 --- a/mongoose.h +++ b/mongoose.h @@ -280,7 +280,7 @@ typedef int socklen_t; #if MG_ENABLE_LWIP #define MG_ENABLE_SOCKET 0 -#else +#elif !defined(MG_ENABLE_SOCKET) #define MG_ENABLE_SOCKET 1 #endif diff --git a/src/config.h b/src/config.h index a83a55b2..d01120ac 100644 --- a/src/config.h +++ b/src/config.h @@ -6,7 +6,7 @@ #if MG_ENABLE_LWIP #define MG_ENABLE_SOCKET 0 -#else +#elif !defined(MG_ENABLE_SOCKET) #define MG_ENABLE_SOCKET 1 #endif diff --git a/src/http.c b/src/http.c index 2081c320..9870a577 100644 --- a/src/http.c +++ b/src/http.c @@ -546,10 +546,11 @@ static void printdirentry(struct mg_connection *c, struct mg_http_message *hm, strftime(mod, sizeof(mod), "%d-%b-%Y %H:%M", localtime(&stp->st_mtime)); // mg_escape(file_name, path, sizeof(path)); // href = mg_url_encode(mg_mk_str(file_name)); - mg_http_printf_chunk( - c, - "%s%s%s%s", - (int) hm->uri.len, hm->uri.ptr, name, slash, name, slash, mod, size); + mg_http_printf_chunk(c, + " %s%s" + "%s%s\n", + (int) hm->uri.len, hm->uri.ptr, name, slash, name, slash, + mod, size); // free((void *) href.p); } @@ -569,7 +570,7 @@ static void listdir(struct mg_connection *c, struct mg_http_message *hm, "font-family: monospace; }" "

Index of %.*s

" "" - "", + "\n", (int) hm->uri.len, hm->uri.ptr, (int) hm->uri.len, hm->uri.ptr); while ((dp = readdir(dirp)) != NULL) { struct stat st; @@ -586,7 +587,7 @@ static void listdir(struct mg_connection *c, struct mg_http_message *hm, mg_http_printf_chunk( c, "" - "
NameModifiedSize



Mongoose v.%s
", + "
Mongoose v.%s
\n", MG_VERSION); mg_http_write_chunk(c, "", 0); } else { diff --git a/src/log.c b/src/log.c index 5ff2e4ae..78c4be08 100644 --- a/src/log.c +++ b/src/log.c @@ -7,6 +7,7 @@ static void mg_log_stdout(const void *buf, int len, void *userdata) { (void) userdata; fwrite(buf, 1, len, stdout); + fflush(stdout); } static const char *s_spec = "2"; @@ -14,7 +15,7 @@ static void (*s_fn)(const void *, int, void *) = mg_log_stdout; static void *s_fn_param = NULL; void mg_log_set(const char *spec) { - LOG(LL_INFO, ("Setting log level to %s", spec)); + LOG(LL_DEBUG, ("Setting log level to %s", spec)); s_spec = spec; } diff --git a/src/sock.c b/src/sock.c index 3369c63c..d7c83f1e 100644 --- a/src/sock.c +++ b/src/sock.c @@ -13,6 +13,9 @@ #if defined(_WIN32) #define MG_SOCK_ERRNO WSAGetLastError() #define FD(C_) ((SOCKET)(C_)->fd) +#ifndef SO_EXCLUSIVEADDRUSE +#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR)) +#endif #elif MG_ARCH == MG_ARCH_FREERTOS #define MG_SOCK_ERRNO errno typedef Socket_t SOCKET; @@ -205,9 +208,10 @@ SOCKET mg_open_listener(const char *url) { #endif #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE) // "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" + //! setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on)) + //! && !setsockopt(fd, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *) &on, sizeof(on)) && - !setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on)) && #endif bind(fd, &usa.sa, slen) == 0 && // NOTE(lsm): FreeRTOS uses backlog value as a connection limit