11// Licensed to the .NET Foundation under one or more agreements.
22// The .NET Foundation licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information.
4+
45#if FEATURE_SYNC_SOCKETS
56
67using System ;
78using System . Collections ;
89using System . Collections . Generic ;
9- using System . Runtime . InteropServices ;
10- using Microsoft . Scripting ;
10+ using System . Net . Sockets ;
1111
1212using IronPython . Runtime ;
1313using IronPython . Runtime . Exceptions ;
1414using IronPython . Runtime . Operations ;
1515using IronPython . Runtime . Types ;
1616
1717using Microsoft . Scripting . Runtime ;
18- using System . Runtime . CompilerServices ;
19- using Microsoft . Scripting . Utils ;
20-
21- using System . Net . Sockets ;
2218
2319[ assembly: PythonModule ( "select" , typeof ( IronPython . Modules . PythonSelect ) ) ]
2420namespace IronPython . Modules {
@@ -67,9 +63,9 @@ public static PythonTuple select(CodeContext/*!*/ context, object iwtd, object o
6763 try {
6864 Socket . Select ( readerList , writerList , errorList , timeoutMicroseconds ) ;
6965 } catch ( ArgumentNullException ) {
70- throw MakeException ( context , SocketExceptionToTuple ( new SocketException ( ( int ) SocketError . InvalidArgument ) ) ) ;
66+ throw PythonSocket . MakeException ( context , new SocketException ( ( int ) SocketError . InvalidArgument ) ) ;
7167 } catch ( SocketException e ) {
72- throw MakeException ( context , SocketExceptionToTuple ( e ) ) ;
68+ throw PythonSocket . MakeException ( context , e ) ;
7369 }
7470
7571 // Convert back to what the user originally passed in
@@ -80,14 +76,6 @@ public static PythonTuple select(CodeContext/*!*/ context, object iwtd, object o
8076 return PythonTuple . MakeTuple ( readerList , writerList , errorList ) ;
8177 }
8278
83- private static PythonTuple SocketExceptionToTuple ( SocketException e ) {
84- return PythonTuple . MakeTuple ( e . ErrorCode , e . Message ) ;
85- }
86-
87- private static Exception MakeException ( CodeContext /*!*/ context , object value ) {
88- return PythonExceptions . CreateThrowable ( ( PythonType ) context . LanguageContext . GetModuleState ( "selecterror" ) , value ) ;
89- }
90-
9179 /// <summary>
9280 /// Process a sequence of objects that are compatible with ObjectToSocket(). Return two
9381 /// things as out params: an in-order List of sockets that correspond to the original
@@ -137,8 +125,7 @@ private static Socket ObjectToSocket(CodeContext context, object obj) {
137125 }
138126 socket = PythonSocket . socket . HandleToSocket ( handle ) ;
139127 if ( socket == null ) {
140- SocketException e = new SocketException ( ( int ) SocketError . NotSocket ) ;
141- throw PythonExceptions . CreateThrowable ( ( PythonType ) context . LanguageContext . GetModuleState ( "selecterror" ) , PythonTuple . MakeTuple ( e . ErrorCode , e . Message ) ) ;
128+ throw PythonSocket . MakeException ( context , new SocketException ( ( int ) SocketError . NotSocket ) ) ;
142129 }
143130 return socket ;
144131 }
0 commit comments