为什么WSARecvMsg函数实现为一个函数指针并且可以重用这个指针? [英] Why is the WSARecvMsg function implemented as a function pointer and can this pointer be reused?

查看:578
本文介绍了为什么WSARecvMsg函数实现为一个函数指针并且可以重用这个指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WSARecvMsg 函数这里要求您检索一个指向它的函数指针,如下面的引号所示:

The WSARecvMsg function as described here requires that you retrieve a function pointer to it as shown in the following quote:


注意WSARecvMsg函数的函数指针必须在运行时通过调用指定SIO_GET_EXTENSION_FUNCTION_POINTER操作码的WSAIoctl函数来获取。

Note The function pointer for the WSARecvMsg function must be obtained at run time by making a call to the WSAIoctl function with the SIO_GET_EXTENSION_FUNCTION_POINTER opcode specified.

是否有特定的原因?
在使用这个函数时,我打算在引导时检索函数指针,然后从头开始使用它。这种方法有什么问题吗?任何关于函数的改变,这意味着我们需要重新获取这个指针,我们怎么知道是否是这种情况?

Is there a specific reason for this? In the use of this function I intend to retrieve the function pointer at boot time then use it consistently from then on. Is there anything wrong with this approach? Can anything about the function change which would mean we need to re-acquire this pointer and how can we know if this is the case?

推荐答案

WSARecvMsg()文件


注意此函数是Windows Sockets规范的 Microsoft特定扩展

根据 WSAIoctrl()文档


SIO_GET_EXTENSION_FUNCTION_POINTER(操作码设置:O,I,T == 1)

检索指向相关服务提供程序支持的指定扩展功能的指针。输入缓冲区包含全局唯一标识符(GUID),其值标识所讨论的扩展功能。指向所需函数的指针在输出缓冲区中返回。扩展功能标识符由服务提供商提供商建立,并应包含在描述扩展功能能力和语义的供应商文档中。

SIO_GET_EXTENSION_FUNCTION_POINTER (opcode setting: O, I, T==1)
Retrieve a pointer to the specified extension function supported by the associated service provider. The input buffer contains a globally unique identifier (GUID) whose value identifies the extension function in question. The pointer to the desired function is returned in the output buffer. Extension function identifiers are established by service provider vendors and should be included in vendor documentation that describes extension function capabilities and semantics.

,微软的提供商是唯一安装的提供商。然而,第三方提供商确实存在(定制TCP堆栈等),并且也可以安装。根据
WSADATA 文档 WSAStartup()

On most systems, Microsoft's provider is the only provider installed. However, 3rd party providers do exist (custom TCP stacks, etc) and may be installed as well. Per the WSADATA documentation for WSAStartup():


Windows Sockets的架构在版本2中已更改为支持多个提供程序,WSADATA不再适用于单个供应商的堆栈。

the architecture of Windows Sockets changed in version 2 to support multiple providers, and WSADATA no longer applies to a single vendor's stack.

其进一步支持:

Windows Sockets 2架构

特定于提供程序的扩展机制

code> socket(),您不能控制使用哪个提供程序。当您使用 WSASocket()创建套接字时,您可以可选通过 lpProtocolInfo 参数。

When you create a socket using socket(), you don't have any control over which provider is used. When you create a socket using WSASocket() instead, you can optionally specify a specific provider via the lpProtocolInfo parameter.

WSARecvMsg()仅在Microsoft的提供程序中可用,因此必须通过它与同一提供者相关联的 SOCKET WSAIoctrl()可用于向 SOCKET 所属的提供程序发送命令。因此,通过使用 SIO_GET_EXTENSION_FUNCTION_POINTER ,您可以确保 WSARecvMsg()(或任何其他供应商特定的函数)指定 SOCKET 的提供者,因此与 SOCKET 兼容。

WSARecvMsg() is only available in Microsoft's provider, and as such you must pass it a SOCKET that is associated with the same provider. WSAIoctrl() can be used to send commands to the provider that a SOCKET belongs to. So, by using SIO_GET_EXTENSION_FUNCTION_POINTER, you ensure that WSARecvMsg() (or any other vendor-specific function) is supported by the provider of the specified SOCKET and thus is compatible with that SOCKET.

Microsoft的提供者通过 WSAIoctrl() 1 提供的其他Microsoft特定功能是:

The other Microsoft-specific functions that are provided by Microsoft's provider via WSAIoctrl()1 are:


  • AcceptEx()

  • ConnectEx ()

  • DisconnectEx()

  • GetAcceptExSockAddrs()

  • TransmitFile()

  • TransmitPackets()

  • WSASendMsg()

  • AcceptEx()
  • ConnectEx()
  • DisconnectEx()
  • GetAcceptExSockAddrs()
  • TransmitFile()
  • TransmitPackets()
  • WSASendMsg()

一旦您检索了指向供应商特定函数的指针,就可以根据需要重用指针,只要提供者保持加载在内存中第一次调用 WSAStartup()和最后一次调用 WSACleanup()

Once you have retrieved a pointer to a vendor-specific function, you can reuse the pointer as much as you want as long as the provider stays loaded in memory (between the first call to WSAStartup() and the last call to WSACleanup()) and you pass it a SOCKET that belongs to that provider.

1 :每提供程序特定的扩展机制

在Windows Vista及更高版本中,新的Winsock系统扩展直接从Winsock DLL导出,因此不需要WSAIoctl函数来加载这些扩展。 Windows Vista及更高版本中可用的新扩展功能包括从Ws2_32.dll导出的 WSAPoll WSASendMsg 函数。

On Windows Vista and later, new Winsock system extensions are exported directly from the Winsock DLL, so the WSAIoctl function is not needed to load these extensions. The new extension functions available on Windows Vista and later include the WSAPoll and WSASendMsg functions that are exported from Ws2_32.dll.

这篇关于为什么WSARecvMsg函数实现为一个函数指针并且可以重用这个指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆