-
WSAAsyncSelect function
The WSAAsyncSelect function requests Windows message-based notification of network events for a socket.
Syntax
int WSAAsyncSelect( _In_ SOCKET s, _In_ HWND hWnd, _In_ unsigned int wMsg, _In_ long lEvent );
Parameters
- s [in]
-
A descriptor that identifies the socket for which event notification is required. - hWnd [in]
-
A handle that identifies the window that will receive a message when a network event occurs. - wMsg [in]
-
A message to be received when a network event occurs.窗口消息循环要接受的消息。
- lEvent [in]
-
A bitmask that specifies a combination of network events in which the application is interested.
Return value
If the WSAAsyncSelect function succeeds, the return value is zero, provided that the application‘s declaration of interest in the network event set was successful. Otherwise, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError.
成功返0,得到之前声明感兴趣的网络事件
失败返SOCKET_ERROR
Error code Meaning
A successful WSAStartup call must occur before using this function.
The network subsystem failed.
One of the specified parameters was invalid, such as the window handle not referring to an existing window, or the specified socket is in an invalid state.
A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
The descriptor is not a socket.Additional error codes can be set when an application window receives a message. This error code is extracted from the lParam in the reply message using theWSAGETSELECTERROR macro. Possible error codes for each network event are listed in the following table.
WSAGETSELECTERROR宏取lParam低字节,看窗口消息内的网络事件的具体错误
Event: FD_CONNECT
Error code Meaning WSAEAFNOSUPPORT Addresses in the specified family cannot be used with this socket. WSAECONNREFUSED The attempt to connect was rejected. WSAENETUNREACH The network cannot be reached from this host at this time. WSAEFAULT The namelen parameter is invalid. WSAEINVAL The socket is already bound to an address. WSAEISCONN The socket is already connected. WSAEMFILE No more file descriptors are available. WSAENOBUFS No buffer space is available. The socket cannot be connected. WSAENOTCONN The socket is not connected. WSAETIMEDOUT Attempt to connect timed out without establishing a connection. Event: FD_CLOSE
Error code Meaning WSAENETDOWN The network subsystem failed. WSAECONNRESET The connection was reset by the remote side. WSAECONNABORTED The connection was terminated due to a time-out or other failure. - Event: FD_ACCEPT
- Event: FD_ADDRESS_LIST_CHANGE
- Event: FD_GROUP_QOS
- Event: FD_OOB
- Event: FD_QOS
- Event: FD_READ
- Event: FD_WRITE
Error code Meaning WSAENETDOWN The network subsystem failed. Event: FD_ROUTING_INTERFACE_CHANGE
Error code Meaning WSAENETUNREACH The specified destination is no longer reachable. WSAENETDOWN The network subsystem failed. Remarks
The WSAAsyncSelect function is used to request that WS2_32.DLL should send a message to the window hWnd when it detects any network event specified by thelEvent parameter. The message that should be sent is specified by the wMsg parameter. The socket for which notification is required is identified by the s parameter.
WSAAsyncSelect 要WS2_32.DLL给窗口发消息,当检测到lEvent的时候发,发的是wMsg消息,s套接字被监察
The WSAAsyncSelect function automatically sets socket s to nonblocking mode, regardless of the value of lEvent. To set socket s back to blocking mode, it is first necessary to clear the event record associated with socket s via a call to WSAAsyncSelect with lEvent set to zero. You can then call ioctlsocket or WSAIoctl to set the socket back to blocking mode. For more information about how to set the nonblocking socket back to blocking mode, see the ioctlsocket and WSAIoctlfunctions.
WSAAsyncSelect 把套接字调成非阻塞,而不管你给的lEvent是什么。
要调回阻塞就要用WSAAsyncSelect 把IEvent置零。然后就可以用 ioctlsocket 或者 WSAIoctl 把套接字调成阻塞模式。
The lEvent parameter is constructed by using the bitwise OR operator with any value listed in the following table.
Value Meaning FD_READ Set to receive notification of readiness for reading. FD_WRITE Wants to receive notification of readiness for writing. FD_OOB Wants to receive notification of the arrival of OOB data. FD_ACCEPT Wants to receive notification of incoming connections. FD_CONNECT Wants to receive notification of completed connection or multipoint join operation. FD_CLOSE Wants to receive notification of socket closure. FD_QOS Wants to receive notification of socket Quality of Service (QoS) changes. FD_GROUP_QOS Wants to receive notification of socket group Quality of Service (QoS) changes (reserved for future use with socket groups). Reserved. FD_ROUTING_INTERFACE_CHANGE Wants to receive notification of routing interface changes for the specified destination(s). FD_ADDRESS_LIST_CHANGE Wants to receive notification of local address list changes for the socket protocol family. Issuing a WSAAsyncSelect for a socket cancels any previous WSAAsyncSelect or WSAEventSelect for the same socket. For example, to receive notification for both reading and writing, the application must call WSAAsyncSelect with both FD_READ and FD_WRITE, as follows:
关注的事件要一起设置在一个消息里
rc = WSAAsyncSelect(s, hWnd, wMsg, FD_READ|FD_WRITE);
It is not possible to specify different messages for different events. The following code will not work; the second call will cancel the effects of the first, and onlyFD_WRITE events will be reported with message wMsg2:
不要分开去设置在不同消息但又是相同的套接字里。。。
rc = WSAAsyncSelect(s, hWnd, wMsg1, FD_READ); rc = WSAAsyncSelect(s, hWnd, wMsg2, FD_WRITE);
To cancel all notification indicating that Windows Sockets should send no further messages related to network events on the socket, lEvent is set to zero.
rc = WSAAsyncSelect(s, hWnd, 0, 0); 这要就不发网络事件了 Although WSAAsyncSelect immediately disables event message posting for the socket in this instance, it is possible that messages could be waiting in the application message queue. Therefore, the application must be prepared to receive network event messages even after cancellation. Closing a socket withclosesocket also cancels WSAAsyncSelect message sending, but the same caveat about messages in the queue still applies. 虽然你这样取消了发送或者说对网络事件的监听,但是之前遗留在Window消息队列里的网络消息还是有效的,也就是随后将根据队列顺序发给窗口,这是就造成了取消之后,窗口仍然会收到网络消息的情况。
WSAAsyncSelect function (Windows)
时间: 2024-10-07 01:06:54
WSAAsyncSelect function (Windows)的相关文章
获取当前 Windows 的安装序列号
Dim s s = InputBox("当前Windows系统序列号为:", "Windows序列号", GetWindowsSN) WScript.Quit '取得当前Windows序列号函数 Function GetWindowsSN() Const HKEY_LOCAL_MACHINE = &H80000002 strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion" s
windows log 打印语句
1.格式化字符串(Writes formatted data to the specified string) wchar_t szMessage[260]; PWSTR pszFunction = L“Hello world !”: DWORD dwError = GetLastError(); StringCchPrintfW(szMessage, ARRAYSIZE(szMessage),L"%s failed w/err 0x%08lx", pszFunction, dwErr
Windows API参考大全新编
书名:新编Windows API参考大全 作者:本书编写组 页数:981页 开数:16开 字数:2392千字 出版日期:2000年4月第二次印刷 出版社:电子工业出版社 书号:ISBN 7-5053-5777-8 定价:98.00元 内容简介 作为Microsoft 32位平台的应用程序编程接口,Win32 API是从事Windows应用程序开发所必备的.本书首先对Win32 API函数做完整的概述:然后收录五大类函数:窗口管理.图形设备接口.系统服务.国际特性以及网络服务:在附录部分,讲解如何
看到关于socket非阻塞模式设置方式记录一下。
关于socket的阻塞与非阻塞模式以及它们之间的优缺点,这已经没什么可言的:我打个很简单的比方,如果你调用socket send函数时: 如果是阻塞模式下: send先比较待发送数据的长度len和套接字s的发送缓冲的长度,如果len大于s的发送缓冲区的长度,该函数返回SOCKET_ERROR:如果len小于或者等于s的发送缓冲区的长度,那么send先检查协议是否正在发送s的发送缓冲中的数据,如果是就等待协议把数据发送完,如果协议还没有开始发送s的发送缓冲中的数据或者s的发送缓冲中没有数据,那么
Active Directory participation features and security extensions
Participation in the Active Directory Samba 3.0 series, as well as the OS since Windows 2000, is possible to participate in the Active Directory domain using Kerberos authentication. Because I think people often are interested, let's explain specific
Lua中的元表与元方法
前言 元表对应的英文是metatable,元方法是metamethod.我们都知道,在C++中,两个类是无法直接相加的,但是,如果你重载了“+”符号,就可以进行类的加法运算.在Lua中也有这个道理,两个table类型的变量,你是无法直接进行“+”操作的,如果你定义了一个指定的函数,就可以进行了.那这篇博文就是主要讲的如何定义这个指定的函数,这个指定的函数是什么?希望对学习Lua的朋友有帮助. Lua是怎么做的? 通常,Lua中的每个值都有一套预定义的操作集合,比如数字是可以相加的,字符串是可以连
字符处理函数
首部 function AnsiResemblesText(const AText, AOther: string): Boolean; $[StrUtils.pas 功能 返回两个字符串是否相似 说明 ANSI(American National Standards Institute)美国国家标准协会;不区分大小写 参考 function StrUtils.SoundexProc; var StrUtils.AnsiResemblesProc
Lua语言基础汇总(8) -- Lua中的元表与元方法
前言 元表对应的英文是metatable,元方法是metamethod.我们都知道,在C++中,两个类是无法直接相加的,但是,如果你重载了“+”符号,就可以进行类的加法运算.在Lua中也有这个道理,两个table类型的变量,你是无法直接进行“+”操作的,如果你定义了一个指定的函数,就可以进行了.那本文就是主要讲的是如何定义这个指定的函数,这个指定的函数是什么?希望对学习Lua的朋友有帮助. Lua是怎么做的? 通常,Lua中的每个值都有一套预定义的操作集合,比如数字是可以相加的,字符串是可以连接
聊聊Python ctypes 模块(转载)
https://zhuanlan.zhihu.com/p/20152309?columnSlug=python-dev 作者:Jerry Jho链接:https://zhuanlan.zhihu.com/p/20152309来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 摘要:模块ctypes是Python内建的用于调用动态链接库函数的功能模块,一定程度上可以用于Python与其他语言的混合编程.由于编写动态链接库,使用C/C++是最常见的方式,故ctypes最常