xref: /freebsd/contrib/ntp/sntp/libevent/test/print-winsock-errors.c (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1 #include <winsock2.h>
2 #include <windows.h>
3 
4 #include <stdlib.h>
5 #include <stdio.h>
6 
7 #include "event2/event.h"
8 #include "event2/util.h"
9 #include "event2/thread.h"
10 
11 #define E(x) printf (#x " -> \"%s\"\n", evutil_socket_error_to_string (x));
12 
13 int main (int argc, char **argv)
14 {
15   int i, j;
16   const char *s1, *s2;
17 
18 #ifdef EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED
19   evthread_use_windows_threads ();
20 #endif
21 
22   s1 = evutil_socket_error_to_string (WSAEINTR);
23 
24   for (i = 0; i < 3; i++) {
25     printf ("\niteration %d:\n\n", i);
26     E(WSAEINTR);
27     E(WSAEACCES);
28     E(WSAEFAULT);
29     E(WSAEINVAL);
30     E(WSAEMFILE);
31     E(WSAEWOULDBLOCK);
32     E(WSAEINPROGRESS);
33     E(WSAEALREADY);
34     E(WSAENOTSOCK);
35     E(WSAEDESTADDRREQ);
36     E(WSAEMSGSIZE);
37     E(WSAEPROTOTYPE);
38     E(WSAENOPROTOOPT);
39     E(WSAEPROTONOSUPPORT);
40     E(WSAESOCKTNOSUPPORT);
41     E(WSAEOPNOTSUPP);
42     E(WSAEPFNOSUPPORT);
43     E(WSAEAFNOSUPPORT);
44     E(WSAEADDRINUSE);
45     E(WSAEADDRNOTAVAIL);
46     E(WSAENETDOWN);
47     E(WSAENETUNREACH);
48     E(WSAENETRESET);
49     E(WSAECONNABORTED);
50     E(WSAECONNRESET);
51     E(WSAENOBUFS);
52     E(WSAEISCONN);
53     E(WSAENOTCONN);
54     E(WSAESHUTDOWN);
55     E(WSAETIMEDOUT);
56     E(WSAECONNREFUSED);
57     E(WSAEHOSTDOWN);
58     E(WSAEHOSTUNREACH);
59     E(WSAEPROCLIM);
60     E(WSASYSNOTREADY);
61     E(WSAVERNOTSUPPORTED);
62     E(WSANOTINITIALISED);
63     E(WSAEDISCON);
64     E(WSATYPE_NOT_FOUND);
65     E(WSAHOST_NOT_FOUND);
66     E(WSATRY_AGAIN);
67     E(WSANO_RECOVERY);
68     E(WSANO_DATA);
69     E(0xdeadbeef); /* test the case where no message is available */
70 
71     /* fill up the hash table a bit to make sure it grows properly */
72     for (j = 0; j < 50; j++) {
73       int err;
74       evutil_secure_rng_get_bytes(&err, sizeof(err));
75       evutil_socket_error_to_string(err);
76     }
77   }
78 
79   s2 = evutil_socket_error_to_string (WSAEINTR);
80   if (s1 != s2)
81     printf ("caching failed!\n");
82 
83   libevent_global_shutdown ();
84 
85   return EXIT_SUCCESS;
86 }
87