void ICACHE_FLASH_ATTR tfp_recv_hold(void) { if(!tfp_is_hold) { for(uint8_t i = 0; i < TFP_MAX_CONNECTIONS; i++) { if(tfp_cons[i].state == TFP_CON_STATE_OPEN || tfp_cons[i].state == TFP_CON_STATE_SENDING) { espconn_recv_hold(tfp_cons[i].con); } } logd("hold: %d\n", ringbuffer_get_free(&tfp_rb)); tfp_is_hold = true; } }
static void esp8266_cb_connect(void *arg) { struct espconn *cs = arg; // struct ip_addr *ipa = (struct ip_addr *)cs->proto.tcp->remote_ip; struct lws_vhost *vh = hacky_context->vhost_list; // struct ip_info info; struct lws *wsi; int n; lwsl_notice("%s: (wsi coming): %p\n", __func__, cs->reverse); #if 0 wifi_get_ip_info(0, &info); if (ip_addr_netcmp(ipa, &info.ip, &info.netmask)) { /* we are on the same subnet as the AP, ie, connected to AP */ while (vh && strcmp(vh->name, "ap")) vh = vh->vhost_next; } else while (vh && !strcmp(vh->name, "ap")) vh = vh->vhost_next; if (!vh) goto bail; #endif n = esp8266_find_free_conn(hacky_context); if (n < 0) goto bail; hacky_context->connpool[n] = cs; espconn_recv_hold(cs); wsi = lws_adopt_socket_vhost(vh, cs); if (!wsi) goto bail; lwsl_err("%s: wsi %p (using free_conn %d): vh %s\n", __func__, wsi, n, vh->name); espconn_regist_recvcb(cs, esp8266_cb_rx); espconn_regist_reconcb(cs, esp8266_cb_recon); espconn_regist_disconcb(cs, esp8266_cb_disconnected); espconn_regist_sentcb(cs, esp8266_cb_sent); espconn_set_opt(cs, ESPCONN_NODELAY | ESPCONN_REUSEADDR); espconn_regist_time(cs, 7200, 1); return; bail: lwsl_err("%s: bailed]n", __func__); espconn_disconnect(cs); }
static int tls_socket_hold( lua_State *L ) { tls_socket_ud *ud = (tls_socket_ud *)luaL_checkudata(L, 1, "tls.socket"); luaL_argcheck(L, ud, 1, "TLS socket expected"); if(ud==NULL){ NODE_DBG("userdata is nil.\n"); return 0; } if(ud->pesp_conn == NULL) { NODE_DBG("not connected"); return 0; } espconn_recv_hold(ud->pesp_conn); return 0; }
/** * ESP8266 callback function that is invoked when new data has arrived over * the TCP/IP connection. */ static void esp8266_callback_recvCB( void *arg, //!< A pointer to a `struct espconn`. char *pData, //!< A pointer to data received over the socket. unsigned short len //!< The length of the data. ) { struct espconn *pEspconn = (struct espconn *)arg; struct socketData *pSocketData = (struct socketData *)pEspconn->reverse; if (pSocketData == NULL) return; // we closed this socket //if (pEspconn != pSocketData->pEspconn) DBG("%s: pEspconn changed in recvCB ***\n", DBG_LIB); assert(pSocketData->state != SOCKET_STATE_UNUSED); //DBG("%s: socket %d recv %d\n", DBG_LIB, pSocketData->socketId, len); //DBG("%s: recv data: %p\n", DBG_LIB, pData); // if this is a dead connection then just ignore the callback if (pSocketData->state == SOCKET_STATE_ABORTING || pSocketData->state == SOCKET_STATE_TO_ABORT || pSocketData->state == SOCKET_STATE_CLOSED || pSocketData->state == SOCKET_STATE_DISCONNECTING) { return; } // Allocate a buffer and add to the receive queue PktBuf *buf = PktBuf_New(len); if (!buf) { // handle out of memory condition DBG("%s: Out of memory allocating %d for recv\n", DBG_LIB, len); // at this point we're gonna deallocate all receive buffers as a panic measure while (pSocketData->rxBufQ != NULL) pSocketData->rxBufQ = PktBuf_ShiftFree(pSocketData->rxBufQ); // save the error setSocketInError(pSocketData, ESPCONN_MEM); // now reset the connection //espconn_abort(pEspconn); // can't do this: espconn crashes! pSocketData->state = SOCKET_STATE_TO_ABORT; // some function called from socket lib will abort //DBG("%s: ret from recvCB\n", DBG_LIB); return; } // if this is the second buffer then stop the flood! if (pSocketData->rxBufQ != NULL) espconn_recv_hold(pEspconn); // got buffer, fill it os_memcpy(buf->data, pData, len); buf->filled = len; pSocketData->rxBufQ = PktBuf_Push(pSocketData->rxBufQ, buf); }
LWS_VISIBLE int lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi, struct lws_pollfd *pfd) { void *p; //lwsl_notice("%s: %p: wsi->pift=%d, events %d\n", // __func__, wsi, wsi->position_in_fds_table, pfd->events); if (pfd->events & LWS_POLLIN) { if (wsi->premature_rx) { lwsl_notice("replaying buffered rx: wsi %p\n", wsi); p = wsi->premature_rx; wsi->premature_rx = NULL; esp8266_cb_rx(wsi->desc.sockfd, (char *)p + wsi->prem_rx_pos, wsi->prem_rx_size - wsi->prem_rx_pos); wsi->prem_rx_size = 0; wsi->prem_rx_pos = 0; lws_free(p); } if (espconn_recv_unhold(wsi->desc.sockfd) < 0) return -1; } else if (espconn_recv_hold(wsi->desc.sockfd) < 0) return -1; if (!(pfd->events & LWS_POLLOUT)) return 0; if (!wsi->pending_send_completion) { pfd->revents |= LWS_POLLOUT; // lwsl_notice("doing POLLOUT\n"); lws_service_fd(lws_get_context(wsi), pfd); } //else //lwsl_notice("pending sc\n"); return 0; }
static int net_socket_hold( lua_State* L ) { const char *mt = "net.socket"; struct espconn *pesp_conn = NULL; lnet_userdata *nud; size_t l; nud = (lnet_userdata *)luaL_checkudata(L, 1, mt); luaL_argcheck(L, nud, 1, "Server/Socket expected"); if(nud==NULL){ NODE_DBG("userdata is nil.\n"); return 0; } if(nud->pesp_conn == NULL){ NODE_DBG("nud->pesp_conn is NULL.\n"); return 0; } pesp_conn = nud->pesp_conn; espconn_recv_hold(pesp_conn); return 0; }