Commit 604c0b18 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by rojer

MG_CC3200 -> MG_SOCKET_SIMPLELINK; some cleanups

PUBLISHED_FROM=865b94073c5ed088847d05f57c1103119648fcaa
parent 356f1f51
...@@ -24,12 +24,9 @@ IPATH = . ../.. $(REPO_PATH) ...@@ -24,12 +24,9 @@ IPATH = . ../.. $(REPO_PATH)
VPATH = ../.. VPATH = ../..
MONGOOSE_FEATURES = \ MONGOOSE_FEATURES = \
-DMG_CC3200 \
-DMG_DISABLE_DIRECTORY_LISTING \ -DMG_DISABLE_DIRECTORY_LISTING \
-DMG_DISABLE_JSON_RPC \ -DMG_DISABLE_JSON_RPC \
-DMG_DISABLE_COAP \ -DMG_DISABLE_COAP \
-DMG_DISABLE_SYNC_RESOLVER \
-DMG_DISABLE_SOCKETPAIR \
-DMG_DISABLE_DAV \ -DMG_DISABLE_DAV \
-DMG_DISABLE_CGI \ -DMG_DISABLE_CGI \
-DMG_DISABLE_SSI \ -DMG_DISABLE_SSI \
...@@ -37,8 +34,7 @@ MONGOOSE_FEATURES = \ ...@@ -37,8 +34,7 @@ MONGOOSE_FEATURES = \
-DMG_MAX_HTTP_HEADERS=20 \ -DMG_MAX_HTTP_HEADERS=20 \
-DMG_MAX_HTTP_REQUEST_SIZE=1024 \ -DMG_MAX_HTTP_REQUEST_SIZE=1024 \
-DMG_MAX_PATH=40 \ -DMG_MAX_PATH=40 \
-DMG_MAX_HTTP_SEND_MBUF=1024 \ -DMG_MAX_HTTP_SEND_MBUF=1024
-DMG_NO_BSD_SOCKETS
SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM # -DTARGET_IS_CC3200 would reduce code size by using functions in ROM
......
...@@ -529,7 +529,7 @@ typedef int cs_dirent_dummy; ...@@ -529,7 +529,7 @@ typedef int cs_dirent_dummy;
#ifndef _WIN32 #ifndef _WIN32
#include <stddef.h> #include <stddef.h>
#ifndef MG_CC3200 #if !defined(CS_PLATFORM) || CS_PLATFORM != CS_P_CC3200
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#else #else
...@@ -3071,8 +3071,10 @@ void mg_set_non_blocking_mode(sock_t sock) { ...@@ -3071,8 +3071,10 @@ void mg_set_non_blocking_mode(sock_t sock) {
#ifdef _WIN32 #ifdef _WIN32
unsigned long on = 1; unsigned long on = 1;
ioctlsocket(sock, FIONBIO, &on); ioctlsocket(sock, FIONBIO, &on);
#elif defined(MG_CC3200) #elif defined(MG_SOCKET_SIMPLELINK)
cc3200_set_non_blocking_mode(sock); SlSockNonblocking_t opt;
opt.NonblockingEnabled = 1;
sl_SetSockOpt(sock, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &opt, sizeof(opt));
#else #else
int flags = fcntl(sock, F_GETFL, 0); int flags = fcntl(sock, F_GETFL, 0);
fcntl(sock, F_SETFL, flags | O_NONBLOCK); fcntl(sock, F_SETFL, flags | O_NONBLOCK);
...@@ -3080,13 +3082,13 @@ void mg_set_non_blocking_mode(sock_t sock) { ...@@ -3080,13 +3082,13 @@ void mg_set_non_blocking_mode(sock_t sock) {
} }
int mg_is_error(int n) { int mg_is_error(int n) {
#ifdef MG_CC3200 #ifdef MG_SOCKET_SIMPLELINK
DBG(("n = %d, errno = %d", n, errno)); DBG(("n = %d, errno = %d", n, errno));
if (n < 0) errno = n; if (n < 0) errno = n;
#endif #endif
return n == 0 || (n < 0 && errno != EINTR && errno != EINPROGRESS && return n == 0 || (n < 0 && errno != EINTR && errno != EINPROGRESS &&
errno != EAGAIN && errno != EWOULDBLOCK errno != EAGAIN && errno != EWOULDBLOCK
#ifdef MG_CC3200 #ifdef MG_SOCKET_SIMPLELINK
&& errno != SL_EALREADY && errno != SL_EALREADY
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
...@@ -3105,7 +3107,7 @@ void mg_if_connect_tcp(struct mg_connection *nc, ...@@ -3105,7 +3107,7 @@ void mg_if_connect_tcp(struct mg_connection *nc,
nc->err = errno ? errno : 1; nc->err = errno ? errno : 1;
return; return;
} }
#if !defined(MG_CC3200) && !defined(MG_ESP8266) #if !defined(MG_SOCKET_SIMPLELINK) && !defined(MG_ESP8266)
mg_set_non_blocking_mode(nc->sock); mg_set_non_blocking_mode(nc->sock);
#endif #endif
rc = connect(nc->sock, &sa->sa, sizeof(sa->sin)); rc = connect(nc->sock, &sa->sa, sizeof(sa->sin));
...@@ -3211,13 +3213,13 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) { ...@@ -3211,13 +3213,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(MG_LWIP) #if !defined(MG_SOCKET_SIMPLELINK) && !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_SOCKET_SIMPLELINK) && \
!defined(MG_LWIP) /* CC3200 and LWIP don't support either */ !defined(MG_LWIP) /* SimpleLink 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,
...@@ -3236,11 +3238,12 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) { ...@@ -3236,11 +3238,12 @@ 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 && !MG_LWIP */ #endif /* !MG_SOCKET_SIMPLELINK && !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(MG_LWIP) /* TODO(rojer): Fix this. */ #if !defined(MG_SOCKET_SIMPLELINK) && \
!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);
...@@ -3444,7 +3447,7 @@ void mg_mgr_handle_conn(struct mg_connection *nc, int fd_flags, double now) { ...@@ -3444,7 +3447,7 @@ void mg_mgr_handle_conn(struct mg_connection *nc, int fd_flags, double now) {
if (nc->flags & MG_F_CONNECTING) { if (nc->flags & MG_F_CONNECTING) {
if (fd_flags != 0) { if (fd_flags != 0) {
int err = 0; int err = 0;
#if !defined(MG_CC3200) && !defined(MG_ESP8266) #if !defined(MG_SOCKET_SIMPLELINK) && !defined(MG_ESP8266)
if (!(nc->flags & MG_F_UDP)) { if (!(nc->flags & MG_F_UDP)) {
socklen_t len = sizeof(err); socklen_t len = sizeof(err);
int ret = int ret =
...@@ -3452,7 +3455,7 @@ void mg_mgr_handle_conn(struct mg_connection *nc, int fd_flags, double now) { ...@@ -3452,7 +3455,7 @@ void mg_mgr_handle_conn(struct mg_connection *nc, int fd_flags, double now) {
if (ret != 0) err = 1; if (ret != 0) err = 1;
} }
#else #else
/* On CC3200 and ESP8266 we use blocking connect. If we got as far as /* On SimpleLink and ESP8266 we use blocking connect. If we got as far as
* this, it means connect() was successful. * this, it means connect() was successful.
* TODO(rojer): Figure out why it fails where blocking succeeds. * TODO(rojer): Figure out why it fails where blocking succeeds.
*/ */
...@@ -3794,8 +3797,8 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) { ...@@ -3794,8 +3797,8 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
(FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) | (FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) |
(FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0); (FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0);
} }
#ifdef MG_CC3200 #ifdef MG_SOCKET_SIMPLELINK
// CC3200 does not report UDP sockets as writeable. /* SimpleLink does not report UDP sockets as writeable. */
if (nc->flags & MG_F_UDP && if (nc->flags & MG_F_UDP &&
(nc->send_mbuf.len > 0 || nc->flags & MG_F_CONNECTING)) { (nc->send_mbuf.len > 0 || nc->flags & MG_F_CONNECTING)) {
fd_flags |= _MG_F_FD_CAN_WRITE; fd_flags |= _MG_F_FD_CAN_WRITE;
...@@ -3867,7 +3870,7 @@ int mg_socketpair(sock_t sp[2], int sock_type) { ...@@ -3867,7 +3870,7 @@ int mg_socketpair(sock_t sp[2], int sock_type) {
} }
#endif /* MG_DISABLE_SOCKETPAIR */ #endif /* MG_DISABLE_SOCKETPAIR */
#ifndef MG_CC3200 #ifndef MG_SOCKET_SIMPLELINK
static void mg_sock_get_addr(sock_t sock, int remote, static void mg_sock_get_addr(sock_t sock, int remote,
union socket_address *sa) { union socket_address *sa) {
socklen_t slen = sizeof(*sa); socklen_t slen = sizeof(*sa);
...@@ -3888,7 +3891,7 @@ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags) { ...@@ -3888,7 +3891,7 @@ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags) {
void mg_if_get_conn_addr(struct mg_connection *nc, int remote, void mg_if_get_conn_addr(struct mg_connection *nc, int remote,
union socket_address *sa) { union socket_address *sa) {
#ifndef MG_CC3200 #ifndef MG_SOCKET_SIMPLELINK
mg_sock_get_addr(nc->sock, remote, sa); mg_sock_get_addr(nc->sock, remote, sa);
#else #else
/* SimpleLink does not provide a way to get socket's peer address after /* SimpleLink does not provide a way to get socket's peer address after
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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