Annotation of parser3/src/main/pa_socks.C, revision 1.31

1.3       paf         1: /**    @file
1.1       paf         2:        Parser: socks initialization/finalization.
                      3: 
1.31    ! moko        4:        Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com)
1.13      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.15      paf         6: */
1.1       paf         7: 
1.31    ! moko        8: volatile const char * IDENT_PA_SOCKS_C="$Id: pa_socks.C,v 1.30 2017/02/07 22:00:44 moko Exp $";
1.2       paf         9: 
                     10: #include "pa_config_includes.h"
1.1       paf        11: 
1.28      moko       12: #ifdef _MSC_VER
                     13: 
1.9       paf        14: #include "pa_exception.h"
                     15: #include "pa_socks.h"
1.19      paf        16: #include "pa_string.h"
1.11      paf        17: 
1.19      paf        18: #include <windows.h>
                     19: 
1.1       paf        20: WSADATA wsaData;
                     21: 
1.22      paf        22: void pa_socks_init() {
1.1       paf        23:        WORD wVersionRequested;
                     24:        int err; 
                     25:        wVersionRequested = MAKEWORD( 1, 1 ); 
                     26:        err = WSAStartup( wVersionRequested, &wsaData );
                     27:        if ( err != 0 ) {
1.28      moko       28:                /* Tell the user that we could not find a usable */
                     29:                throw Exception(0, 0, "can not WSAStartup, err=%d", err);
1.1       paf        30:        } 
                     31: }
                     32: 
1.22      paf        33: void pa_socks_done() {
1.1       paf        34:        /* Confirm that the WinSock DLL supports 2.2.*/
                     35:        /* Note that if the DLL supports versions greater    */
                     36:        /* than 2.2 in addition to 2.2, it will still return */
                     37:        /* 2.2 in wVersion since that is the version we      */
                     38:        /* requested.                                        */ 
1.28      moko       39:        if ( LOBYTE( wsaData.wVersion ) == 2 || HIBYTE( wsaData.wVersion ) == 2 ) {
                     40:                WSACleanup();
                     41:                return;
1.1       paf        42:        } 
                     43: }
                     44: 
1.23      paf        45: const char* pa_socks_strerr(int no) {
                     46:        char buf[MAX_STRING];
                     47:        buf[0]=0;
                     48:        size_t error_size=FormatMessage( 
                     49:                FORMAT_MESSAGE_FROM_SYSTEM | 
                     50:                FORMAT_MESSAGE_IGNORE_INSERTS,
                     51:                NULL,
                     52:                no,
                     53:                0, // Default language
                     54:                (LPTSTR) &buf,
                     55:                sizeof(buf),
                     56:                NULL 
                     57:        );
                     58:        if(error_size>3) // ".\r\n"
                     59:                buf[error_size-3]=0;
                     60:        return buf[0]? pa_strdup(buf): "unknown error";
                     61: }
                     62: int pa_socks_errno() {
                     63:        return WSAGetLastError();
                     64: }
                     65: 
1.1       paf        66: #else
1.10      paf        67: 
1.22      paf        68: void pa_socks_init() {}
                     69: void pa_socks_done() {}
1.23      paf        70: 
                     71: const char* pa_socks_strerr(int no) {
                     72:        return strerror(no);
                     73: }
                     74: int pa_socks_errno() {
                     75:        return errno;
                     76: }
1.1       paf        77: 
                     78: #endif

E-mail: