Skip to content

Commit

Permalink
Showing 4 changed files with 35 additions and 11 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3733,6 +3733,10 @@ public RaiseException newErrnoEDESTADDRREQError(String func) {
return newRaiseException(getErrno().getClass("EDESTADDRREQ"), func);
}

public RaiseException newErrnoENETUNREACHError() {
return newRaiseException(getErrno().getClass("ENETUNREACH"), null);
}

public RaiseException newIndexError(String message) {
return newRaiseException(getIndexError(), message);
}
@@ -3984,6 +3988,8 @@ public RaiseException newIOErrorFromException(IOException e) {
return newErrnoEMFILEError();
} else if ("Too many open files in system".equals(e.getMessage())) {
return newErrnoENFILEError();
} else if ("Network is unreachable".equals(e.getMessage())) {
return newErrnoENETUNREACHError();
}
return newRaiseException(getIOError(), e.getMessage());
} else {
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ext/socket/RubyTCPServer.java
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
}

} catch(IOException e) {
throw SocketUtils.sockerr(runtime, "initialize: name or service not known");
throw runtime.newIOErrorFromException(e);

} catch (IllegalArgumentException iae) {
throw SocketUtils.sockerr(runtime, iae.getMessage());
@@ -169,7 +169,7 @@ public IRubyObject accept(ThreadContext context) {
}

} catch(IOException e) {
throw SocketUtils.sockerr(runtime, "problem when accepting");
throw runtime.newIOErrorFromException(e);
}
}

@@ -201,7 +201,7 @@ public IRubyObject accept_nonblock(ThreadContext context) {
}

} catch(IOException e) {
throw SocketUtils.sockerr(context.runtime, "problem when accepting");
throw runtime.newIOErrorFromException(e);

} finally {
try {
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/socket/RubyTCPSocket.java
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
throw runtime.newErrnoEADDRFromBindException(e, " on: " + localHost + ":" + String.valueOf(localPort));

} catch(IOException e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
throw runtime.newIOErrorFromException(e);

} catch (IllegalArgumentException iae) {
throw SocketUtils.sockerr(runtime, iae.getMessage());
32 changes: 25 additions & 7 deletions core/src/main/java/org/jruby/ext/socket/RubyUDPSocket.java
Original file line number Diff line number Diff line change
@@ -185,9 +185,12 @@ public IRubyObject connect(ThreadContext context, IRubyObject host, IRubyObject

} catch (UnknownHostException e) {
throw SocketUtils.sockerr(runtime, "connect: name or service not known");

} catch (IOException e) {
throw SocketUtils.sockerr(runtime, "connect: name or service not known");
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}

@@ -211,7 +214,10 @@ public IRubyObject recvfrom_nonblock(ThreadContext context, IRubyObject _length)
throw runtime.newErrnoECONNREFUSEDError();

} catch (IOException e) {
throw SocketUtils.sockerr(runtime, "recvfrom: name or service not known");
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}

@@ -243,7 +249,10 @@ public IRubyObject send(ThreadContext context, IRubyObject _mesg, IRubyObject _f
throw SocketUtils.sockerr(runtime, "send: name or service not known");

} catch (IOException e) {
throw SocketUtils.sockerr(runtime, "send: name or service not known");
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}

@@ -312,7 +321,10 @@ public IRubyObject send(ThreadContext context, IRubyObject[] args) {
throw SocketUtils.sockerr(runtime, "send: name or service not known");

} catch (IOException e) {
throw SocketUtils.sockerr(runtime, "send: name or service not known");
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}

@@ -357,7 +369,10 @@ public IRubyObject recvfrom(ThreadContext context, IRubyObject _length) {
throw runtime.newErrnoECONNREFUSEDError();

} catch (IOException e) {
throw SocketUtils.sockerr(runtime, "recvfrom: name or service not known");
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}

@@ -381,7 +396,10 @@ public IRubyObject recv(ThreadContext context, IRubyObject _length) {
return doReceive(runtime, RubyNumeric.fix2int(_length));

} catch (IOException e) {
throw SocketUtils.sockerr(runtime, "recv: name or service not known");
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());

}
}

0 comments on commit 60be4d2

Please sign in to comment.