--- parser3/src/main/pa_socks.C 2002/02/07 17:41:36 1.10 +++ parser3/src/main/pa_socks.C 2026/04/25 13:38:46 1.35 @@ -1,57 +1,78 @@ /** @file Parser: socks initialization/finalization. - Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) - Author: Alexander Petrosyan (http://paf.design.ru) - - $Id: pa_socks.C,v 1.10 2002/02/07 17:41:36 paf Exp $ + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ -#define NO_UNISTD_H +volatile const char * IDENT_PA_SOCKS_C="$Id: pa_socks.C,v 1.35 2026/04/25 13:38:46 moko Exp $"; + #include "pa_config_includes.h" -#ifndef HAVE_SYS_SELECT_H -#include +#ifdef _MSC_VER #include "pa_exception.h" #include "pa_socks.h" +#include "pa_string.h" + +#include WSADATA wsaData; -void init_socks(Pool& pool) { +void pa_socks_init() { WORD wVersionRequested; int err; wVersionRequested = MAKEWORD( 1, 1 ); - //wVersionRequested = MAKEWORD( 2, 2 ); err = WSAStartup( wVersionRequested, &wsaData ); if ( err != 0 ) { - /* Tell the user that we could not find a usable */ - /* WinSock DLL. */ - throw Exception(0, 0, - 0, - "can not WSAStartup, err=%d", - err); + /* Tell the user that we could not find a usable */ + throw Exception(0, 0, "cannot WSAStartup, err=%d", err); } } -void done_socks() { +void pa_socks_done() { /* Confirm that the WinSock DLL supports 2.2.*/ /* Note that if the DLL supports versions greater */ /* than 2.2 in addition to 2.2, it will still return */ /* 2.2 in wVersion since that is the version we */ /* requested. */ - if ( LOBYTE( wsaData.wVersion ) == 2 || - HIBYTE( wsaData.wVersion ) == 2 ) { - WSACleanup( ); - return; + if ( LOBYTE( wsaData.wVersion ) == 2 || HIBYTE( wsaData.wVersion ) == 2 ) { + WSACleanup(); + return; } } +const char* pa_socks_strerr(int no) { + char buf[MAX_STRING]; + buf[0]=0; + size_t error_size=FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + no, + 0, // Default language + (LPTSTR) &buf, + sizeof(buf), + NULL + ); + if(error_size>3) // ".\r\n" + buf[error_size-3]=0; + return buf[0]? pa_strdup(buf): "unknown error"; +} +int pa_socks_errno() { + return WSAGetLastError(); +} + #else -#include "pa_pool.h" +void pa_socks_init() {} +void pa_socks_done() {} -void init_socks(Pool& pool) {} -void done_socks() {} +const char* pa_socks_strerr(int no) { + return strerror(no); +} +int pa_socks_errno() { + return errno; +} #endif