示例#1
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;
}
示例#2
0
static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg)
{
    espconn_msg *psent = arg;

    if (psent == NULL) {
        return;
    }

    if (psent->pcommon.cntr == 0) {
        psent->pespconn->state = ESPCONN_CONNECT;
        sys_timeout(TCP_FAST_INTERVAL, espconn_data_sentcb, psent->pespconn);
    } else {
        espconn_udp_sent(arg, psent->pcommon.ptrbuf, psent->pcommon.cntr);
    }
}
示例#3
0
static void ICACHE_FLASH_ATTR espconn_data_sent(void *arg, enum send_opt opt)
{
    espconn_msg *psent = arg;

    if (psent == NULL) {
        return;
    }

    if (psent->pcommon.cntr == 0) {
        psent->pespconn->state = ESPCONN_CONNECT;
        if (psent->pcommon.err == 0)
        	espconn_data_sentcb(psent->pespconn);
    } else {
    	if (opt == ESPCONN_SEND){
    		espconn_udp_sent(arg, psent->pcommon.ptrbuf, psent->pcommon.cntr);
    	} else {
    		espconn_udp_sendto(arg, psent->pcommon.ptrbuf, psent->pcommon.cntr);
    	}
    }
}
示例#4
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;
	err_t error = ESPCONN_OK;
	espconn_buf *pbuf = NULL;
	
    if (espconn == NULL || psent == NULL || length == 0) {
        return ESPCONN_ARG;
    }
    //printf("espconn_sent len %d %s \n",length,psent);
	/*Find the node depend on the espconn message*/
	value = espconn_find_connection(espconn, &pnode);
    if (value){
    	espconn ->state = ESPCONN_WRITE;
		switch (espconn ->type) {
			case ESPCONN_TCP:
				/* calling sent function frequently,make sure last packet has been backup or sent fully*/
				if (pnode->pcommon.write_flag){
					/*If total number of espconn_buf on the unsent lists exceeds the set maximum, return an error */
					if (espconn_copy_enabled(pnode)){
						if (espconn_tcp_get_buf_count(pnode->pcommon.pbuf) >= pnode ->pcommon.pbuf_num)
							return ESPCONN_MAXNUM;
					} else {
						// struct tcp_pcb *pcb = (struct tcp_pcb *)pnode->pcommon.pcb;
						if (((struct tcp_pcb *)pnode->pcommon.pcb)->snd_queuelen >= TCP_SND_QUEUELEN(0))
							return ESPCONN_MAXNUM;
					}

					pbuf = (espconn_buf*) malloc(sizeof(espconn_buf));
					if (pbuf == NULL)
						return ESPCONN_MEM;
					else {
						/*Backup the application packet information for send more data*/
						pbuf->payload = psent;
						pbuf->punsent = pbuf->payload;
						pbuf->unsent = length;
						pbuf->len = length;
						/*insert the espconn_pbuf to the list*/
						espconn_pbuf_create(&pnode->pcommon.pbuf, pbuf);
						if (pnode->pcommon.ptail == NULL) {
							pnode->pcommon.ptail = pbuf;
						}
	//printf("espconn_pbuf_create %p pesp_buf %p\n",pnode,pnode->pcommon.pbuf);
					}
					/*when set the data copy option. change the flag for next packet*/
					if (espconn_copy_disabled(pnode))
						pnode->pcommon.write_flag = false;
					error = espconn_tcp_write(pnode);
					if (error != ESPCONN_OK){
						/*send the application packet fail,
						 * ensure that each allocated is deleted*/
						espconn_pbuf_delete(&pnode->pcommon.pbuf, pbuf);
						// free();
						free(pbuf);
						pbuf = NULL;
					}
					return error;
				} else
					return ESPCONN_ARG;
				break;

			case ESPCONN_UDP:
				return espconn_udp_sent(pnode, psent, length);
				break;

			default :
				break;
		}
    }
    return ESPCONN_ARG;
}