//callback after the data are sent static void ICACHE_FLASH_ATTR serverSentCb(void *arg) { serverConnData *conn = serverFindConnData(arg); //ets_uart_printf("Sent callback on conn %p\n", conn); if (conn==NULL) return; conn->readytosend = true; sendtxbuffer(conn); // send possible new data in txbuffer }
//use espbuffsent instead of espconn_sent //It solve problem: the next espconn_sent must after espconn_sent_callback of the pre-packet. //Add data to the send buffer and send if previous send was completed it call sendtxbuffer and espconn_sent //Returns ESPCONN_OK (0) for success, -128 if buffer is full or error from espconn_sent sint8 ICACHE_FLASH_ATTR espbuffsent(serverConnData *conn, const char *data, uint16 len) { if (connData->txbufferlen + len > MAX_TXBUFFER) { os_printf("\r\nespbuffsent: txbuffer full txbufferlen=%d, len=%d, max=%d", connData->txbufferlen, len, MAX_TXBUFFER); return -128; } os_memcpy(connData->txbuffer + connData->txbufferlen, data, len); connData->txbufferlen += len; if (connData->readytosend) return sendtxbuffer(connData); return ESPCONN_OK; }
//use espbuffsent instead of espconn_sent //It solve problem: the next espconn_sent must after espconn_sent_callback of the pre-packet. //Add data to the send buffer and send if previous send was completed it call sendtxbuffer and espconn_sent //Returns ESPCONN_OK (0) for success, -128 if buffer is full or error from espconn_sent sint8 ICACHE_FLASH_ATTR espbuffsent(serverConnData *conn, const char *data, uint16 len) { if (conn->txbufferlen + len > MAX_TXBUFFER) { //ets_uart_printf("espbuffsent: txbuffer full on conn %p\n", conn); return -128; } os_memcpy(conn->txbuffer + conn->txbufferlen, data, len); conn->txbufferlen += len; if (conn->readytosend) return sendtxbuffer(conn); return ESPCONN_OK; }
//send formatted output to transmit buffer and call sendtxbuffer, if ready (previous espconn_sent is completed) sint8 ICACHE_FLASH_ATTR espbuffsentprintf(serverConnData *conn, const char *format, ...) { uint16 len; va_list al; va_start(al, format); len = ets_vsnprintf(conn->txbuffer + conn->txbufferlen, MAX_TXBUFFER - conn->txbufferlen - 1, format, al); va_end(al); if (len <0) { return len; } conn->txbufferlen += len; if (conn->readytosend) return sendtxbuffer(conn); return ESPCONN_OK; }
//callback after the data are sent static void ICACHE_FLASH_ATTR serverSentCb(void *arg) { connData->readytosend = true; sendtxbuffer(connData); // send possible new data in txbuffer }