@@ -90,14 +90,14 @@ abstract static class AcceptNode extends PythonUnaryBuiltinNode {
90
90
Object accept (PSocket socket ) {
91
91
try {
92
92
SocketChannel acceptSocket = socket .getServerSocket ().accept ();
93
- if (acceptSocket == null ){
93
+ if (acceptSocket == null ) {
94
94
throw raise (PythonBuiltinClassType .OSError );
95
95
}
96
96
SocketAddress addr = acceptSocket .getLocalAddress ();
97
- if (!acceptSocket .socket ().isBound () || addr == null ) {
97
+ if (!acceptSocket .socket ().isBound () || addr == null ) {
98
98
throw raise (PythonBuiltinClassType .OSError );
99
99
}
100
- PSocket newSocket = factory ().createSocket (socket .getFamily (),socket .getType (),socket .getProto ());
100
+ PSocket newSocket = factory ().createSocket (socket .getFamily (), socket .getType (), socket .getProto ());
101
101
int fd = getContext ().getResources ().openSocket (newSocket );
102
102
newSocket .setFileno (fd );
103
103
newSocket .setSocket (acceptSocket );
@@ -118,7 +118,7 @@ abstract static class BindNode extends PythonBinaryBuiltinNode {
118
118
Object bind (PSocket socket , PTuple address ) {
119
119
Object [] hostAndPort = address .getArray ();
120
120
121
- int port = (int )hostAndPort [1 ];
121
+ int port = (int ) hostAndPort [1 ];
122
122
123
123
if (port >= 65536 || port < 0 ) {
124
124
throw raise (PythonBuiltinClassType .OverflowError );
@@ -147,8 +147,7 @@ Object close(PSocket socket) {
147
147
} catch (IOException e ) {
148
148
throw raise (PythonBuiltinClassType .OSError , "Bad file descriptor" );
149
149
}
150
- }
151
- else if (socket .getServerSocket () != null ) {
150
+ } else if (socket .getServerSocket () != null ) {
152
151
if (!socket .getServerSocket ().isOpen ()) {
153
152
throw raise (PythonBuiltinClassType .OSError , "Bad file descriptor" );
154
153
}
@@ -191,7 +190,7 @@ abstract static class GetPeerNameNode extends PythonUnaryBuiltinNode {
191
190
@ Specialization
192
191
@ TruffleBoundary
193
192
Object get (PSocket socket ) {
194
- if (socket .getSocket () == null ){
193
+ if (socket .getSocket () == null ) {
195
194
throw raise (PythonBuiltinClassType .OSError , "[Errno 57] Socket is not connected" );
196
195
}
197
196
@@ -220,7 +219,7 @@ Object get(PSocket socket) {
220
219
}
221
220
}
222
221
223
- if (socket .getSocket () != null ){
222
+ if (socket .getSocket () != null ) {
224
223
try {
225
224
InetSocketAddress addr = (InetSocketAddress ) socket .getSocket ().getLocalAddress ();
226
225
return factory ().createTuple (new Object []{addr .getAddress ().getHostAddress (), addr .getPort ()});
@@ -251,17 +250,27 @@ boolean get(PSocket socket) {
251
250
@ Builtin (name = "gettimeout" , minNumOfPositionalArgs = 1 )
252
251
@ GenerateNodeFactory
253
252
abstract static class GetTimeoutNode extends PythonUnaryBuiltinNode {
253
+ @ TruffleBoundary
254
+ private static int getSoTimeout (SocketChannel channel ) throws SocketException {
255
+ return channel .socket ().getSoTimeout ();
256
+ }
257
+
258
+ @ TruffleBoundary
259
+ private static int getSoTimeout (ServerSocketChannel channel ) throws IOException {
260
+ return channel .socket ().getSoTimeout ();
261
+ }
262
+
254
263
@ Specialization
255
264
Object get (PSocket socket ) {
256
265
try {
257
266
if (socket .getSocket () != null ) {
258
- socket .getSocket (). socket (). getSoTimeout ( );
267
+ return getSoTimeout ( socket .getSocket ());
259
268
}
260
269
261
270
if (socket .getServerSocket () != null ) {
262
- socket .getServerSocket (). socket (). getSoTimeout ( );
271
+ return getSoTimeout ( socket .getServerSocket ());
263
272
}
264
- } catch (Exception e ) {
273
+ } catch (IOException e ) {
265
274
throw raise (PythonBuiltinClassType .OSError );
266
275
}
267
276
return PNone .NONE ;
@@ -281,7 +290,8 @@ Object listen(PSocket socket, int backlog) {
281
290
282
291
ServerSocketChannel serverSocketChannel = ServerSocketChannel .open ();
283
292
// calling bind with port 0 will take the first available
284
- // for some reason this only works on the ServerSocket not on the ServerSocketChannel
293
+ // for some reason this only works on the ServerSocket not on the
294
+ // ServerSocketChannel
285
295
serverSocketChannel .socket ().bind (socketAddress , backlog );
286
296
serverSocketChannel .configureBlocking (socket .isBlocking ());
287
297
@@ -305,8 +315,9 @@ Object listen(PSocket socket, PNone backlog) {
305
315
abstract static class RecvNode extends PythonTernaryBuiltinNode {
306
316
@ Specialization
307
317
Object recv (PSocket socket , int bufsize , int flags ) {
308
- return recv (socket ,bufsize ,PNone .NONE );
318
+ return recv (socket , bufsize , PNone .NONE );
309
319
}
320
+
310
321
@ Specialization
311
322
@ TruffleBoundary
312
323
PBytes recv (PSocket socket , int bufsize , PNone flags ) {
@@ -329,6 +340,7 @@ abstract static class RecvFromNode extends PythonTernaryBuiltinNode {
329
340
Object recvFrom (PSocket socket , int bufsize , int flags ) {
330
341
return PNotImplemented .NOT_IMPLEMENTED ;
331
342
}
343
+
332
344
@ Specialization
333
345
Object recvFrom (PSocket socket , int bufsize , PNone flags ) {
334
346
return PNotImplemented .NOT_IMPLEMENTED ;
@@ -373,10 +385,12 @@ abstract static class RecvMsgNode extends PythonBuiltinNode {
373
385
Object recvFrom (PSocket socket , int bufsize , int ancbufsize , int flags ) {
374
386
return PNotImplemented .NOT_IMPLEMENTED ;
375
387
}
388
+
376
389
@ Specialization
377
390
Object recvFrom (PSocket socket , int bufsize , int ancbufsize , PNone flags ) {
378
391
return PNotImplemented .NOT_IMPLEMENTED ;
379
392
}
393
+
380
394
@ Specialization
381
395
Object recvFrom (PSocket socket , int bufsize , PNone ancbufsize , PNone flags ) {
382
396
return PNotImplemented .NOT_IMPLEMENTED ;
@@ -389,7 +403,7 @@ Object recvFrom(PSocket socket, int bufsize, PNone ancbufsize, PNone flags) {
389
403
abstract static class SendNode extends PythonTernaryBuiltinNode {
390
404
@ Specialization
391
405
Object send (PSocket socket , PBytes bytes , int flags ) {
392
- return send (socket ,bytes ,PNone .NONE );
406
+ return send (socket , bytes , PNone .NONE );
393
407
}
394
408
395
409
@ Specialization
@@ -448,6 +462,7 @@ abstract static class SendToNode extends PythonBuiltinNode {
448
462
Object sendTo (PSocket socket , Object bytes , int flags , Object address ) {
449
463
return PNotImplemented .NOT_IMPLEMENTED ;
450
464
}
465
+
451
466
@ Specialization
452
467
Object sendTo (PSocket socket , Object bytes , PNone flags , Object address ) {
453
468
return PNotImplemented .NOT_IMPLEMENTED ;
@@ -509,6 +524,7 @@ Object setTimeout(PSocket socket, Integer value) {
509
524
510
525
return PNone .NONE ;
511
526
}
527
+
512
528
@ Specialization
513
529
Object setTimeout (PSocket socket , double value ) {
514
530
Integer intValue = (int ) value ;
@@ -531,12 +547,10 @@ Object family(PSocket socket, int how) {
531
547
if (how == 1 || how == 2 ) {
532
548
socket .getSocket ().shutdownOutput ();
533
549
}
534
- }
535
- catch (IOException e ) {
550
+ } catch (IOException e ) {
536
551
throw raise (PythonBuiltinClassType .OSError );
537
552
}
538
- }
539
- else {
553
+ } else {
540
554
throw raise (PythonBuiltinClassType .OSError );
541
555
}
542
556
return PNone .NO_VALUE ;
0 commit comments