42
42
43
43
import java .io .FileNotFoundException ;
44
44
import java .io .IOException ;
45
+ import java .nio .channels .AlreadyConnectedException ;
45
46
import java .nio .channels .ClosedChannelException ;
46
47
import java .nio .channels .NonReadableChannelException ;
47
48
import java .nio .channels .NonWritableChannelException ;
49
+ import java .nio .channels .NotYetConnectedException ;
48
50
import java .nio .file .AccessDeniedException ;
49
51
import java .nio .file .DirectoryNotEmptyException ;
50
52
import java .nio .file .FileAlreadyExistsException ;
@@ -165,13 +167,13 @@ public enum OSErrorEnum {
165
167
ESTRPIPE (86 , "Streams pipe error" ),
166
168
EUSERS (87 , "Too many users" ),
167
169
ENOTSOCK (88 , "Socket operation on non-socket" ),
168
- EDESTADDRREQ (89 , "Destination address required" ),
170
+ EDESTADDRREQ (platformSpecific ( 89 , 39 ) , "Destination address required" ),
169
171
EMSGSIZE (90 , "Message too long" ),
170
172
EPROTOTYPE (91 , "Protocol wrong type for socket" ),
171
173
ENOPROTOOPT (92 , "Protocol not available" ),
172
174
EPROTONOSUPPORT (93 , "Protocol not supported" ),
173
175
ESOCKTNOSUPPORT (94 , "Socket type not supported" ),
174
- EOPNOTSUPP (95 , "Operation not supported on transport endpoint" ),
176
+ EOPNOTSUPP (platformSpecific ( 95 , 102 ) , "Operation not supported on transport endpoint" ),
175
177
EPFNOSUPPORT (96 , "Protocol family not supported" ),
176
178
EAFNOSUPPORT (platformSpecific (97 , 47 ), "Address family not supported by protocol" ),
177
179
EADDRINUSE (98 , "Address already in use" ),
@@ -182,7 +184,7 @@ public enum OSErrorEnum {
182
184
ECONNABORTED (103 , "Software caused connection abort" ),
183
185
ECONNRESET (104 , "Connection reset by peer" ),
184
186
ENOBUFS (105 , "No buffer space available" ),
185
- EISCONN (106 , "Transport endpoint is already connected" ),
187
+ EISCONN (platformSpecific ( 106 , 56 ) , "Transport endpoint is already connected" ),
186
188
ENOTCONN (platformSpecific (107 , 57 ), "Transport endpoint is not connected" ),
187
189
ESHUTDOWN (108 , "Cannot send after transport endpoint shutdown" ),
188
190
ETOOMANYREFS (109 , "Too many references: cannot splice" ),
@@ -309,6 +311,13 @@ public static ErrorAndMessagePair fromException(Exception e) {
309
311
return new ErrorAndMessagePair (OSErrorEnum .EOPNOTSUPP , OSErrorEnum .EOPNOTSUPP .getMessage ());
310
312
} else if (e instanceof NonReadableChannelException || e instanceof NonWritableChannelException ) {
311
313
return new ErrorAndMessagePair (OSErrorEnum .EBADF , OSErrorEnum .EBADF .getMessage ());
314
+ } else if (e instanceof OperationWouldBlockException ) {
315
+ return new ErrorAndMessagePair (OSErrorEnum .EWOULDBLOCK , OSErrorEnum .EWOULDBLOCK .getMessage ());
316
+ } else if (e instanceof NotYetConnectedException ) {
317
+ // TODO for UDP send without connect it should probably be EDESTADDRREQ
318
+ return new ErrorAndMessagePair (OSErrorEnum .ENOTCONN , OSErrorEnum .ENOTCONN .getMessage ());
319
+ } else if (e instanceof AlreadyConnectedException ) {
320
+ return new ErrorAndMessagePair (OSErrorEnum .EISCONN , OSErrorEnum .EISCONN .getMessage ());
312
321
} else if (e instanceof RuntimeException ) {
313
322
throw (RuntimeException ) e ;
314
323
} else {
@@ -355,4 +364,8 @@ public ErrorAndMessagePair(OSErrorEnum oserror, String message) {
355
364
private static int platformSpecific (int linuxValue , int darwinValue ) {
356
365
return getPythonOSName ().equals (PLATFORM_DARWIN ) ? darwinValue : linuxValue ;
357
366
}
367
+
368
+ public static class OperationWouldBlockException extends IllegalStateException {
369
+ private static final long serialVersionUID = -6947337041526311362L ;
370
+ }
358
371
}
0 commit comments