WSARecv() 函数使用解析

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

时间: 2024-10-14 05:31:23

WSARecv() 函数使用解析的相关文章

关于函数的解析顺序

<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>函数的解析顺序</title> </head> <body> <script type="text/javascript"> function f(){ return 1; } alert(f()); //4,说明第一个函数被第四个函数覆盖 v

CImageList类Create函数参数解析

前面提到了CImageList类的Create(...)函数,虽然MSDN上已经有所解释,但仍有网友问到参数的具体含义,下面就我的理解,对参数进行一次轻量级的剖析 函数原型(其他重载函数请参看msdn):   BOOL Create( int cx, int cy, UINT nFlags, int nInitial, int nGrow ); cx ,cy: 图片的实际像素宽与高,没有问题 nFlags:创建图像列表的类型,包括4/8/16/24/32/位色, nInitial : 创建Ima

C++的那些事:函数全解析

一.函数的结构 函数在C++中可能出现在三种地方,一是函数的定义,它包括了如上图的结构:二是函数的声明,它与函数的定义相比,没有了函数体部分:三则是函数的调用.当然,不同的函数定义可以还会稍有不同,比如类的成员函数.内联函数等.这里我们主要讨论函数的调用时需要注意的一些问题. 二.参数传递 我们将函数定义或声明里的参数叫形参,而在调用函数时传入的参数叫实参.那么根据形参类型的不同,有几下形式的参数传递. 1,非引用形参 1)普通的内置类型 普通非引用类型的参数通过复制对应的实参实现形参的初始化.

cmake函数参数解析

最近在迁移公司的make系统到cmake上,发现cmake的function参数很奇怪.例如,如果我们向一个function传递list作为参数,在function中,形参会变成如下状况: set(SRC) list(APPEND SRC a.cpp b.cpp) list(APPEND SRC c.cpp d.cpp) function(tst_arguments src_list) message("src_list = "${src_list}) endfunction() me

Mysql研究之MySQL常用内置函数完全解析

说明: 1)可以用在SELECT/UPDATE/DELETE中,及where,orderby,having中 2)在函数里将字段名作为参数,变量的值就是字段所对应的每一行的值. 3)在程序设计语言如C++中提供的函数,MySQL大部分也提供了,关于MySQL函数的完整信息,请参阅<MySQL参考手册> 一.字符串函数[比较常用,需要掌握] 1. concat(s1,s2,…,sn) #把传入的参数连接成一个字符串 selectconcat(‘abc’,’def’); selectconcat(

php 函数strtr 替换函数实例解析 strtr 速度比较快

先来看看这个php字符串替换函数 PHP字符串替换函数strtr()的两种状态 strtr(string,from,to) 或者strtr(string,array) 首先针对PHP字符串替换函数strtr()第一种方式 我们看看下面的举例: <?php echo strtr("I Love you","Lo","lO"); ?> 得到的结果是 I lOve yOu 这个结果提醒我们 1.strtr它是区分大小写的 2.PHP字符串替

discuz 使模板中的函数不解析 正常使用

<!--{if $_GET['zcdw']=="baxi"}--><!--{eval $duiwuxinxi = "巴西队";}--><!--{elseif $_GET['zcdw']=="deguo"}--><!--{eval $duiwuxinxi = "德国队";}--><!--{elseif $_GET['zcdw']=="agenting"}-

Generator函数语法解析

转载请注明出处: Generator函数语法解析 Generator函数是ES6提供的一种异步编程解决方案,语法与传统函数完全不同.以下会介绍一下Generator函数. 写下这篇文章的目的其实很简单,是想梳理一下自己对于Generator的理解,同时呢,为学习async函数做一下知识储备. Generator函数 基本概念 yield表达式 next方法 next方法的参数 yield*表达式 与Iterator接口的关系 for...of循环 作为对象属性的Generator函数 Gener

0143 JavaScript预解析:概念、变量预解析、函数预解析、函数表达式声明函数问题

4.1 预解析的相关概念 JavaScript 代码是由浏览器中的 JavaScript 解析器来执行的. JavaScript 解析器在运行 JavaScript 代码的时候分为两步:预解析 和 代码执行. 预解析:在当前作用域下, JS 代码执行之前,浏览器会默认把带有 var 和 function 声明的变量在内存中进行提前声明或者定义. [提升到当前作用域的最顶部.] 代码执行: 从上到下执行JS语句. 预解析会把变量和函数的声明在代码执行之前执行完成.[声明提前,赋值留在原地.] 4.