mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-13 17:00:19 +00:00
Eliminate explicit _WIN32 checks
This commit is contained in:
1 parent
3e8e2ab513
commit
3e085ccbaa
4 files changed
+22
-22
No files matched your search
+11
-11
@@ -756,7 +756,7 @@ static int p_stat(const char *path, size_t *size, time_t *mtime) {
|
|||||||
LOG(LL_ERROR, ("stat() API is not supported. %p %p %p", path, size, mtime));
|
LOG(LL_ERROR, ("stat() API is not supported. %p %p %p", path, size, mtime));
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
#if defined(_WIN32)
|
#if MG_ARCH == MG_ARCH_WIN32
|
||||||
struct _stati64 st;
|
struct _stati64 st;
|
||||||
wchar_t tmp[PATH_MAX];
|
wchar_t tmp[PATH_MAX];
|
||||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
||||||
@@ -771,7 +771,7 @@ static int p_stat(const char *path, size_t *size, time_t *mtime) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if MG_ARCH == MG_ARCH_WIN32
|
||||||
struct dirent {
|
struct dirent {
|
||||||
char d_name[MAX_PATH];
|
char d_name[MAX_PATH];
|
||||||
};
|
};
|
||||||
@@ -898,7 +898,7 @@ static void p_list(const char *dir, void (*fn)(const char *, void *),
|
|||||||
|
|
||||||
static void *p_open(const char *path, int flags) {
|
static void *p_open(const char *path, int flags) {
|
||||||
const char *mode = flags == MG_FS_READ ? "rb" : "a+b";
|
const char *mode = flags == MG_FS_READ ? "rb" : "a+b";
|
||||||
#ifdef _WIN32
|
#if MG_ARCH == MG_ARCH_WIN32
|
||||||
wchar_t b1[PATH_MAX], b2[10];
|
wchar_t b1[PATH_MAX], b2[10];
|
||||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, b1, sizeof(b1) / sizeof(b1[0]));
|
MultiByteToWideChar(CP_UTF8, 0, path, -1, b1, sizeof(b1) / sizeof(b1[0]));
|
||||||
MultiByteToWideChar(CP_UTF8, 0, mode, -1, b2, sizeof(b2) / sizeof(b2[0]));
|
MultiByteToWideChar(CP_UTF8, 0, mode, -1, b2, sizeof(b2) / sizeof(b2[0]));
|
||||||
@@ -2741,7 +2741,7 @@ void mg_mgr_free(struct mg_mgr *mgr) {
|
|||||||
|
|
||||||
void mg_mgr_init(struct mg_mgr *mgr) {
|
void mg_mgr_init(struct mg_mgr *mgr) {
|
||||||
memset(mgr, 0, sizeof(*mgr));
|
memset(mgr, 0, sizeof(*mgr));
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
// clang-format off
|
// clang-format off
|
||||||
{ WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); }
|
{ WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); }
|
||||||
// clang-format on
|
// clang-format on
|
||||||
@@ -3105,7 +3105,7 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url,
|
|||||||
|
|
||||||
|
|
||||||
#if MG_ENABLE_SOCKET
|
#if MG_ENABLE_SOCKET
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
#define MG_SOCK_ERRNO WSAGetLastError()
|
#define MG_SOCK_ERRNO WSAGetLastError()
|
||||||
#ifndef SO_EXCLUSIVEADDRUSE
|
#ifndef SO_EXCLUSIVEADDRUSE
|
||||||
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
||||||
@@ -3177,7 +3177,7 @@ static bool mg_sock_would_block(void) {
|
|||||||
#ifndef WINCE
|
#ifndef WINCE
|
||||||
|| err == EAGAIN || err == EINTR
|
|| err == EAGAIN || err == EINTR
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
|| err == WSAEINTR || err == WSAEWOULDBLOCK
|
|| err == WSAEINTR || err == WSAEWOULDBLOCK
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
@@ -3271,7 +3271,7 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mg_set_non_blocking_mode(SOCKET fd) {
|
static void mg_set_non_blocking_mode(SOCKET fd) {
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
unsigned long on = 1;
|
unsigned long on = 1;
|
||||||
ioctlsocket(fd, FIONBIO, &on);
|
ioctlsocket(fd, FIONBIO, &on);
|
||||||
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||||
@@ -3304,7 +3304,7 @@ static SOCKET mg_open_listener(const char *url, struct mg_addr *addr) {
|
|||||||
(void) on;
|
(void) on;
|
||||||
|
|
||||||
if ((fd = socket(af, type, proto)) != INVALID_SOCKET &&
|
if ((fd = socket(af, type, proto)) != INVALID_SOCKET &&
|
||||||
#if (!defined(_WIN32) || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
#if (MG_ARCH != MG_ARCH_WIN32 || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
||||||
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
||||||
// 1. SO_RESUSEADDR is not enabled on Windows because the semantics of
|
// 1. SO_RESUSEADDR is not enabled on Windows because the semantics of
|
||||||
// SO_REUSEADDR on UNIX and Windows is different. On Windows,
|
// SO_REUSEADDR on UNIX and Windows is different. On Windows,
|
||||||
@@ -3319,7 +3319,7 @@ static SOCKET mg_open_listener(const char *url, struct mg_addr *addr) {
|
|||||||
// but won't work! (setsockopt will return EINVAL)
|
// but won't work! (setsockopt will return EINVAL)
|
||||||
!setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) &&
|
!setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) &&
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
||||||
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
||||||
//! setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on))
|
//! setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on))
|
||||||
//! &&
|
//! &&
|
||||||
@@ -3430,7 +3430,7 @@ static void setsockopts(struct mg_connection *c) {
|
|||||||
int idle = 60;
|
int idle = 60;
|
||||||
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
|
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_WIN32) && !defined(__QNX__)
|
#if MG_ARCH != MG_ARCH_WIN32 && !defined(__QNX__)
|
||||||
{
|
{
|
||||||
int cnt = 3, intvl = 20;
|
int cnt = 3, intvl = 20;
|
||||||
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
|
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
|
||||||
@@ -3499,7 +3499,7 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
|||||||
if (MG_SOCK_ERRNO != EAGAIN)
|
if (MG_SOCK_ERRNO != EAGAIN)
|
||||||
#endif
|
#endif
|
||||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||||
#if (!defined(_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP))
|
#if ((MG_ARCH != MG_ARCH_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP))
|
||||||
} else if ((long) fd >= FD_SETSIZE) {
|
} else if ((long) fd >= FD_SETSIZE) {
|
||||||
LOG(LL_ERROR, ("%ld > %ld", (long) fd, (long) FD_SETSIZE));
|
LOG(LL_ERROR, ("%ld > %ld", (long) fd, (long) FD_SETSIZE));
|
||||||
closesocket(fd);
|
closesocket(fd);
|
||||||
|
|||||||
+3
-3
@@ -15,7 +15,7 @@ static int p_stat(const char *path, size_t *size, time_t *mtime) {
|
|||||||
LOG(LL_ERROR, ("stat() API is not supported. %p %p %p", path, size, mtime));
|
LOG(LL_ERROR, ("stat() API is not supported. %p %p %p", path, size, mtime));
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
#if defined(_WIN32)
|
#if MG_ARCH == MG_ARCH_WIN32
|
||||||
struct _stati64 st;
|
struct _stati64 st;
|
||||||
wchar_t tmp[PATH_MAX];
|
wchar_t tmp[PATH_MAX];
|
||||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
||||||
@@ -30,7 +30,7 @@ static int p_stat(const char *path, size_t *size, time_t *mtime) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if MG_ARCH == MG_ARCH_WIN32
|
||||||
struct dirent {
|
struct dirent {
|
||||||
char d_name[MAX_PATH];
|
char d_name[MAX_PATH];
|
||||||
};
|
};
|
||||||
@@ -157,7 +157,7 @@ static void p_list(const char *dir, void (*fn)(const char *, void *),
|
|||||||
|
|
||||||
static void *p_open(const char *path, int flags) {
|
static void *p_open(const char *path, int flags) {
|
||||||
const char *mode = flags == MG_FS_READ ? "rb" : "a+b";
|
const char *mode = flags == MG_FS_READ ? "rb" : "a+b";
|
||||||
#ifdef _WIN32
|
#if MG_ARCH == MG_ARCH_WIN32
|
||||||
wchar_t b1[PATH_MAX], b2[10];
|
wchar_t b1[PATH_MAX], b2[10];
|
||||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, b1, sizeof(b1) / sizeof(b1[0]));
|
MultiByteToWideChar(CP_UTF8, 0, path, -1, b1, sizeof(b1) / sizeof(b1[0]));
|
||||||
MultiByteToWideChar(CP_UTF8, 0, mode, -1, b2, sizeof(b2) / sizeof(b2[0]));
|
MultiByteToWideChar(CP_UTF8, 0, mode, -1, b2, sizeof(b2) / sizeof(b2[0]));
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ void mg_mgr_free(struct mg_mgr *mgr) {
|
|||||||
|
|
||||||
void mg_mgr_init(struct mg_mgr *mgr) {
|
void mg_mgr_init(struct mg_mgr *mgr) {
|
||||||
memset(mgr, 0, sizeof(*mgr));
|
memset(mgr, 0, sizeof(*mgr));
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
// clang-format off
|
// clang-format off
|
||||||
{ WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); }
|
{ WSADATA data; WSAStartup(MAKEWORD(2, 2), &data); }
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|||||||
+7
-7
@@ -9,7 +9,7 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#if MG_ENABLE_SOCKET
|
#if MG_ENABLE_SOCKET
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
#define MG_SOCK_ERRNO WSAGetLastError()
|
#define MG_SOCK_ERRNO WSAGetLastError()
|
||||||
#ifndef SO_EXCLUSIVEADDRUSE
|
#ifndef SO_EXCLUSIVEADDRUSE
|
||||||
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
#define SO_EXCLUSIVEADDRUSE ((int) (~SO_REUSEADDR))
|
||||||
@@ -81,7 +81,7 @@ static bool mg_sock_would_block(void) {
|
|||||||
#ifndef WINCE
|
#ifndef WINCE
|
||||||
|| err == EAGAIN || err == EINTR
|
|| err == EAGAIN || err == EINTR
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
|| err == WSAEINTR || err == WSAEWOULDBLOCK
|
|| err == WSAEINTR || err == WSAEWOULDBLOCK
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
@@ -175,7 +175,7 @@ bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mg_set_non_blocking_mode(SOCKET fd) {
|
static void mg_set_non_blocking_mode(SOCKET fd) {
|
||||||
#if defined(_WIN32) && MG_ENABLE_WINSOCK
|
#if MG_ARCH == MG_ARCH_WIN32 && MG_ENABLE_WINSOCK
|
||||||
unsigned long on = 1;
|
unsigned long on = 1;
|
||||||
ioctlsocket(fd, FIONBIO, &on);
|
ioctlsocket(fd, FIONBIO, &on);
|
||||||
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
#elif MG_ARCH == MG_ARCH_FREERTOS_TCP
|
||||||
@@ -208,7 +208,7 @@ static SOCKET mg_open_listener(const char *url, struct mg_addr *addr) {
|
|||||||
(void) on;
|
(void) on;
|
||||||
|
|
||||||
if ((fd = socket(af, type, proto)) != INVALID_SOCKET &&
|
if ((fd = socket(af, type, proto)) != INVALID_SOCKET &&
|
||||||
#if (!defined(_WIN32) || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
#if (MG_ARCH != MG_ARCH_WIN32 || !defined(SO_EXCLUSIVEADDRUSE)) && \
|
||||||
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
(!defined(LWIP_SOCKET) || (defined(LWIP_SOCKET) && SO_REUSE == 1))
|
||||||
// 1. SO_RESUSEADDR is not enabled on Windows because the semantics of
|
// 1. SO_RESUSEADDR is not enabled on Windows because the semantics of
|
||||||
// SO_REUSEADDR on UNIX and Windows is different. On Windows,
|
// SO_REUSEADDR on UNIX and Windows is different. On Windows,
|
||||||
@@ -223,7 +223,7 @@ static SOCKET mg_open_listener(const char *url, struct mg_addr *addr) {
|
|||||||
// but won't work! (setsockopt will return EINVAL)
|
// but won't work! (setsockopt will return EINVAL)
|
||||||
!setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) &&
|
!setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) &&
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
#if MG_ARCH == MG_ARCH_WIN32 && defined(SO_EXCLUSIVEADDRUSE) && !defined(WINCE)
|
||||||
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
// "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE"
|
||||||
//! setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on))
|
//! setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char *) &on, sizeof(on))
|
||||||
//! &&
|
//! &&
|
||||||
@@ -334,7 +334,7 @@ static void setsockopts(struct mg_connection *c) {
|
|||||||
int idle = 60;
|
int idle = 60;
|
||||||
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
|
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle));
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_WIN32) && !defined(__QNX__)
|
#if MG_ARCH != MG_ARCH_WIN32 && !defined(__QNX__)
|
||||||
{
|
{
|
||||||
int cnt = 3, intvl = 20;
|
int cnt = 3, intvl = 20;
|
||||||
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
|
setsockopt(FD(c), IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt));
|
||||||
@@ -403,7 +403,7 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
|||||||
if (MG_SOCK_ERRNO != EAGAIN)
|
if (MG_SOCK_ERRNO != EAGAIN)
|
||||||
#endif
|
#endif
|
||||||
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
LOG(LL_ERROR, ("%lu accept failed, errno %d", lsn->id, MG_SOCK_ERRNO));
|
||||||
#if (!defined(_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP))
|
#if ((MG_ARCH != MG_ARCH_WIN32) && (MG_ARCH != MG_ARCH_FREERTOS_TCP))
|
||||||
} else if ((long) fd >= FD_SETSIZE) {
|
} else if ((long) fd >= FD_SETSIZE) {
|
||||||
LOG(LL_ERROR, ("%ld > %ld", (long) fd, (long) FD_SETSIZE));
|
LOG(LL_ERROR, ("%ld > %ld", (long) fd, (long) FD_SETSIZE));
|
||||||
closesocket(fd);
|
closesocket(fd);
|
||||||
|
|||||||
Reference in new issue
Block a user