将Winsock移植到Linux套接字 [英] Porting Winsock to Linux Sockets

查看:110
本文介绍了将Winsock移植到Linux套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序可以使用Winsock进行一些网络连接,现在我们的要求之一是将我们的程序移植到Linux.唯一阻止我们执行此操作的是Winsock.

I have a program that does some networking using Winsock, and one of our requirements right now is to port over our program to Linux. The only thing stopping us from doing this is Winsock.

我的问题是:如何轻松地将其移植到Linux实现中?

My question is: How easy can I port this over to a Linux implementation?

我应该注意任何陷阱吗?如果仅包含适当的头文件,我必须确定要处理哪些事情?

Are there any pitfalls I should be aware of, and if I simply include the appropriate header files, what sort of things will I have to be sure to handle?

感谢您的帮助!

我会发布代码,但是由于法律原因,我不能这样做. 但是,我们的代码确实使用以下代码:

I'd post code but I can't unfortunately due to legal reasons. But, our code does use the following:

WSAStartup(..)
WSACleanup(..)
Socket(..)
sendto(..)
recvfrom(..)
ioctlsocket(..)
setsocketopt(..)

推荐答案

这取决于您使用的是Windows特定的联网功能还是仅使用大多数与BSD兼容的API.

It will depend if you use any windows specific networking functionality or if you're just using mostly the mostly BSD compatible API.

因此,如果您使用重叠的I/O和I/O完成端口以及Winsock API的其他高级部分,那么将很难移植,如果您仅使用与BSD兼容的东西,则应该很容易编写一个薄的翻译层,甚至只在特定于Windows的ifdef窗口中包含Winsock的启动和关闭内容...

So, if you're using overlapped I/O and I/O completion ports and other advanced parts of the Winsock API then things will be very difficult to port and if you're just using the BSD compatible stuff then it should be easy to write a thin translation layer or even just have the winsock startup and shutdown stuff inside a windows specific ifdef...

这可能会有所帮助: http://tangentsoft.net/wskfaq/articles/bsd- ibility.html

这篇关于将Winsock移植到Linux套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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