高级会员
- 积分
- 560
- 金钱
- 560
- 注册时间
- 2016-4-12
- 在线时间
- 230 小时
|
楼主 |
发表于 2017-8-4 16:01:36
|
显示全部楼层
[mw_shl_code=applescript,true]static err_t tcp_echoclient_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
{
struct echoclient *es = NULL;
es = (struct echoclient *)mem_malloc(sizeof(struct echoclient));
if (es != NULL)
{
es->state = ES_CONNECTED;
es->pcb = tpcb;
es->p_tx = NULL;
tcp_arg(tpcb, es);
//tcp_sent(tpcb, tcp_echoclient_sent);
tcp_poll(tpcb, tcp_echoclient_poll, 1);
err = ERR_OK;
}
}
static void tcp_echoclient_send_test(struct tcp_pcb *tpcb, struct echoclient * es)
{
struct pbuf *ptr;
err_t wr_err = ERR_OK;
while ((wr_err == ERR_OK) && ( es->p_tx != NULL) && (es->p_tx->len <= tcp_sndbuf(tpcb)))
{
ptr = es->p_tx;
wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 0);
if (wr_err == ERR_OK)
{
es->p_tx = ptr->next;
if(es->p_tx != NULL)
{
pbuf_ref(es->p_tx);
}
pbuf_free(ptr);
}
else if(wr_err == ERR_MEM)
{
es->p_tx = ptr;
}
tcp_output(tpcb);
}
}
static err_t tcp_echoclient_poll(void *arg, struct tcp_pcb *tpcb)
{
err_t ret_err;
struct echoclient *es;
es = (struct echoclient*)arg;
test6_init();
if (es != NULL)
{
es->p_tx = pbuf_alloc(PBUF_TRANSPORT, strlen((char*)test) , PBUF_POOL);
pbuf_take(es->p_tx, (char *)test, strlen((char *)test));
led_onf();
tcp_echoclient_send_test(tpcb, es);
//tcp_echoclient_send(tpcb, es);
if (es->p_tx)
pbuf_free(es->p_tx);
if(es->state == ES_CLOSING) tcp_echoclient_connection_close(tpcb, es);
ret_err = ERR_OK;
}
else
{
tcp_abort(tpcb);
ret_err = ERR_ABRT;
}
return ret_err;
}[/mw_shl_code]
|
|