新手上路
- 积分
- 37
- 金钱
- 37
- 注册时间
- 2020-4-9
- 在线时间
- 17 小时
|

楼主 |
发表于 2020-4-14 18:53:37
|
显示全部楼层
附上 发送代码
static void tcp_echoclient_send(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))) //tcp_sndbuf ·¢Ëí3¤¶è£¨»o3åÇøÄü′æ·ÅμÄ3¤¶è£©
{
/* get pointer on pbuf from es structure */
ptr = es->p_tx;
/* enqueue data for transmission */
wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1); //½«·¢Ëíêy¾Y¼óèë¶óáD
if (wr_err == ERR_OK)
{
u8 freed;
/* continue with next pbuf in chain (if any) */
es->p_tx = ptr->next;
if(es->p_tx != NULL)
{
/* increment reference count for es->p */
pbuf_ref(es->p_tx);
}
/* free pbuf: will free pbufs up to es->p (because es->p has a reference count > 0) */
do
{
/* try hard to free pbuf */
freed = pbuf_free(ptr);
}
while(freed == 0);
tcp_recved(tpcb, ptr->len);
}
else if(wr_err == ERR_MEM)
{
/* we are low on memory, try later, defer to poll */
es->p_tx = ptr;
tcp_output(tpcb);
// pbuf_free(ptr);
}
else
{
/* other problem ?? */
}
tcp_output(tpcb);
}
}
u8_t tcp_send_message(void *msg, uint16_t len)
{
tcp_size_buf = tcp_sndbuf(es->pcb);
if(tcp_connected_flag == 1)
{
es->p_tx = pbuf_alloc(PBUF_TRANSPORT,len,PBUF_RAM);
pbuf_take( es->p_tx ,msg , len);
tcp_echoclient_send(es->pcb, es);
}
return 1;
} |
|