简体   繁体   English

BSD套接字兼容包装的Winsock吗?

[英]BSD socket compatible wrapper around winsock?

I'm attempting to port a Linux application to Windows. 我正在尝试将Linux应用程序移植到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. 主要依赖项是libelf(在mingw下可以很好地编译),pthreads(似乎有可用的win32版本)和套接字。 The main problem is with sockets...Windows provides WinSock, but this is not 100% compatible with BSD (Berkeley) sockets as used by all *nixes. 主要问题是套接字... Windows提供了WinSock,但这与所有* nix所使用的BSD(Berkeley)套接字不是100%兼容。 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? 我想知道的是,是否有人在Windows上编写了一个包装程序来公开BSD套接字API,却在后端调用Winsock来简化移植?

I would recommend using cygwin.dll . 我建议使用cygwin.dll It's built for bringing over *nixes to windows including sockets, file IO, etc. 它是为将* nixes移到Windows(包括套接字,文件IO等)而构建的。

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. 在大多数情况下,您只需要确保在开始和结束时调用WSAStartup()和WSACleanup(),否则,基本的BSD套接字将转换得很好。 You could create some static global variable that gets checked for each call to the socket calls, and call WSAStartup() and WSACleanup() accordingly. 您可以创建一些静态全局变量,以对每个套接字调用的调用进行检查,然后分别调用WSAStartup()和WSACleanup()。 As for poll() ... well, it translates quite easily to select(). 至于poll()...好吧,它很容易转换为select()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM