diff options
author | Tomasz Konojacki <me@xenu.pl> | 2023-03-10 01:12:58 +0100 |
---|---|---|
committer | xenu <me@xenu.pl> | 2023-03-17 09:26:39 +0100 |
commit | 8a548d15292f2166cb07a69fc5fc943391b7fba5 (patch) | |
tree | bc5f62672879c5ba9900354ea70aeb5c931ef0c0 /win32 | |
parent | c1cac033a542bfd8a5ab0a5152c35f0b07cc3024 (diff) | |
download | perl-8a548d15292f2166cb07a69fc5fc943391b7fba5.tar.gz |
win32: initialise winsock unconditionally
The next commit needs it. Also, I don't think this optimisation is worth
the trouble.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/win32.c | 11 | ||||
-rw-r--r-- | win32/win32.h | 29 | ||||
-rw-r--r-- | win32/win32sck.c | 63 |
3 files changed, 4 insertions, 99 deletions
diff --git a/win32/win32.c b/win32/win32.c index f42e6a23ce..435d160eda 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -3313,11 +3313,7 @@ win32_freopen(const char *path, const char *mode, FILE *stream) DllExport int win32_fclose(FILE *pf) { -#ifdef WIN32_NO_SOCKETS - return fclose(pf); -#else return my_fclose(pf); /* defined in win32sck.c */ -#endif } DllExport int @@ -3923,11 +3919,7 @@ extern int my_close(int); /* in win32sck.c */ DllExport int win32_close(int fd) { -#ifdef WIN32_NO_SOCKETS - return close(fd); -#else return my_close(fd); -#endif } DllExport int @@ -5210,6 +5202,9 @@ Perl_win32_init(int *argcp, char ***argvp) */ InitCommonControls(); + WSADATA wsadata; + WSAStartup(MAKEWORD(2, 2), &wsadata); + g_osver.dwOSVersionInfoSize = sizeof(g_osver); GetVersionEx(&g_osver); diff --git a/win32/win32.h b/win32/win32.h index da83afb682..c184b9f5f5 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -15,12 +15,6 @@ /* Win32 only optimizations for faster building */ #ifdef PERL_IS_MINIPERL -/* this macro will remove Winsock only on miniperl, PERL_IMPLICIT_SYS and - * makedef.pl create dependencies that will keep Winsock linked in even with - * this macro defined, even though sockets will be umimplemented from a script - * level in full perl - */ -# define WIN32_NO_SOCKETS /* less I/O calls during each require */ # define PERL_DISABLE_PMC @@ -31,29 +25,6 @@ # define PERL_TEXTMODE_SCRIPTS #endif -#ifdef WIN32_NO_SOCKETS -# undef HAS_SOCKET -# undef HAS_GETPROTOBYNAME -# undef HAS_GETPROTOBYNUMBER -# undef HAS_GETPROTOENT -# undef HAS_GETNETBYNAME -# undef HAS_GETNETBYADDR -# undef HAS_GETNETENT -# undef HAS_GETSERVBYNAME -# undef HAS_GETSERVBYPORT -# undef HAS_GETSERVENT -# undef HAS_GETHOSTBYNAME -# undef HAS_GETHOSTBYADDR -# undef HAS_GETHOSTENT -# undef HAS_SELECT -# undef HAS_IOCTL -# undef HAS_NTOHL -# undef HAS_HTONL -# undef HAS_HTONS -# undef HAS_NTOHS -# define WIN32SCK_IS_STDSCK -#endif - #if defined(PERL_IMPLICIT_SYS) # define DYNAMIC_ENV_FETCH # define HAS_GETENV_LEN diff --git a/win32/win32sck.c b/win32/win32sck.c index ef5c682101..f08b7bea29 100644 --- a/win32/win32sck.c +++ b/win32/win32sck.c @@ -33,15 +33,8 @@ #define OPEN_SOCKET(x) win32_open_osfhandle(x,O_RDWR|O_BINARY) #define TO_SOCKET(x) _get_osfhandle(x) -#define StartSockets() \ - STMT_START { \ - if (!wsock_started) \ - start_sockets(); \ - } STMT_END - #define SOCKET_TEST(x, y) \ STMT_START { \ - StartSockets(); \ if((x) == (y)) \ { \ int wsaerr = WSAGetLastError(); \ @@ -56,8 +49,6 @@ static struct servent* win32_savecopyservent(struct servent*d, struct servent*s, const char *proto); -static int wsock_started = 0; - #ifdef WIN32_DYN_IOINFO_SIZE EXTERN_C Size_t w32_ioinfo_size; #endif @@ -65,8 +56,7 @@ EXTERN_C Size_t w32_ioinfo_size; EXTERN_C void EndSockets(void) { - if (wsock_started) - WSACleanup(); + WSACleanup(); } /* Translate WSAExxx values to corresponding Exxx values where possible. Not all @@ -326,63 +316,27 @@ convert_errno_to_wsa_error(int err) } #endif /* ERRNO_HAS_POSIX_SUPPLEMENT */ -void -start_sockets(void) -{ - unsigned short version; - WSADATA retdata; - int ret; - - /* - * initalize the winsock interface and insure that it is - * cleaned up at exit. - */ - version = 0x2; - if(ret = WSAStartup(version, &retdata)) - Perl_croak_nocontext("Unable to locate winsock library!\n"); - if(retdata.wVersion != version) - Perl_croak_nocontext("Could not find version 2.0 of winsock dll\n"); - - /* atexit((void (*)(void)) EndSockets); */ - wsock_started = 1; -} - -/* in no sockets Win32 builds, these use the inline functions defined in - * perl.h - */ u_long win32_htonl(u_long hostlong) { -#ifndef WIN32_NO_SOCKETS - StartSockets(); -#endif return htonl(hostlong); } u_short win32_htons(u_short hostshort) { -#ifndef WIN32_NO_SOCKETS - StartSockets(); -#endif return htons(hostshort); } u_long win32_ntohl(u_long netlong) { -#ifndef WIN32_NO_SOCKETS - StartSockets(); -#endif return ntohl(netlong); } u_short win32_ntohs(u_short netshort) { -#ifndef WIN32_NO_SOCKETS - StartSockets(); -#endif return ntohs(netshort); } @@ -495,8 +449,6 @@ win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const FD_SET nrd, nwr, nex; bool just_sleep = TRUE; - StartSockets(); - FD_ZERO(&nrd); FD_ZERO(&nwr); FD_ZERO(&nex); @@ -668,8 +620,6 @@ win32_socket(int af, int type, int protocol) { SOCKET s; - StartSockets(); - if((s = open_ifs_socket(af, type, protocol)) == INVALID_SOCKET) { int wsaerr = WSAGetLastError(); @@ -692,8 +642,6 @@ win32_socket(int af, int type, int protocol) int my_close(int fd) { int osf; - if (!wsock_started) /* No WinSock? */ - return(close(fd)); /* Then not a socket. */ osf = TO_SOCKET(fd);/* Get it now before it's gone! */ if (osf != -1) { int err; @@ -728,8 +676,6 @@ int my_fclose (FILE *pf) { int osf; - if (!wsock_started) /* No WinSock? */ - return(fclose(pf)); /* Then not a socket. */ osf = TO_SOCKET(win32_fileno(pf));/* Get it now before it's gone! */ if (osf != -1) { int err; @@ -839,11 +785,6 @@ win32_ioctl(int i, unsigned int u, char *data) u_long u_long_arg; int retval; - if (!wsock_started) { - Perl_croak_nocontext("ioctl implemented only on sockets"); - /* NOTREACHED */ - } - /* mauke says using memcpy avoids alignment issues */ memcpy(&u_long_arg, data, sizeof u_long_arg); retval = ioctlsocket(TO_SOCKET(i), (long)u, &u_long_arg); @@ -865,14 +806,12 @@ win32_ioctl(int i, unsigned int u, char *data) char FAR * win32_inet_ntoa(struct in_addr in) { - StartSockets(); return inet_ntoa(in); } unsigned long win32_inet_addr(const char FAR *cp) { - StartSockets(); return inet_addr(cp); } |