diff options
Diffstat (limited to 'docs/examples/win32sockets.c')
-rw-r--r-- | docs/examples/win32sockets.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/docs/examples/win32sockets.c b/docs/examples/win32sockets.c new file mode 100644 index 000000000..f052299d6 --- /dev/null +++ b/docs/examples/win32sockets.c @@ -0,0 +1,41 @@ +/* + * These are example functions doing socket init that Windows + * require. If you don't use windows, you can safely ignore this crap. + */ + +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +static void win32_cleanup(void) +{ + WSACleanup(); +} + +static CURLcode win32_init(void) +{ + WORD wVersionRequested; + WSADATA wsaData; + int err; + wVersionRequested = MAKEWORD(1, 1); + + err = WSAStartup(wVersionRequested, &wsaData); + + if (err != 0) + /* Tell the user that we couldn't find a useable */ + /* winsock.dll. */ + return 1; + + /* Confirm that the Windows Sockets DLL supports 1.1.*/ + /* Note that if the DLL supports versions greater */ + /* than 1.1 in addition to 1.1, it will still return */ + /* 1.1 in wVersion since that is the version we */ + /* requested. */ + + if ( LOBYTE( wsaData.wVersion ) != 1 || + HIBYTE( wsaData.wVersion ) != 1 ) { + /* Tell the user that we couldn't find a useable */ + + /* winsock.dll. */ + WSACleanup(); + return 1; + } + return 0; /* 0 is ok */ +} |