Skip to content

Commit 8a548d1

Browse files
committed
win32: initialise winsock unconditionally
The next commit needs it. Also, I don't think this optimisation is worth the trouble.
1 parent c1cac03 commit 8a548d1

File tree

3 files changed

+4
-99
lines changed

3 files changed

+4
-99
lines changed

win32/win32.c

+3-8
Original file line numberDiff line numberDiff line change
@@ -3313,11 +3313,7 @@ win32_freopen(const char *path, const char *mode, FILE *stream)
33133313
DllExport int
33143314
win32_fclose(FILE *pf)
33153315
{
3316-
#ifdef WIN32_NO_SOCKETS
3317-
return fclose(pf);
3318-
#else
33193316
return my_fclose(pf); /* defined in win32sck.c */
3320-
#endif
33213317
}
33223318

33233319
DllExport int
@@ -3923,11 +3919,7 @@ extern int my_close(int); /* in win32sck.c */
39233919
DllExport int
39243920
win32_close(int fd)
39253921
{
3926-
#ifdef WIN32_NO_SOCKETS
3927-
return close(fd);
3928-
#else
39293922
return my_close(fd);
3930-
#endif
39313923
}
39323924

39333925
DllExport int
@@ -5210,6 +5202,9 @@ Perl_win32_init(int *argcp, char ***argvp)
52105202
*/
52115203
InitCommonControls();
52125204

5205+
WSADATA wsadata;
5206+
WSAStartup(MAKEWORD(2, 2), &wsadata);
5207+
52135208
g_osver.dwOSVersionInfoSize = sizeof(g_osver);
52145209
GetVersionEx(&g_osver);
52155210

win32/win32.h

-29
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515

1616
/* Win32 only optimizations for faster building */
1717
#ifdef PERL_IS_MINIPERL
18-
/* this macro will remove Winsock only on miniperl, PERL_IMPLICIT_SYS and
19-
* makedef.pl create dependencies that will keep Winsock linked in even with
20-
* this macro defined, even though sockets will be umimplemented from a script
21-
* level in full perl
22-
*/
23-
# define WIN32_NO_SOCKETS
2418
/* less I/O calls during each require */
2519
# define PERL_DISABLE_PMC
2620

@@ -31,29 +25,6 @@
3125
# define PERL_TEXTMODE_SCRIPTS
3226
#endif
3327

34-
#ifdef WIN32_NO_SOCKETS
35-
# undef HAS_SOCKET
36-
# undef HAS_GETPROTOBYNAME
37-
# undef HAS_GETPROTOBYNUMBER
38-
# undef HAS_GETPROTOENT
39-
# undef HAS_GETNETBYNAME
40-
# undef HAS_GETNETBYADDR
41-
# undef HAS_GETNETENT
42-
# undef HAS_GETSERVBYNAME
43-
# undef HAS_GETSERVBYPORT
44-
# undef HAS_GETSERVENT
45-
# undef HAS_GETHOSTBYNAME
46-
# undef HAS_GETHOSTBYADDR
47-
# undef HAS_GETHOSTENT
48-
# undef HAS_SELECT
49-
# undef HAS_IOCTL
50-
# undef HAS_NTOHL
51-
# undef HAS_HTONL
52-
# undef HAS_HTONS
53-
# undef HAS_NTOHS
54-
# define WIN32SCK_IS_STDSCK
55-
#endif
56-
5728
#if defined(PERL_IMPLICIT_SYS)
5829
# define DYNAMIC_ENV_FETCH
5930
# define HAS_GETENV_LEN

win32/win32sck.c

+1-62
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,8 @@
3333
#define OPEN_SOCKET(x) win32_open_osfhandle(x,O_RDWR|O_BINARY)
3434
#define TO_SOCKET(x) _get_osfhandle(x)
3535

36-
#define StartSockets() \
37-
STMT_START { \
38-
if (!wsock_started) \
39-
start_sockets(); \
40-
} STMT_END
41-
4236
#define SOCKET_TEST(x, y) \
4337
STMT_START { \
44-
StartSockets(); \
4538
if((x) == (y)) \
4639
{ \
4740
int wsaerr = WSAGetLastError(); \
@@ -56,17 +49,14 @@ static struct servent* win32_savecopyservent(struct servent*d,
5649
struct servent*s,
5750
const char *proto);
5851

59-
static int wsock_started = 0;
60-
6152
#ifdef WIN32_DYN_IOINFO_SIZE
6253
EXTERN_C Size_t w32_ioinfo_size;
6354
#endif
6455

6556
EXTERN_C void
6657
EndSockets(void)
6758
{
68-
if (wsock_started)
69-
WSACleanup();
59+
WSACleanup();
7060
}
7161

7262
/* Translate WSAExxx values to corresponding Exxx values where possible. Not all
@@ -326,63 +316,27 @@ convert_errno_to_wsa_error(int err)
326316
}
327317
#endif /* ERRNO_HAS_POSIX_SUPPLEMENT */
328318

329-
void
330-
start_sockets(void)
331-
{
332-
unsigned short version;
333-
WSADATA retdata;
334-
int ret;
335-
336-
/*
337-
* initalize the winsock interface and insure that it is
338-
* cleaned up at exit.
339-
*/
340-
version = 0x2;
341-
if(ret = WSAStartup(version, &retdata))
342-
Perl_croak_nocontext("Unable to locate winsock library!\n");
343-
if(retdata.wVersion != version)
344-
Perl_croak_nocontext("Could not find version 2.0 of winsock dll\n");
345-
346-
/* atexit((void (*)(void)) EndSockets); */
347-
wsock_started = 1;
348-
}
349-
350-
/* in no sockets Win32 builds, these use the inline functions defined in
351-
* perl.h
352-
*/
353319
u_long
354320
win32_htonl(u_long hostlong)
355321
{
356-
#ifndef WIN32_NO_SOCKETS
357-
StartSockets();
358-
#endif
359322
return htonl(hostlong);
360323
}
361324

362325
u_short
363326
win32_htons(u_short hostshort)
364327
{
365-
#ifndef WIN32_NO_SOCKETS
366-
StartSockets();
367-
#endif
368328
return htons(hostshort);
369329
}
370330

371331
u_long
372332
win32_ntohl(u_long netlong)
373333
{
374-
#ifndef WIN32_NO_SOCKETS
375-
StartSockets();
376-
#endif
377334
return ntohl(netlong);
378335
}
379336

380337
u_short
381338
win32_ntohs(u_short netshort)
382339
{
383-
#ifndef WIN32_NO_SOCKETS
384-
StartSockets();
385-
#endif
386340
return ntohs(netshort);
387341
}
388342

@@ -495,8 +449,6 @@ win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const
495449
FD_SET nrd, nwr, nex;
496450
bool just_sleep = TRUE;
497451

498-
StartSockets();
499-
500452
FD_ZERO(&nrd);
501453
FD_ZERO(&nwr);
502454
FD_ZERO(&nex);
@@ -668,8 +620,6 @@ win32_socket(int af, int type, int protocol)
668620
{
669621
SOCKET s;
670622

671-
StartSockets();
672-
673623
if((s = open_ifs_socket(af, type, protocol)) == INVALID_SOCKET)
674624
{
675625
int wsaerr = WSAGetLastError();
@@ -692,8 +642,6 @@ win32_socket(int af, int type, int protocol)
692642
int my_close(int fd)
693643
{
694644
int osf;
695-
if (!wsock_started) /* No WinSock? */
696-
return(close(fd)); /* Then not a socket. */
697645
osf = TO_SOCKET(fd);/* Get it now before it's gone! */
698646
if (osf != -1) {
699647
int err;
@@ -728,8 +676,6 @@ int
728676
my_fclose (FILE *pf)
729677
{
730678
int osf;
731-
if (!wsock_started) /* No WinSock? */
732-
return(fclose(pf)); /* Then not a socket. */
733679
osf = TO_SOCKET(win32_fileno(pf));/* Get it now before it's gone! */
734680
if (osf != -1) {
735681
int err;
@@ -839,11 +785,6 @@ win32_ioctl(int i, unsigned int u, char *data)
839785
u_long u_long_arg;
840786
int retval;
841787

842-
if (!wsock_started) {
843-
Perl_croak_nocontext("ioctl implemented only on sockets");
844-
/* NOTREACHED */
845-
}
846-
847788
/* mauke says using memcpy avoids alignment issues */
848789
memcpy(&u_long_arg, data, sizeof u_long_arg);
849790
retval = ioctlsocket(TO_SOCKET(i), (long)u, &u_long_arg);
@@ -865,14 +806,12 @@ win32_ioctl(int i, unsigned int u, char *data)
865806
char FAR *
866807
win32_inet_ntoa(struct in_addr in)
867808
{
868-
StartSockets();
869809
return inet_ntoa(in);
870810
}
871811

872812
unsigned long
873813
win32_inet_addr(const char FAR *cp)
874814
{
875-
StartSockets();
876815
return inet_addr(cp);
877816
}
878817

0 commit comments

Comments
 (0)