Beispiel #1
0
/******************************************************************************
 * FunctionName : espconn_tcp_write
 * Description  : write the packet which in the active connection's list.
 * Parameters   : arg -- the node pointer which reverse the packet
 * Returns      : ESPCONN_MEM: memory error
 * 				  ESPCONN_OK:have enough space for write packet
*******************************************************************************/
err_t ICACHE_FLASH_ATTR espconn_tcp_write(void *arg)
{
	espconn_msg *pwrite = (espconn_msg *) arg;
	err_t err = ERR_OK;
	struct tcp_pcb *pcb = (struct tcp_pcb *)(pwrite->pcommon.pcb);
	/*for one active connection,limit the sender buffer space*/
	if (tcp_nagle_disabled(pcb) && (pcb->snd_queuelen >= TCP_SND_QUEUELEN(0)))
		return ESPCONN_MEM;

	while (tcp_sndbuf(pcb) != 0){
		if (pwrite->pcommon.ptail != NULL) {
			/*Find the node whether in the list's tail or not*/
			if (pwrite->pcommon.ptail->unsent == 0) {
				pwrite->pcommon.ptail = pwrite->pcommon.ptail->pnext;
				continue;
			}

			/*Send the packet for the active connection*/
			err = espconn_tcp_sent(pwrite, pwrite->pcommon.ptail->punsent,pwrite->pcommon.ptail->unsent);
			if (err != ERR_OK)
				break;
		} else
			break;
	}
	return err;
}
Beispiel #2
0
/******************************************************************************
 * FunctionName : espconn_server_sent
 * Description  : Data has been sent and acknowledged by the remote host.
 * This means that more data can be sent.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb for which data has been acknowledged
 *                len -- The amount of bytes acknowledged
 * Returns      : ERR_OK: try to send some data by calling tcp_output
 *                ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_server_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
	espconn_msg *psent_cb = arg;

	psent_cb->pcommon.pcb = pcb;
	psent_cb->pcommon.recv_check = 0;
	psent_cb->pcommon.write_total += len;
	espconn_printf("espconn_server_sent sent %d %d\n", len, psent_cb->pcommon.write_total);
	if (psent_cb->pcommon.write_total == psent_cb->pcommon.write_len){
		psent_cb->pcommon.write_total = 0;
		psent_cb->pcommon.write_len = 0;
		if (psent_cb ->pcommon.cntr == 0) {
			psent_cb ->pespconn ->state = ESPCONN_CONNECT;

			if (psent_cb ->pespconn ->sent_callback != NULL) {
				psent_cb ->pespconn ->sent_callback(psent_cb ->pespconn);
			}
		} else
			espconn_tcp_sent(psent_cb, psent_cb ->pcommon.ptrbuf, psent_cb ->pcommon.cntr);
	} else {

	}
    return ERR_OK;
}
Beispiel #3
0
/******************************************************************************
 * FunctionName : espconn_sent
 * Description  : sent data for client or server
 * Parameters   : espconn -- espconn to set for client or server
 *                psent -- data to send
 *                length -- length of data to send
 * Returns      : none
*******************************************************************************/
sint8 ICACHE_FLASH_ATTR
espconn_sent(struct espconn *espconn, uint8 *psent, uint16 length)
{
	espconn_msg *pnode = NULL;
	bool value = false;
    if (espconn == NULL) {
        return ESPCONN_ARG;
    }
    espconn ->state = ESPCONN_WRITE;
    value = espconn_find_connection(espconn, &pnode);
    switch (espconn ->type) {
        case ESPCONN_TCP:
            // if (value && (pnode->pcommon.write_len == pnode->pcommon.write_total)){
        	if (value && (pnode->pcommon.cntr == 0)){
           		espconn_tcp_sent(pnode, psent, length);
            }else
            	return ESPCONN_ARG;
            break;

        case ESPCONN_UDP: {
        	if (value)
        		espconn_udp_sent(pnode, psent, length);
        	else
        		return ESPCONN_ARG;
            break;
        }

        default :
            break;
    }
    return ESPCONN_OK;
}
/******************************************************************************
 * FunctionName : espconn_client_sent
 * Description  : Data has been sent and acknowledged by the remote host.
 *                This means that more data can be sent.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb for which data has been acknowledged
 *                len -- The amount of bytes acknowledged
 * Returns      : ERR_OK: try to send some data by calling tcp_output
 *                ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t 
espconn_client_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
	espconn_msg *psent_cb = arg;
	psent_cb->pcommon.pcb = pcb;
    if (psent_cb->pcommon.cntr == 0) {
    	psent_cb->pespconn->state = ESPCONN_CONNECT;

        if (psent_cb->pespconn->sent_callback != NULL) {
        	psent_cb->pespconn->sent_callback(psent_cb->pespconn);
        }
    } else
    	espconn_tcp_sent(psent_cb, psent_cb->pcommon.ptrbuf, psent_cb->pcommon.cntr);

    return ERR_OK;
}