简体   繁体   English

将Windows平台C ++移植到POSIX(Linux)C ++ - WSAGetLastError()

[英]Porting Windows platform C++ to POSIX (Linux) C++ - WSAGetLastError()

I am currently porting some Windows mobile C++ code to standard C++. 我目前正在将一些Windows移动C ++代码移植到标准C ++。

So I am trying to find alternatives for windows specific functions. 所以我试图找到Windows特定功能的替代品。

I have had very little luck in finding a standard C++ function that can help me replace the WSAGetLastError() windows specific function. 我很难找到一个标准的C ++函数,它可以帮助我替换WSAGetLastError()窗口特定的函数。

WSAGetLastError() returns error numbers for errors that occur with sockets in windows. WSAGetLastError()返回Windows中套接字发生的错误的错误号。

So I was wondering if anyone was aware of a way to replace this function in standard c++? 所以我想知道是否有人知道在标准c ++中替换此功能的方法?

A way to get different error numbers for different outcomes of connecting/dissconecting a socket would be sufficent. 为连接/解除套接字的不同结果获取不同错误号的方法是足够的。

There are no Standard C++ functions supporting sockets. 没有支持套接字的标准C ++函数。 However, the POSIX socket functions should all set the errno variable on error - you just need to examine this - it should be declared in errno.h . 但是,POSIX套接字函数应该在出错时设置errno变量 - 您只需要检查它 - 它应该在errno.h声明。

I would port to Boost.ASIO which will abstract networking differences and likely give you better performance by using asynchronous calls and overlapped IO. 我将移植到Boost.ASIO,它将抽象网络差异,并可能通过使用异步调用和重叠IO提供更好的性能。 When you are done you code will work everywhere boost works. 当你完成后,你的代码将在任何地方工作。

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

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