void ICACHE_FLASH_ATTR tfp_recv_unhold(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_unhold(tfp_cons[i].con);
			}
		}

		logd("unhold: %d\n", ringbuffer_get_free(&tfp_rb));
		tfp_is_hold = false;
	}
}
示例#2
0
static int tls_socket_unhold( 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_unhold(ud->pesp_conn);

  return 0;
}
示例#3
0
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;
}
示例#4
0
static int net_socket_unhold( 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_unhold(pesp_conn);

  return 0;
}
示例#5
0
/**
 * Receive data from the network device.
 * Returns the number of bytes received which may be 0 and <0 if there was an error.
 */
int net_ESP8266_BOARD_recv(
    JsNetwork *net, //!< The Network we are going to use to create the socket.
    int sckt,       //!< The socket from which we are to receive data.
    void *buf,      //!< The storage buffer into which we will receive data.
    size_t len      //!< The length of the buffer.
) {
    //DBG("%s:recv\n", DBG_LIB);
    struct socketData *pSocketData = getSocketData(sckt);
    assert(pSocketData);
    assert(pSocketData->state != SOCKET_STATE_UNUSED);

    // handle socket that needs aborting
    if (pSocketData->state == SOCKET_STATE_TO_ABORT) {
        espconn_abort(pSocketData->pEspconn);
        return pSocketData->errorCode;
    }

    // If there is no data in the receive buffer, then all we need do is return
    // 0 bytes as the length of data moved or -1 if the socket is actually closed.
    if (pSocketData->rxBufQ == NULL) {
        switch (pSocketData->state) {
        case SOCKET_STATE_CLOSED:
            return pSocketData->errorCode != 0 ? pSocketData->errorCode : SOCKET_ERR_CLOSED;
        case SOCKET_STATE_DISCONNECTING:
        case SOCKET_STATE_ABORTING:
            return pSocketData->errorCode;
        case SOCKET_STATE_HOST_RESOLVING:
        case SOCKET_STATE_CONNECTING:
            return SOCKET_ERR_NO_CONN;
        default:
            return 0; // we just have no data
        }
    }
    PktBuf *rxBuf = pSocketData->rxBufQ;

    // If the receive buffer is able to completely fit in the buffer
    // passed into us then we can copy all the data and the receive buffer will be clear.
    if (rxBuf->filled <= len) {
        os_memcpy(buf, rxBuf->data, rxBuf->filled);
        int retLen = rxBuf->filled;
        pSocketData->rxBufQ = PktBuf_ShiftFree(rxBuf);
        // if we now have exactly one buffer enqueued we need to re-enable the flood
        if (pSocketData->rxBufQ != NULL && pSocketData->rxBufQ->next == NULL)
            espconn_recv_unhold(pSocketData->pEspconn);
        //DBG("%s: socket %d JS recv %d\n", DBG_LIB, sckt, retLen);
        return retLen;
    }

    // If we are here, then we have more data in the receive buffer than is available
    // to be returned in this request for data.  So we have to copy the amount of data
    // that is allowed to be returned and then strip that from the beginning of the
    // receive buffer.

    // First we copy the data we are going to return.
    os_memcpy(buf, rxBuf->data, len);
    // Next we shift up the remaining data
    uint16_t newLen = rxBuf->filled - len;
    os_memmove(rxBuf->data, rxBuf->data + len, newLen);
    rxBuf->filled = newLen;
    //DBG("%s: socket %d JS recv %d\n", DBG_LIB, sckt, len);
    return len;
}