Apple GCC 中的 WSAAsyncSelect() 函数类似物是什么?
请告诉我将 WSAAsyncSelect() 函数移植到 GCC 的最轻松的方法...
Please tell me the most painless way of porting WSAAsyncSelect() function to GCC...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
虽然
select()
和pselect()
可能适用于您的应用程序,但它们与WSAAsyncSelect()
非常不同。这些函数使您可以在非阻塞套接字或套接字集合上进行受控阻塞。poll()
也是如此。另一方面,Winsock 的异步套接字永远不会阻塞。还有大量的异步通知问题,您的代码无疑依赖于它。
我不相信 OS X 上有任何本机 API 可以提供类似的行为。然而,建立这样的东西是可能的。谷歌搜索了一下CocoaAsyncSocket。
如果您不想依赖第三方库,我建议在 Cocoa 的 CFSocket,就像 CocoaAsyncSocket 开发人员所做的那样,如果您要移植 GUI 程序,而不是深入研究
select()
。对于所有事情都使用单一的开发框架是有道理的。如果您需要代码跨平台,wxWidgets 库具有 wxSockets* 类层次结构,它模拟 Winsock 异步套接字机制。总体而言,wxWidgets 的结构与 MFC 非常相似,如果您熟悉 MFC,则可以轻松移植。
While
select()
andpselect()
may work for your application, they are very much not the same thing asWSAAsyncSelect()
. Those functions let you do controlled blocking on an otherwise non-blocking socket, or collection of sockets. The same goes forpoll()
.Winsock's asynchronous sockets, on the other hand, do not block, ever. There's also the large matter of async notifications, which your code doubtless depends on.
I do not believe there are any native APIs on OS X that provide similar behavior. However, it's possible to build up such a thing. A little Googling turned up CocoaAsyncSocket.
If you would rather not depend on third-party libraries, I suggest building up something on top of Cocoa's CFSocket, as the CocoaAsyncSocket developers did, if you will be porting over a GUI program, rather than dig down to core functions like
select()
. There's something to be said for using a single development framework for everything.If you need your code to be cross-platform, the wxWidgets library has the wxSockets* class hierarchy, which emulates the Winsock async socket mechanism. Overall, wxWidgets is structured much like MFC, which eases porting if you're familiar with that.
我相信您想看看 select 函数
I believe you want to look at the select function
我使用 pselect 函数。
I use pselect function.