Merge pull request #2208 from cesanta/fixwbind

fix bind issue in W
This commit is contained in:
Sergio R. Caprile 2023-05-22 19:46:42 -03:00 committed by GitHub
commit 81b05b9de4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -4554,8 +4554,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
(char *) &on, sizeof(on))) != 0) {
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
MG_ERROR(("setsockopt(SO_EXCLUSIVEADDRUSE): %d %d", on, MG_SOCK_ERR(rc)));
#endif
#if defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
#elif defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
sizeof(on))) != 0) {
// 1. SO_REUSEADDR semantics on UNIX and Windows is different. On

View File

@ -198,8 +198,7 @@ bool mg_open_listener(struct mg_connection *c, const char *url) {
(char *) &on, sizeof(on))) != 0) {
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
MG_ERROR(("setsockopt(SO_EXCLUSIVEADDRUSE): %d %d", on, MG_SOCK_ERR(rc)));
#endif
#if defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
#elif defined(SO_REUSEADDR) && (!defined(LWIP_SOCKET) || SO_REUSE)
} else if ((rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on,
sizeof(on))) != 0) {
// 1. SO_REUSEADDR semantics on UNIX and Windows is different. On

View File

@ -2137,10 +2137,12 @@ static void eh5(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
static void test_http_chunked_case(mg_event_handler_t s, mg_event_handler_t c,
int req_count, const char *expected) {
char url[100];
struct mg_mgr mgr;
const char *url = "http://127.0.0.1:12344";
uint32_t i, crc = 0, expected_crc = mg_crc32(0, expected, strlen(expected));
struct mg_connection *conn;
static uint16_t port = 32344; // To prevent bind errors on Windows
mg_snprintf(url, sizeof(url), "http://127.0.0.1:%d", port++);
mg_mgr_init(&mgr);
mg_http_listen(&mgr, url, s, NULL);
conn = mg_http_connect(&mgr, url, c, &crc);
@ -2799,7 +2801,7 @@ static void test_poll(void) {
int count = 0, i;
struct mg_mgr mgr;
mg_mgr_init(&mgr);
mg_http_listen(&mgr, "http://127.0.0.1:12346", ph, &count);
mg_http_listen(&mgr, "http://127.0.0.1:42346", ph, &count); // To prevent bind errors on Windows
for (i = 0; i < 10; i++) mg_mgr_poll(&mgr, 0);
ASSERT(count == 10);
mg_mgr_free(&mgr);