码迷,mamicode.com
首页 > 其他好文 > 详细

WSARecv() 函数使用解析

时间:2017-09-16 19:03:23      阅读:768      评论:0      收藏:0      [点我收藏+]

标签:msdn   trail   aes   sdn   ping   sock   tag   long   set   

详情参考:https://msdn.microsoft.com/en-us/library/windows/desktop/ms741688(v=vs.85).aspx

简述

The WSARecv function receives data from a connected socket or a bound connectionless socket.

The WSARecv function provides some additional features compared with the standard recv function in three important areas:

  • It can be used in conjunction with overlapped sockets to perform overlapped recv operations.
  • It allows multiple receive buffers to be specified making it applicable to the scatter/gather type of I/O.
  • The lpFlags parameter is used both on input and returned on output, allowing applications to sense the output state of the MSG_PARTIAL flag bit. However, the MSG_PARTIAL flag bit is not supported by all protocols.

WSARecv 和标准的recv相比有以下扩展特性:

  1.可以和重叠sockets结合来使用重叠接收操作

  2.允许使用多个接收buffer来应对分散/聚合型IO

  3.lpFlags参数可以用在输入和输出上,允许应用感知输出状态的MSG_PARTIAL 标志位

函数原型

int WSARecv(
  _In_    SOCKET                             s,
  _Inout_ LPWSABUF                           lpBuffers,
  _In_    DWORD                              dwBufferCount,
  _Out_   LPDWORD                            lpNumberOfBytesRecvd,
  _Inout_ LPDWORD                            lpFlags,
  _In_    LPWSAOVERLAPPED                    lpOverlapped,
  _In_    LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);

参数

s: 套接字句柄

lpBuffers: 与Recv函数不同 这里需要一个由WSABUF结构构成的数组

dwBufferCount: 数组中WSABUF结构的数量

lpNumberOfBytesRecvd: 如果接收操作立即完成,这里会返回函数调用所接收到的字节数

lpFlags:A pointer to flags used to modify the behavior of the WSARecv function call. For more information, see the Remarks section.

lpOverlapped:WSAOVERLAPPED structure

lpCompletionRoutine: A pointer to the completion routine called when the receive operation has been completed (ignored for nonoverlapped sockets).

返回值

Error codeMeaning
WSAECONNABORTED

The virtual circuit was terminated due to a time-out or other failure.

WSAECONNRESET

For a stream socket, the virtual circuit was reset by the remote side. The application should close the socket as it is no longer usable. For a UDP datagram socket, this error would indicate that a previous send operation resulted in an ICMP "Port Unreachable" message.

WSAEDISCON

Socket s is message oriented and the virtual circuit was gracefully closed by the remote side.

WSAEFAULT

The lpBuffers parameter is not completely contained in a valid part of the user address space.

WSAEINPROGRESS

A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.

WSAEINTR

The (blocking) call was canceled by the WSACancelBlockingCall function.

WSAEINVAL

The socket has not been bound (for example, with bind).

WSAEMSGSIZE

The message was too large to fit into the specified buffer and (for unreliable protocols only) any trailing portion of the message that did not fit into the buffer has been discarded.

WSAENETDOWN

The network subsystem has failed.

WSAENETRESET

For a connection-oriented socket, this error indicates that the connection has been broken due to keep-alive activity that detected a failure while the operation was in progress. For a datagram socket, this error indicates that the time to live has expired.

WSAENOTCONN

The socket is not connected.

WSAENOTSOCK

The descriptor is not a socket.

WSAEOPNOTSUPP

MSG_OOB was specified, but the socket is not stream-style such as type SOCK_STREAM, OOB data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only send operations.

WSAESHUTDOWN

The socket has been shut down; it is not possible to call WSARecv on a socket after shutdown has been invoked with how set to SD_RECEIVE or SD_BOTH.

WSAETIMEDOUT

The connection has been dropped because of a network failure or because the peer system failed to respond.

WSAEWOULDBLOCK

 

Windows NT:  Overlapped sockets: there are too many outstanding overlapped I/O requests. Nonoverlapped sockets: The socket is marked as nonblocking and the receive operation cannot be completed immediately.

WSANOTINITIALISED

A successful WSAStartup call must occur before using this function.

WSA_IO_PENDING

An overlapped operation was successfully initiated and completion will be indicated at a later time.

WSA_OPERATION_ABORTED

The overlapped operation has been canceled due to the closure of the socket.

 

 

WSARecv() 函数使用解析

标签:msdn   trail   aes   sdn   ping   sock   tag   long   set   

原文地址:http://www.cnblogs.com/jasonsword/p/7531866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!