4242
4343import java .io .FileNotFoundException ;
4444import java .io .IOException ;
45+ import java .nio .channels .AlreadyConnectedException ;
4546import java .nio .channels .ClosedChannelException ;
4647import java .nio .channels .NonReadableChannelException ;
4748import java .nio .channels .NonWritableChannelException ;
49+ import java .nio .channels .NotYetConnectedException ;
4850import java .nio .file .AccessDeniedException ;
4951import java .nio .file .DirectoryNotEmptyException ;
5052import java .nio .file .FileAlreadyExistsException ;
@@ -165,13 +167,13 @@ public enum OSErrorEnum {
165167 ESTRPIPE (86 , "Streams pipe error" ),
166168 EUSERS (87 , "Too many users" ),
167169 ENOTSOCK (88 , "Socket operation on non-socket" ),
168- EDESTADDRREQ (89 , "Destination address required" ),
170+ EDESTADDRREQ (platformSpecific ( 89 , 39 ) , "Destination address required" ),
169171 EMSGSIZE (90 , "Message too long" ),
170172 EPROTOTYPE (91 , "Protocol wrong type for socket" ),
171173 ENOPROTOOPT (92 , "Protocol not available" ),
172174 EPROTONOSUPPORT (93 , "Protocol not supported" ),
173175 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" ),
175177 EPFNOSUPPORT (96 , "Protocol family not supported" ),
176178 EAFNOSUPPORT (platformSpecific (97 , 47 ), "Address family not supported by protocol" ),
177179 EADDRINUSE (98 , "Address already in use" ),
@@ -182,7 +184,7 @@ public enum OSErrorEnum {
182184 ECONNABORTED (103 , "Software caused connection abort" ),
183185 ECONNRESET (104 , "Connection reset by peer" ),
184186 ENOBUFS (105 , "No buffer space available" ),
185- EISCONN (106 , "Transport endpoint is already connected" ),
187+ EISCONN (platformSpecific ( 106 , 56 ) , "Transport endpoint is already connected" ),
186188 ENOTCONN (platformSpecific (107 , 57 ), "Transport endpoint is not connected" ),
187189 ESHUTDOWN (108 , "Cannot send after transport endpoint shutdown" ),
188190 ETOOMANYREFS (109 , "Too many references: cannot splice" ),
@@ -309,6 +311,13 @@ public static ErrorAndMessagePair fromException(Exception e) {
309311 return new ErrorAndMessagePair (OSErrorEnum .EOPNOTSUPP , OSErrorEnum .EOPNOTSUPP .getMessage ());
310312 } else if (e instanceof NonReadableChannelException || e instanceof NonWritableChannelException ) {
311313 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 ());
312321 } else if (e instanceof RuntimeException ) {
313322 throw (RuntimeException ) e ;
314323 } else {
@@ -355,4 +364,8 @@ public ErrorAndMessagePair(OSErrorEnum oserror, String message) {
355364 private static int platformSpecific (int linuxValue , int darwinValue ) {
356365 return getPythonOSName ().equals (PLATFORM_DARWIN ) ? darwinValue : linuxValue ;
357366 }
367+
368+ public static class OperationWouldBlockException extends IllegalStateException {
369+ private static final long serialVersionUID = -6947337041526311362L ;
370+ }
358371}
0 commit comments