Hello all,
If I am trying to write a cross-platform (windows/Linux) tcp package.. what is the best way to handle errno? Are the enums different for each OS? Would passing back strerror(errno) be sufficient?
Thanks!
Printable View
Hello all,
If I am trying to write a cross-platform (windows/Linux) tcp package.. what is the best way to handle errno? Are the enums different for each OS? Would passing back strerror(errno) be sufficient?
Thanks!
Winsock uses WSAGetLastError() while UNIX and Linux and Free BSD all use errno.
if you are going to make a single portable source code, you can use the preprocessor to cover the gap.
Code:#ifdef WIN32//defined by wizard
//put your windows specific code here such as
//dealing with error conditions and loading the winsock dll.
#elif defined(FREEBSD) //this is your custom define
//put your NIX code h for dealing with error codes etc
#elif defined (YADAYADA)(//whatever else you have to define
//whatever you have to do.
#endif
To the best of my knowledge there is no established standard that mandates al of the values be identical.
Since I prefer to play it safe, I always have a platform specific class which translates the system error number into a enum that I control. (Also I generally translate most of them into exceptions which are then thrown...)