views:

158

answers:

1

I am currently porting some Windows mobile C++ code to standard C++.

So I am trying to find alternatives for windows specific functions.

I have had very little luck in finding a standard C++ function that can help me replace the WSAGetLastError() windows specific function.

WSAGetLastError() returns error numbers for errors that occur with sockets in windows.

So I was wondering if anyone was aware of a way to replace this function in standard c++?

A way to get different error numbers for different outcomes of connecting/dissconecting a socket would be sufficent.

+6  A: 

There are no Standard C++ functions supporting sockets. 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.

anon
Cheers, thanks!
Donal Rafferty
If you are using non-blocking connects, then you will also need to use `getsockopt(socket, SOL_SOCKET, SO_ERROR, ...);` to get the `connect()` status. And be aware that `errno` is not changed on successful operations - so you may want to specifically set it to zero before each operation.
caf
Setting errno to zero is not good practice. You should instead only examine it if the function call return value indicates an error.
anon