UDT::recv 函数

来源:互联网 发布:mac电脑铃声剪辑软件 编辑:程序博客网 时间:2024/06/13 03:20

recv

The recv method reads certain amount of data into a local memory buffer.

int recv(
  UDTSOCKET u,
  char* buf,
  int len,
  int flags
);
Parameters
u
[in] Descriptor identifying a connected socket.
buf
[out] The buffer used to store incoming data.
len
[in] Length of the buffer.
flags
[in] Ignored. For compatibility only.

Description

The recv method reads certain amount of data from the protocol buffer. If there is not enough data in the buffer, recv only reads the available data in the protocol buffer and returns the actual size of data received. However, recv will never read more data than the buffer size indicates by len.

In blocking mode (default), recv waits until there is some data received into the receiver buffer. In non-blocking mode, recv returns immediately and returns error if no data available.

If UDT_RCVTIMEO is set and the socket is in blocking mode, recv only waits a limited time specified by UDT_RCVTIMEO option. If there is still no data available when the timer expires, error will be returned. UDT_RCVTIMEO has no effect for non-blocking socket.


以上是UDT文档的解释。


这里,在默认情况下:用SOCK_STREAM方式,接收为blocking mode,可以保证接收安顺序,完成的接收数据,但是一个大的数据包一层 UDT::send, 这里就很可能会分包按顺序发送,分包大小不定, 同理,也就是,接收端会按顺序不定大小的接收一个大的数据包。


所以,如果处理大数据,还是要自定义结构处理。