From 5351f46efbfae4647646f5b694df9ddde0e31886 Mon Sep 17 00:00:00 2001
From: Marko Mikulicic <mkm@cesanta.com>
Date: Tue, 22 Sep 2015 14:16:40 +0100
Subject: [PATCH] Mongoose send on esp8266 RTOS_SDK

    PUBLISHED_FROM=1e97853ebc1c39b01754cf76d875453842e9b36d
---
 mongoose.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/mongoose.c b/mongoose.c
index f91af5cab..6bae65b04 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -2074,7 +2074,7 @@ MG_INTERNAL struct mg_connection *mg_create_connection(
 
 /* Associate a socket to a connection and and add to the manager. */
 MG_INTERNAL void mg_set_sock(struct mg_connection *nc, sock_t sock) {
-#if !defined(MG_CC3200) && !defined(MG_ESP8266)
+#if !defined(MG_CC3200)
   /* Can't get non-blocking connect to work.
    * TODO(rojer): Figure out why it fails where blocking succeeds.
    */
@@ -2530,6 +2530,11 @@ static void mg_write_to_socket(struct mg_connection *conn) {
   struct mbuf *io = &conn->send_mbuf;
   int n = 0;
 
+#ifdef RTOS_SDK
+  /* In ESP8266 RTOS_SDK we don't know if the socket is ready */
+  if (io->len == 0) return;
+#endif
+
   assert(io->len > 0);
 
 #ifdef MG_ENABLE_SSL
@@ -2889,6 +2894,10 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
         (nc->send_mbuf.len > 0 || nc->flags & MG_F_CONNECTING)) {
       fd_flags |= _MG_F_FD_CAN_WRITE;
     }
+#endif
+#ifdef RTOS_SDK
+    /* In ESP8266 RTOS_SDK we don't get write events */
+    fd_flags |= _MG_F_FD_CAN_WRITE;
 #endif
     tmp = nc->next;
     mg_mgr_handle_connection(nc, fd_flags, now);
-- 
GitLab