WSASend()的评述

作者&投稿:南璧 (若有异议请与网页底部的电邮联系)
WSASend()的返回值~

若无错误发生且发送操作立即完成,则WSASend()函数返回0。这时,完成例程(Completion Routine)应该已经被调度,一旦调用线程处于alertable状态时就会调用它。否则,返回SOCKET_ERROR 。通过WSAGetLastError获得详细的错误代码。WSA_IO_PENDING 这个错误码(其实表示没有错误)表示重叠操作已经提交成功(就是异步IO的意思了),稍后会提示完成(这个完成可不一定是发送成功,没准出问题也不一定)。其他的错误代码都代表重叠操作没有正确开始,也不会有完成标志出现。 Error code Meaning WSAEACCES The requested address is a broadcast address, but the appropriate flag was not set. 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 useable. For a UDP datagram socket, this error would indicate that a previous send operation resulted in an ICMP Port Unreachable message. WSAEFAULT ThelpBuffers,lpNumberOfBytesSent,lpOverlapped,lpCompletionRoutineparameter is not totally contained in a valid part of the user address space. WSAEINTR A blocking Windows Socket 1.1 call was canceled throughWSACancelBlockingCall. WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. WSAEINVAL The socket has not been bound withbindor the socket is not created with the overlapped flag. WSAEMSGSIZE The socket is message oriented, and the message is larger than the maximum supported by the underlying transport. WSAENETDOWN The network subsystem has failed. WSAENETRESET For a stream socket, the connection has been broken due to keep-alive activity detecting a failure while the operation was in progress. For a datagram socket, this error indicates that the time to live has expired. WSAENOBUFS The Windows Sockets provider reports a buffer deadlock. 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, MSG_PARTIAL is not supported, or the socket is unidirectional and supports only receive operations. WSAESHUTDOWN The socket has been shut down; it is not possible toWSASendon a socket aftershutdownhas been invoked with how set to SD_SEND or SD_BOTH. WSAEWOULDBLOCK Windows NT:Overlapped sockets: There are too many outstanding overlapped I/O requests. Nonoverlapped sockets: The socket is marked as nonblocking and the send operation cannot be completed immediately. WSANOTINITIALISED A successfulWSAStartupcall 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, the execution of the SIO_FLUSH command inWSAIoctl, or the thread that initiated the overlapped request exited before the operation completed. For more information, see the Remarks section.

和文件IO差不多,文件IO如果不会,就先文件IO吧。
简单说,就是把消息发出去,然后返回,不管实际消息是不是发出去了。然后在程序某个地方使用多种方案(如WaitForSingleObject,GetOverlappedResult,重叠IO完成例程等)来查看消息发出去了没有。

但SOCKET的重叠IO还要涉及到很多方面的,在实际编程时,不像文件IO,对程序的结构模型必须有非常高的要求,否则即使能编译通过,实际使用会出现很多问题。
譬如发消息时为什么要立刻返回,究竟在什么地方查看发消息的结果,如果消息没发出去又该如何处理等必须根据要实现的程序功能有个明确的认识。
这东西主要还是编程经验,写的程序多了,接触过了各种结构模型,才能知道各个模型的特点,并灵活使用,较难!
建议买本书看看吧!

WSASend覆盖标准的send函数,并在下面两个方面有所增强:
>它可以用于overlapped socket(重叠socket)上以进行重叠发送的操作(简单地理解为就是异步send也可以了)
>它可以一次发送多个缓冲区中的数据来进行集中写入。应该相当于unix上的writev,好处看来是避免Nagle算法。
WSASend用于在一个面向连接的socket(第一个参数s)上发出的数据。It can also be used, however, onconnectionless sockets that have a stipulated default peer address established through theconnectorWSAConnectfunction.
对于overlapped sockets来说 (通过WSASocket函数,用WSA_FLAG_OVERLAPPED标示创建),发送消息时使用的是重叠IO(overlapped I/O), 除非lpOverlapped and lpCompletionRoutine 都是NULL. 这时, 这个socket被视为非重叠的socket. 当所有的缓冲区都被发送完成了,将会执行一个动作来表示操作完成,这个动作可能是调用完成例程或者是引发一个event对象。如果操作没有立即完成, 最终的完成状态通过完成例程或者 WSAGetOverlappedResult得到
对于非重叠的sockets来说, 最后两个参数(lpOverlapped, lpCompletionRoutine) 被忽略,WSASend 和 send具有同样的语意。数据从用户缓冲区拷贝到发送缓冲区中(应该是指系统的socket堆栈)。如果socket是非阻塞的又是同时是面向流的(简单地理解为tcp), 同时发送缓冲区没有足够的大小, WSASend将只发送用户缓冲区中的部分数据。 如果同样缓存大小,而socke是阻塞的socket, WSASend将阻塞直到用户所有的数据被发送成功。
Note socket配置项SO_RCVTIMEO and SO_SNDTIMEO只能被用于阻塞的sockets。
lpBuffers这个参数是一个指针,它指向一个WSABUF结构的数组。这个数组可以是瞬态的(transient)。所谓瞬态的含义如下:如果这个操作时重叠的操作,服务提供者有责任在这个调用返回之前保存WSABUF数组。这允许用户的应用使用一个基于栈的WSABUF数组。就是说你可以定义一个局部变量,当wsasend返回后如果是重叠IO呢,你的函数局部变量已经被销毁了(例如你的函数已经返回了)。系统实际上还没发送数据呢,那你不要担心,系统会保存这个数组的副本。
对于面向消息的socket(UDP?), 不要超过下层协议的最大消息大小,这个值可以通过SO_MAX_MSG_SIZE这个socket配置项得到。如果数据太长无法原子地发送,返回WSAEMSGSIZE, 没有数据发送成功。
Windows Me/98/95:TheWSASendfunction does not support more than 16 buffers.
NoteWSASend的成功完成不代表数据已经发送成功。




您说SAS中用end=last,然后用if last来判断是否为最后一个观测值,那如何...
_N_ _ERROR_ FIRST. LAST. END 等等 但是是没有begin(或者start)的比方说如果你要取第一条你可以这样写 Data A;Set Sashelp.Class End=Last;Tot+Age;If _N_>1 Then stop;Run;此外,end 是作为当前是否到达文件底部的标志,也就是说只有当前读入的记录是最后一条的时候end 对应的...

SAS中 end=last是什么意思
就是对数据集最后一条记录打个标记,以判断是否到达最后一条观测.SAS 是行读入机制,如果读到最后一行这个标记为1否则为0 例如:Data A;Set Sashelp.Class End=Last;Tot+Age;If Last Then Put Tot=;Run;Sashelp 中的Class有19条记录,以上程序实行的是对所有记录的age字段求和,并在最后一条的时候...

统计软件SAS 多变量分组(两个)排序后,如何找到亚组中的最小值,并重新...
先把分组好的落到一张新表假设表名test,先聚合得出最小的值,然后再用左关联去替换就可以得到需要的值了。在SAS里可以直接用proc步调用这段SQL.select a.col1,a.col2,case when a.col3=b.col3 then '' else to_char(a.col3) end casefrom test a left join(select col1,col2,min(col...

英文奥数 一定追加!(5题 行程问题)
1.设全程X米,列方程得:(X\/30+25)×24=X 解得,X=3000 2.(10.8+4.8)×5\/60=1.3km 1.3÷10.8=13\/108h 3.设全程X千米,列方程得:X\/40+3=X\/20 解得X=120 4.设全程X米,列方程得:X\/6=50+(25×50+X)\/25 解得 X=1500\/19 5.设B行20米需时间为T,则...

跪求谁も知らないハッピーエンド(无人知晓的happy end) 罗马音...
wa motomezu ni.Honno sasayaka na shiawase,wakachiatte aruite kimashita.Ano hi deaeta koto, tagai o aishita koto.Doramachikku na dekigoto nado nozonde nai keredo.Dōka futari ni sotto odayaka na mainichi o.Saigo no nemuri ni tsuku hi made.Oyasumi. Medetashi, medetashi.

nine的序数词(英文表达)
Distractionscanbeamajorproductivitykiller.Tostayfocused,eliminateasmanydistractionsaspossible.Turnoffyourphonenotifications,closeunnecessarytabsonyourcomputer,andfindaquietworkspacewhereyoucanconcentrate.Step4:TakeBreaks Whileitmayseemcounterintuitive,takingbreakscanactuallyimproveyourproductivity.Takingshortbreaks...

神思者的《Aphrodite》 歌词
歌曲名:Aphrodite 歌手:神思者 专辑:Natural-The Very Best Of S.E.N.S.Ash - Aphrodite As dark falls On these shores Fell in love With Aphrodite Her dark power In my heart In my heart Feel it now her beauty never ends As dark falls On these shores On this earth Feel like ...

Minii Zahia(爱的眼泪)— 歌词是什么意思
歌词的大致意思是:暗恋一个女孩子 写信给她 但是遭到她的拒绝 心情很不好……一切只是道听涂说 继续学习的旅程 这世界好辽阔 但讯息却举手可得 让希望多一点 欢乐多一些 正面积极能量发挥 吸引力法则也许会自己作用。Aav eej hoyoroos mini zahia irjee…Uchigdur manai hamaatnii egch end aj...

求,七年级下(人教版)数学,(国标江苏版)的语文,英语的复习提纲
(2) 三角形三个内角的和等于180°。三角形的一个外角等于的它不相邻的两个内角的和。(3) 全等三角形的对应边相等,对应角相等。(4) 有三边对应相等的两个三角形全等(简写成“边边边”或“SSS”);有一个角和夹这个角的两边对应相等的两个三角形全等(简写成“边角边”或“SAS”);有...

SAS中 end=last是什么意思
SAS 是行读入机制,如果读到最后一行这个标记为1否则为0 例如:Data A;Set Sashelp.Class End=Last;Tot+Age;If Last Then Put Tot=;Run;Sashelp 中的Class有19条记录,以上程序实行的是对所有记录的age字段求和,并在最后一条的时候运行Put Tot= 语句,可以在log窗口查看.

曲阜市18846889968: WSASend()的简述 -
戏宣捷立: int WSASend ( SOCKET s,LPWSABUF lpBuffers DWORD dwBufferCount,LPDWORD lpNumberOfBytesSent,DWORD dwFlags,LPWSAOVERLAPPED lpOverlapped,LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); s:...

曲阜市18846889968: WSASend()的返回值 -
戏宣捷立: 若无错误发生且发送操作立即完成,则WSASend()函数返回0.这时,完成例程(Completion Routine)应该已经被调度,一旦调用线程处于alertable状态时就会调用它.否则,返回SOCKET_ERROR .通过WSAGetLastError获得详细的错误...

曲阜市18846889968: WSASend()的操作 -
戏宣捷立: Overlapped Socket I/O<br>如果重叠操作立即完成,WSASend返回0 同时设置lpNumberOfBytesSent指向的变量为发送的字节数.如果重叠操作成功初始化将稍后完成,WSASend返回 SOCKET_ERROR同时设置错误码为WSA_IO_PENDING. ...

曲阜市18846889968: 关于异步IO函数,WSASend和WSARecv的疑问
戏宣捷立: PER_IO 结构体里面呢? 我是菜鸟中的菜鸟,刚开始学套接字的异步IO , 你将sizeof(myWSABUF.buf)输入看看长度为多少?如果长度为8之对了一半,

曲阜市18846889968: IOCP 的WSASend与WSARecv问题 -
戏宣捷立: 采纳哦

曲阜市18846889968: html5 的video 怎么检测是否缓冲完毕 -
戏宣捷立: 首先要检测是否完全发送完毕了.WSASend是不是不需要检测是不是发了一部分,只需要调用一次WSASend,就可以放弃这几个缓冲的数据了

曲阜市18846889968: GetLastError和WSAGetLastError的区别 -
戏宣捷立: if(WSASend(PerHandleData->Socket, &(PerIoData->DataBuf), 1, &SendByts, Flags, &(PerIoData->Overlapped), NULL) == SOCKET_ERROR)//meiyou zhi xing 把中间回车符去掉即可!

曲阜市18846889968: 谈谈你心中的偶像即兴评述即兴评述案例与指导 案例十二讨论话题:谈谈你心中的偶像评述提示本题要评述的对象是"偶像",也就是考生崇拜并向往的人.... -
戏宣捷立:[答案] 想起你让我心跳加速,这对我是唯一重要的事

曲阜市18846889968: 播音主持考试最容易出那些即兴评述的话题? -
戏宣捷立: 播音主持专业艺考中存在的一些问题分析其实艺术类高考中存在的问题都是一些很普遍的问题,最重要的我觉得应该是语言方面的问题,这才是考生在考试当中站得住脚的最主要的优...

曲阜市18846889968: 求100 - 150字关于双十一网购热现象英文的评论 -
戏宣捷立: November 11 should be nothing special but an ordinary day. However it is a different day, it is a day recognized by most young people as the single's day. Although many would think this day is the day peoplle do something like western people do in ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网