33
33
#define OPEN_SOCKET (x ) win32_open_osfhandle(x,O_RDWR|O_BINARY)
34
34
#define TO_SOCKET (x ) _get_osfhandle(x)
35
35
36
- #define StartSockets () \
37
- STMT_START { \
38
- if (!wsock_started) \
39
- start_sockets(); \
40
- } STMT_END
41
-
42
36
#define SOCKET_TEST (x , y ) \
43
37
STMT_START { \
44
- StartSockets(); \
45
38
if((x) == (y)) \
46
39
{ \
47
40
int wsaerr = WSAGetLastError(); \
@@ -56,17 +49,14 @@ static struct servent* win32_savecopyservent(struct servent*d,
56
49
struct servent * s ,
57
50
const char * proto );
58
51
59
- static int wsock_started = 0 ;
60
-
61
52
#ifdef WIN32_DYN_IOINFO_SIZE
62
53
EXTERN_C Size_t w32_ioinfo_size ;
63
54
#endif
64
55
65
56
EXTERN_C void
66
57
EndSockets (void )
67
58
{
68
- if (wsock_started )
69
- WSACleanup ();
59
+ WSACleanup ();
70
60
}
71
61
72
62
/* Translate WSAExxx values to corresponding Exxx values where possible. Not all
@@ -326,63 +316,27 @@ convert_errno_to_wsa_error(int err)
326
316
}
327
317
#endif /* ERRNO_HAS_POSIX_SUPPLEMENT */
328
318
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
- */
353
319
u_long
354
320
win32_htonl (u_long hostlong )
355
321
{
356
- #ifndef WIN32_NO_SOCKETS
357
- StartSockets ();
358
- #endif
359
322
return htonl (hostlong );
360
323
}
361
324
362
325
u_short
363
326
win32_htons (u_short hostshort )
364
327
{
365
- #ifndef WIN32_NO_SOCKETS
366
- StartSockets ();
367
- #endif
368
328
return htons (hostshort );
369
329
}
370
330
371
331
u_long
372
332
win32_ntohl (u_long netlong )
373
333
{
374
- #ifndef WIN32_NO_SOCKETS
375
- StartSockets ();
376
- #endif
377
334
return ntohl (netlong );
378
335
}
379
336
380
337
u_short
381
338
win32_ntohs (u_short netshort )
382
339
{
383
- #ifndef WIN32_NO_SOCKETS
384
- StartSockets ();
385
- #endif
386
340
return ntohs (netshort );
387
341
}
388
342
@@ -495,8 +449,6 @@ win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const
495
449
FD_SET nrd , nwr , nex ;
496
450
bool just_sleep = TRUE;
497
451
498
- StartSockets ();
499
-
500
452
FD_ZERO (& nrd );
501
453
FD_ZERO (& nwr );
502
454
FD_ZERO (& nex );
@@ -668,8 +620,6 @@ win32_socket(int af, int type, int protocol)
668
620
{
669
621
SOCKET s ;
670
622
671
- StartSockets ();
672
-
673
623
if ((s = open_ifs_socket (af , type , protocol )) == INVALID_SOCKET )
674
624
{
675
625
int wsaerr = WSAGetLastError ();
@@ -692,8 +642,6 @@ win32_socket(int af, int type, int protocol)
692
642
int my_close (int fd )
693
643
{
694
644
int osf ;
695
- if (!wsock_started ) /* No WinSock? */
696
- return (close (fd )); /* Then not a socket. */
697
645
osf = TO_SOCKET (fd );/* Get it now before it's gone! */
698
646
if (osf != -1 ) {
699
647
int err ;
728
676
my_fclose (FILE * pf )
729
677
{
730
678
int osf ;
731
- if (!wsock_started ) /* No WinSock? */
732
- return (fclose (pf )); /* Then not a socket. */
733
679
osf = TO_SOCKET (win32_fileno (pf ));/* Get it now before it's gone! */
734
680
if (osf != -1 ) {
735
681
int err ;
@@ -839,11 +785,6 @@ win32_ioctl(int i, unsigned int u, char *data)
839
785
u_long u_long_arg ;
840
786
int retval ;
841
787
842
- if (!wsock_started ) {
843
- Perl_croak_nocontext ("ioctl implemented only on sockets" );
844
- /* NOTREACHED */
845
- }
846
-
847
788
/* mauke says using memcpy avoids alignment issues */
848
789
memcpy (& u_long_arg , data , sizeof u_long_arg );
849
790
retval = ioctlsocket (TO_SOCKET (i ), (long )u , & u_long_arg );
@@ -865,14 +806,12 @@ win32_ioctl(int i, unsigned int u, char *data)
865
806
char FAR *
866
807
win32_inet_ntoa (struct in_addr in )
867
808
{
868
- StartSockets ();
869
809
return inet_ntoa (in );
870
810
}
871
811
872
812
unsigned long
873
813
win32_inet_addr (const char FAR * cp )
874
814
{
875
- StartSockets ();
876
815
return inet_addr (cp );
877
816
}
878
817
0 commit comments