1313import time
1414import unittest
1515
16- from iptest import IronPythonTestCase , is_cli , is_osx , is_linux , is_windows , is_cpython , run_test
16+ from iptest import IronPythonTestCase , is_cli , is_mono , is_osx , is_linux , is_windows , is_cpython , run_test
1717
1818AF_DICT = {"AF_APPLETALK" : 5 ,
1919 "AF_DECnet" : 12 ,
@@ -432,7 +432,6 @@ def test_cp5814(self):
432432HOST = 'localhost'
433433PORT = 0
434434s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
435- s.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, 1) # prevents an "Address already in use" error when the socket is in a TIME_WAIT state
436435s.settimeout(20) # prevents the server from staying open if the client never connects
437436s.bind((HOST, PORT))
438437s.listen(1)
@@ -534,15 +533,14 @@ def test_misc(self):
534533 def test_makefile_refcount (self ):
535534 "Ensures that the _socket stays open while there's still a file associated"
536535
537- GPORT = None
536+ PORT = None
538537 def echoer ():
539- nonlocal GPORT
538+ nonlocal PORT
540539 s = socket .socket ()
541- s .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 ) # prevents an "Address already in use" error when the socket is in a TIME_WAIT state
542540 s .settimeout (15 ) # prevents the server from staying open if the client never connects
543541 s .bind (('localhost' , 0 ))
544- GPORT = s .getsockname ()[1 ]
545542 s .listen (5 )
543+ PORT = s .getsockname ()[1 ]
546544 (s2 , _ ) = s .accept ()
547545 s2 .send (s2 .recv (10 ))
548546 s2 .close ()
@@ -551,11 +549,16 @@ def echoer():
551549 _thread .start_new_thread (echoer , ())
552550 for _ in range (20 ):
553551 time .sleep (0.5 )
554- if GPORT is not None :
552+ if PORT is not None :
555553 break
556554
555+ if is_mono :
556+ # Warm up Mono to connecting sockets
557+ dummy = socket .socket ()
557558 s = socket .socket ()
558- s .connect (('localhost' , GPORT ))
559+ if is_mono :
560+ dummy .close ()
561+ s .connect (('localhost' , PORT ))
559562 f1 = s .makefile ('r' )
560563 f2 = s .makefile ('w' )
561564 s .close ()
@@ -582,7 +585,6 @@ def test_cp7451(self):
582585HOST = 'localhost'
583586PORT = 0
584587s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
585- s.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, 1) # prevents an "Address already in use" error when the socket is in a TIME_WAIT state
586588s.settimeout(20) # prevents the server from staying open if the client never connects
587589s.bind((HOST, PORT))
588590s.listen(1)
0 commit comments