Commit b3565781 authored by Marko Mikulicic's avatar Marko Mikulicic Committed by Sergey Lyubka

Factor our LWIP enabling flag

    PUBLISHED_FROM=d080ccb2d0daef1103ff7487b5c3f4b65ab97b99
parent a2322c77
...@@ -2161,13 +2161,13 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) { ...@@ -2161,13 +2161,13 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) {
socklen_t sa_len = socklen_t sa_len =
(sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6); (sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6);
sock_t sock = INVALID_SOCKET; sock_t sock = INVALID_SOCKET;
#if !defined(MG_CC3200) && !defined(RTOS_SDK) #if !defined(MG_CC3200) && !defined(MG_LWIP)
int on = 1; int on = 1;
#endif #endif
if ((sock = socket(sa->sa.sa_family, proto, 0)) != INVALID_SOCKET && if ((sock = socket(sa->sa.sa_family, proto, 0)) != INVALID_SOCKET &&
#if !defined(MG_CC3200) && \ #if !defined(MG_CC3200) && \
!defined(RTOS_SDK) /* CC3200 nor ESP8266 don't support either */ !defined(MG_LWIP) /* CC3200 and LWIP don't support either */
#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE) #if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE)
/* "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" http://goo.gl/RmrFTm */ /* "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" http://goo.gl/RmrFTm */
!setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on, !setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on,
...@@ -2186,11 +2186,11 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) { ...@@ -2186,11 +2186,11 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) {
*/ */
!setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) && !setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) &&
#endif #endif
#endif /* !MG_CC3200 */ #endif /* !MG_CC3200 && !MG_LWIP */
!bind(sock, &sa->sa, sa_len) && !bind(sock, &sa->sa, sa_len) &&
(proto == SOCK_DGRAM || listen(sock, SOMAXCONN) == 0)) { (proto == SOCK_DGRAM || listen(sock, SOMAXCONN) == 0)) {
#if !defined(MG_CC3200) && !defined(RTOS_SDK) /* TODO(rojer): Fix this. */ #if !defined(MG_CC3200) && !defined(MG_LWIP) /* TODO(rojer): Fix this. */
mg_set_non_blocking_mode(sock); mg_set_non_blocking_mode(sock);
/* In case port was set to 0, get the real port number */ /* In case port was set to 0, get the real port number */
(void) getsockname(sock, &sa->sa, &sa_len); (void) getsockname(sock, &sa->sa, &sa_len);
...@@ -2530,8 +2530,8 @@ static void mg_write_to_socket(struct mg_connection *conn) { ...@@ -2530,8 +2530,8 @@ static void mg_write_to_socket(struct mg_connection *conn) {
struct mbuf *io = &conn->send_mbuf; struct mbuf *io = &conn->send_mbuf;
int n = 0; int n = 0;
#ifdef RTOS_SDK #ifdef MG_LWIP
/* In ESP8266 RTOS_SDK we don't know if the socket is ready */ /* With LWIP we don't know if the socket is ready */
if (io->len == 0) return; if (io->len == 0) return;
#endif #endif
...@@ -2895,8 +2895,8 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) { ...@@ -2895,8 +2895,8 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
fd_flags |= _MG_F_FD_CAN_WRITE; fd_flags |= _MG_F_FD_CAN_WRITE;
} }
#endif #endif
#ifdef RTOS_SDK #ifdef MG_LWIP
/* In ESP8266 RTOS_SDK we don't get write events */ /* With LWIP socket emulation layer, we don't get write events */
fd_flags |= _MG_F_FD_CAN_WRITE; fd_flags |= _MG_F_FD_CAN_WRITE;
#endif #endif
tmp = nc->next; tmp = nc->next;
......
...@@ -194,13 +194,17 @@ struct dirent *readdir(DIR *dir); ...@@ -194,13 +194,17 @@ struct dirent *readdir(DIR *dir);
#include <cc3200_libc.h> #include <cc3200_libc.h>
#include <cc3200_socket.h> #include <cc3200_socket.h>
#elif /* not CC3200 */ defined(MG_ESP8266) && defined(RTOS_SDK) #elif /* not CC3200 */ defined(MG_LWIP)
#include <lwip/sockets.h> #include <lwip/sockets.h>
#include <lwip/netdb.h> #include <lwip/netdb.h>
#include <lwip/dns.h> #include <lwip/dns.h>
#if defined(MG_ESP8266) && defined(RTOS_SDK)
#include <esp_libc.h> #include <esp_libc.h>
#define random() os_random() #define random() os_random()
#endif
/* TODO(alashkin): check if zero is OK */ /* TODO(alashkin): check if zero is OK */
#define SOMAXCONN 0 #define SOMAXCONN 0
#include <stdlib.h> #include <stdlib.h>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment