BSD套接字兼容包装的Winsock吗? [英] BSD socket compatible wrapper around winsock?

查看:92
本文介绍了BSD套接字兼容包装的Winsock吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Linux应用程序移植到Windows.该应用程序不太复杂,使用所有相当标准的代码,几乎没有外部依赖项.主要依赖项是libelf(在mingw下可以很好地编译),pthreads(似乎有可用的win32版本)和套接字.主要问题是套接字... Windows提供了WinSock,但这与所有* nix所使用的BSD(Berkeley)套接字不是100%兼容.我想知道的是,是否有人在Windows上编写了一个包装程序来公开BSD套接字API,但在后端调用Winsock来简化移植?

I'm attempting to port a Linux application to Windows. The application isn't too complex, using all fairly standard code, with few external dependencies. The main dependencies are libelf (which compiles fine under mingw), pthreads (there appears to be a win32 version available), and sockets. The main problem is with sockets...Windows provides WinSock, but this is not 100% compatible with BSD (Berkeley) sockets as used by all *nixes. What I'm wondering is, has anybody written a wrapper on windows that exposes a BSD socket API, but calls Winsock on the backend, to ease porting?

推荐答案

在大多数情况下,您只需要确保在开始和结束时调用WSAStartup()和WSACleanup(),否则,将使用基本的BSD套接字会翻译得很好.您可以创建一些静态全局变量,以对每个套接字调用的调用进行检查,然后分别调用WSAStartup()和WSACleanup().至于poll()...好吧,它很容易转换为select().

For the most part, you'll just have to make sure that WSAStartup() and WSACleanup() are called at start and end, otherwise, basic BSD sockets will translate pretty well. You could create some static global variable that gets checked for each call to the socket calls, and call WSAStartup() and WSACleanup() accordingly. As for poll() ... well, it translates quite easily to select().

这篇关于BSD套接字兼容包装的Winsock吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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