static void handleSocketException(final Ruby runtime, final SocketException ex, final String caller, final SocketAddress addr) { final String message = ex.getMessage(); if ( message != null ) { switch ( message ) { case "permission denied" : case "Permission denied" : if ( addr == null ) { throw runtime.newErrnoEACCESError(caller + " - " + message); } throw runtime.newErrnoEACCESError("Address already in use - " + caller + " for " + formatAddress(addr)); case "Address already in use" : throw runtime.newErrnoEADDRINUSEError(caller + " for " + formatAddress(addr)); case "Protocol family unavailable" : throw runtime.newErrnoEADDRNOTAVAILError(caller + " for " + formatAddress(addr)); } // This is ugly, but what can we do, Java provides the same exception type // for different situations, so we differentiate the errors // based on the exception's message. if (ALREADY_BOUND_PATTERN.matcher(message).find()) { throw runtime.newErrnoEINVALError(caller + " - " + message); } if (ADDR_NOT_AVAIL_PATTERN.matcher(message).find()) { throw runtime.newErrnoEADDRNOTAVAILError(caller + " - " + message); } } throw runtime.newErrnoEADDRINUSEError(caller + " - " + message); }
static void handleSocketException(final Ruby runtime, final SocketException ex, final String caller, final SocketAddress addr) { final String message = ex.getMessage(); if ( message != null ) { switch ( message ) { case "permission denied" : case "Permission denied" : if ( addr == null ) { throw runtime.newErrnoEACCESError(caller + " - " + message); } throw runtime.newErrnoEACCESError("Address already in use - " + caller + " for " + formatAddress(addr)); case "Address already in use" : throw runtime.newErrnoEADDRINUSEError(caller + " for " + formatAddress(addr)); case "Protocol family unavailable" : throw runtime.newErrnoEADDRNOTAVAILError(caller + " for " + formatAddress(addr)); } // This is ugly, but what can we do, Java provides the same exception type // for different situations, so we differentiate the errors // based on the exception's message. if (ALREADY_BOUND_PATTERN.matcher(message).find()) { throw runtime.newErrnoEINVALError(caller + " - " + message); } if (ADDR_NOT_AVAIL_PATTERN.matcher(message).find()) { throw runtime.newErrnoEADDRNOTAVAILError(caller + " - " + message); } } throw runtime.newErrnoEADDRINUSEError(caller + " - " + message); }