Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 303a1289f19c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a78ea29beabb
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Oct 14, 2015

  1. Copy the full SHA
    18c97a1 View commit details
  2. Copy the full SHA
    a78ea29 View commit details
5 changes: 1 addition & 4 deletions test/truffle/simple-webrick-server.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
require 'webrick'

root = File.expand_path '~/public_html'
server = WEBrick::HTTPServer.new :Port => 8080, :DocumentRoot => root

trap 'INT' do server.shutdown end
server = WEBrick::HTTPServer.new(:Port => 8080)

server.mount_proc '/' do |req, res|
res.body = "Hello, world!\n"
Original file line number Diff line number Diff line change
@@ -594,7 +594,7 @@ public Object select(DynamicObject readables, DynamicObject writables, DynamicOb
readableSet.set(fd);
}

final int result = getContext().getThreadManager().runUntilTimeout(this, timeout, new ThreadManager.BlockingTimeoutAction<Integer>() {
final ThreadManager.ResultOrTimeout<Integer> result = getContext().getThreadManager().runUntilTimeout(this, timeout, new ThreadManager.BlockingTimeoutAction<Integer>() {
@Override
public Integer block(Timeval timeoutToUse) throws InterruptedException {
final int result = nativeSockets().select(
@@ -612,7 +612,13 @@ public Integer block(Timeval timeoutToUse) throws InterruptedException {
}
});

if (result == -1 || result == 0) {
if (result instanceof ThreadManager.TimedOut) {
return nil();
}

final int resultCode = ((ThreadManager.ResultWithinTime<Integer>) result).getValue();

if (resultCode == -1 || resultCode == 0) {
return nil();
}

Original file line number Diff line number Diff line change
@@ -95,30 +95,54 @@ public <T> T runUntilResult(Node currentNode, BlockingAction<T> action) {
return result;
}

public <T> T runUntilTimeout(Node currentNode, int timeout, final BlockingTimeoutAction<T> action) {
public interface ResultOrTimeout<T> {
}

public static class ResultWithinTime<T> implements ResultOrTimeout<T> {

private final T value;

public ResultWithinTime(T value) {
this.value = value;
}

public T getValue() {
return value;
}

}

public static class TimedOut<T> implements ResultOrTimeout<T> {
}

public <T> ResultOrTimeout<T> runUntilTimeout(Node currentNode, int timeout, final BlockingTimeoutAction<T> action) {
final Timeval timeoutToUse = new DefaultNativeTimeval(jnr.ffi.Runtime.getSystemRuntime());

if (timeout == 0) {
timeoutToUse.setTime(new long[]{0, 0});

return runUntilResult(currentNode, new BlockingAction<T>() {
return new ResultWithinTime<>(runUntilResult(currentNode, new BlockingAction<T>() {

@Override
public T block() throws InterruptedException {
return action.block(timeoutToUse);
}

});
}));
} else {
final int pollTime = 500_000_000;
final long requestedTimeoutAt = System.nanoTime() + timeout * 1_000;

return runUntilResult(currentNode, new BlockingAction<T>() {
return runUntilResult(currentNode, new BlockingAction<ResultOrTimeout<T>>() {

@Override
public T block() throws InterruptedException {
public ResultOrTimeout<T> block() throws InterruptedException {
final long timeUntilRequestedTimeout = requestedTimeoutAt - System.nanoTime();

if (timeUntilRequestedTimeout <= 0) {
return new TimedOut<>();
}

final boolean timeoutForPoll;
final long effectiveTimeout;

@@ -139,7 +163,11 @@ public T block() throws InterruptedException {
throw new InterruptedException();
}

return result;
if (result == null) {
return new TimedOut<>();
}

return new ResultWithinTime<>(result);
}

});