翻译:Lizhiming Mail:seu.zhiming@gmail.com
8 / 43
将数据入队写至由参数 dataptr 指定的内存区域。数据的长度作为 len 参数传递。拷贝参数为 0 或 1,用于指示是否为
将要拷贝来的数据分配新的内存。如果该参数为 0,将不分配新的内存,并且数据仅能通过指针来引用。
The tcp_write() function will fail and return ERR_MEM if the length of the data exceeds
the current send buffer size or if the length of the queue of outgoing segment is larger than
the upper limit defined in lwipopts.h. The number of bytes available in the output queue can
be retrieved with the tcp_sndbuf() function.
如果数据的最大长度超过了当前发送数据缓冲区的大小,或 输 出 片段队列的长度超过了 lwipopts.h 文件中定义的上限,
tcp_write()将失败并返回 EER_MEM,在输出队列中可获得的字节数可通过 tcp_sndbuf()函数检索。
The proper way to use this function is to call the function with at most tcp_sndbuf() bytes
of data. If the function returns ERR_MEM, the application should wait until some of the
currently enqueued data has been successfully received by the other host and try again.
使用该函数的正确方式是调用该函数,并将参数指定为 tcp_sndbuf()获得的最大字节数。如果函数返回 ERR_MEM,应
用程序应等待直到当前入队数据正确地被其他主机接受并重试。
- void tcp_sent(struct tcp_pcb *pcb,
err_t (* sent)(void *arg, struct tcp_pcb *tpcb,u16_t len))
Specifies the callback function that should be called when data has successfully been received
(i.e., acknowledged) by the remote host. The len argument passed to the callback function
gives the amount bytes that was acknowledged by the last acknowledgment.
指定当数据被远程主机成功接收时应调用的回调函数。传递给回调函数的 len 参数给出了在最后一次确认中确认的字节
数。
--- Receiving TCP data
--- 接收 TCP 数据
TCP data reception is callback based - an application specified callback function is called
when new data arrives. When the application has taken the data, it has to call the tcp_recved()
function to indicate that TCP can advertise increase the receive window.
TCP 数据接收是基于回调函数的——当新的数据到达时,应用程序指定的回调函数被调用。当应用程序接收数据完毕,必
须调用 tcp_recved()函数用于指示 TCP 通告可以增加新的接收窗口。
- void tcp_recv(struct tcp_pcb *pcb,
err_t (* recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err))
Sets the callback function that will be called when new data arrives. The callback function
will be passed a NULL pbuf to indicate that the remote host has closed the connection. If
there are no errors and the callback function is to return ERR_OK, then it must free the pbuf.
Otherwise, it must not free the pbuf so that lwIP core code can store it.
当新的数据到达时,设置被调用的回调函数。如果远程主机已关闭了连接,该 函 数 的 pbuf 参数将返回一个 NULL 空指针。
如没有错误,并且回调函数的该参数返回值为 ERR_OK,那么该函数必须释放 pbuf。否则,禁止释放 pbuf,以确保 LwIP
内核代码可以存储其值。
- void tcp_recved(struct tcp_pcb *pcb, u16_t len)