详情参考: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 code Meaning
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.

转载于:https://www.cnblogs.com/jasonsword/p/7531866.html

WSARecv() 函数使用解析相关推荐

  1. 语言中拟合函数 计算aic_Go语言函数深度解析(中)

    上回函数深度解析给大家聊了一些函数的基本知识,不知道还有没有人记得,不记得赶紧回去复习! 他们是 go语言中函数的基本原理 单/多个同/不同类型参数 单/多个同/不同类型返回值 值传递,引用传递 函数 ...

  2. c语言的point函数,C语言中friend友元函数详细解析

    C语言中friend友元函数详细解析 友元函数是可以直接访问类的私有成员的非成员函数.它是定义在类外的普通函数,它不属于任何类,但需要在类的定义中加以声明,声明时只需在友元的名称前加上关键字frien ...

  3. php 立即执行函数,关于javascrip的立即执行函数的解析

    这篇文章主要介绍了关于javascrip的t立即执行函数的解析,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 概念: 立即执行函数顾名思义就是函数定义好之后立即执行. 函数表达式方式: ...

  4. C++函数重载解析细节

    Copyright(C)<C++从入门到精通-经典完整版> 函数重载解析细节 函数重载解析过程有三个步骤这些步骤可以总结如下: 1 确定为该调用而考虑的候选函数以及函数调用中的实参表属性 ...

  5. Python中sort和sorted函数代码解析

    Python中sort和sorted函数代码解析 本文研究的主要是Python中sort和sorted函数的相关内容,具体如下. 一.sort函数 sort函数是序列的内部函数 函数原型: L.sor ...

  6. Linux进程调用execve,linux内核系统调用函数do_execve()解析实例源码

    linux内核系统调用函数do_execve()解析,彻底解析内核调用用户空间代码入口函数do_execve() sys_execve() –> do_execve() /usr/src/lin ...

  7. Python文本变量与函数的解析执行,增强自动化测试数据驱动

    关注我,每天分享软件测试技术干货.面试经验,想要领取测试资料.进入软件测试学习交流群的可以直接私信我哦~~ 我们在使用Python进行自动化测试或者测试脚本开发时,通常会在代码中融入数据驱动设计,以便 ...

  8. main主函数参数解析

    默认的main函数参数 int main(int argc, char *argv[]) {// 主函数的代码逻辑return 0; } 其中,int 是主函数的返回值类型,主函数执行完后会返回一个整 ...

  9. 【C语言】自定义函数例题解析

    C语言函数例题解析 C语言函数解析 C语言函数例题解析 值传递 自定义函数求解一元二次方程 自定义函数计算给定日期是该年的第几天 地址传递 自定义函数对N个数排序 自定义函数对字符串的处理 值传递 自 ...

最新文章

  1. python什么时候用框架_Python 中三大框架各自的应用场景
  2. 3种时间序列混合建模方法的效果对比和代码实现
  3. 滇西应用技术大学计算机专业录取分数线,滇西应用技术大学录取分数线2021是多少分(附历年录取分数线)...
  4. Machine Learning week 6 quiz: Advice for Applying Machine Learning
  5. python爬虫表格中清除空格_爬虫清洗:python strip()函数 去空格\n\r\t函数的用法
  6. mysql对库授权alter_mysql 数据库授权(给某个用户授权某个数据库)
  7. Laravel中数据库的操作
  8. [教程]win10 ,ubuntu双系统安装避坑指南
  9. Java学习之面板与布局管理器
  10. 贪心 赛码 1001 Movie
  11. java做节奏大师,《节奏大师》高手必修之路 亲测攻略_iOS游戏频道_97973手游网
  12. windows下如何制作和应用数字签名证书 全流程
  13. 隔行换色+删除+批量删除+排序+模糊查询+修改+添加
  14. NMS(非极大值抑制)
  15. 【§美女杨颖win7电脑主题下载§系统美化】
  16. C# 打印PDF文件之使用不同打印机打印所有页面或部分页面
  17. 7月,带你阅读图灵原创图书以及上榜新书
  18. 一句话突破上传限制一句话_一句话的基础
  19. textview中划线效果
  20. MySQL数据库体系 全面梳理(漂亮简洁的思维导图)

热门文章

  1. 【牛客 - 315C】排列(思维,贪心,同优则立证明法)
  2. *【HDU - 6333】Problem B. Harvest of Apples (莫队,逆元,组合数学)(这样预处理正确吗?)
  3. 【CodeForces - 580D】Kefa and Dishes (状压dp)
  4. 13.Data Leakage
  5. unsigned int mysql_mysql 中int类型字段unsigned和signed的探索
  6. 助记词创建以太坊钱包源码_墨客科普 | MOAC区块链钱包账号管理
  7. html淡化效果,jQuery实现基本淡入淡出效果的方法详解
  8. shell从oracle中获取变量,shell 如何读取环境变量的值
  9. sam格式的结构和意义_各种格式的练字本,对写字真有帮助吗
  10. Python- 解决PIP下载安装速度慢