May 2019
Intermediate to advanced
478 pages
11h 21m
English
In Chapter 2, Getting to Grips with Socket APIs, we developed the GETSOCKETERRNO() macro as a cross-platform way to obtain the error code after a failed system call.
The GETSOCKETERRNO() macro is repeated here for your convenience:
#if defined(_WIN32)#define GETSOCKETERRNO() (WSAGetLastError())#else#define GETSOCKETERRNO() (errno)#endif
The preceding code has served us well throughout this book. It has the advantage of being short and simple.
In a real-world program, you may want to display a text-based error message in addition to the error code. Windows and Unix-based systems both provide functions for this purpose.
We can build a simple function to return the last error message as a C string. The code for ...
Read now
Unlock full access