#undef LK_LEN
+/* Get the errno value corresponding to the given err. This function is not
+ * intended to handle conversion of general GetLastError() codes. It only exists
+ * to translate Windows sockets error codes from WSAGetLastError(). Such codes
+ * used to be assigned to errno/$! in earlier versions of perl; this function is
+ * used to catch any old Perl code which is still trying to assign such values
+ * to $! and convert them to errno values instead.
+ */
+int
+win32_get_errno(int err)
+{
+ return convert_wsa_error_to_errno(err);
+}
+
/*
* redirected io subsystem for all XS modules
*
#define SOCKET_TEST_ERROR(x) SOCKET_TEST(x, SOCKET_ERROR)
+static int get_last_socket_error(void);
static struct servent* win32_savecopyservent(struct servent*d,
struct servent*s,
const char *proto);
WSACleanup();
}
-int
+static int
get_last_socket_error(void)
{
- int err = WSAGetLastError();
-
- /* Translate WSAExxx values to corresponding Exxx values. Not all WSAExxx
- * constants have corresponding Exxx constants in <errno.h> (even in VC++
- * 2010 and above, which have expanded <errno.h> with more values), but any
- * missing constants are provided by win32/include/sys/errno2.h.
- * The list of possible WSAExxx values used here comes from the MSDN page
- * titled "Windows Sockets Error Codes".
- * (Note: Only the WSAExxx values are handled here; other WSAxxx values are
- * returned unchanged. The return value normally ends up in errno/$! and at
- * the Perl code level may be tested against the Exxx constants exported by
- * the Errno and POSIX modules, which have never handled the other WSAxxx
- * values themselves, apparently without any ill effect so far.)
- */
- switch (err) {
+ return convert_wsa_error_to_errno(WSAGetLastError());
+}
+
+/* Translate WSAExxx values to corresponding Exxx values. Not all WSAExxx
+ * constants have corresponding Exxx constants in <errno.h> (even in VC++
+ * 2010 and above, which have expanded <errno.h> with more values), but any
+ * missing constants are provided by win32/include/sys/errno2.h.
+ * The list of possible WSAExxx values used here comes from the MSDN page
+ * titled "Windows Sockets Error Codes".
+ * (Note: Only the WSAExxx values are handled here; other WSAxxx values are
+ * returned unchanged. The return value normally ends up in errno/$! and at
+ * the Perl code level may be tested against the Exxx constants exported by
+ * the Errno and POSIX modules, which have never handled the other WSAxxx
+ * values themselves, apparently without any ill effect so far.)
+ */
+int
+convert_wsa_error_to_errno(int wsaerr)
+{
+ switch (wsaerr) {
case WSAEINTR:
return EINTR;
case WSAEBADF:
return EREFUSED;
}
- return err;
+ return wsaerr;
}
void