Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement cancel for AsyncServerSocketHandle.
  • Loading branch information
donaldh committed Jun 5, 2014
1 parent bbaf492 commit 7a36ff2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/io/AsyncServerSocketHandle.java
Expand Up @@ -17,7 +17,7 @@
import org.perl6.nqp.sixmodel.reprs.ConcBlockingQueueInstance;
import org.perl6.nqp.sixmodel.reprs.IOHandleInstance;

public class AsyncServerSocketHandle implements IIOBindable {
public class AsyncServerSocketHandle implements IIOBindable, IIOCancelable {

AsynchronousServerSocketChannel listenChan;

Expand Down Expand Up @@ -86,4 +86,13 @@ public void failed(Throwable exc, AsyncTaskInstance task) {
throw ExceptionHandling.dieInternal(tc, e);
}
}

@Override
public void cancel(ThreadContext tc) {
try {
listenChan.close();
} catch (IOException e) {
throw ExceptionHandling.dieInternal(tc, e);
}
}
}
4 changes: 3 additions & 1 deletion src/vm/jvm/runtime/org/perl6/nqp/io/IIOCancelable.java
@@ -1,6 +1,8 @@
package org.perl6.nqp.io;

import org.perl6.nqp.runtime.ThreadContext;

public interface IIOCancelable {

public void cancelIt();
public void cancel(ThreadContext tc);
}
4 changes: 2 additions & 2 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java
Expand Up @@ -4391,7 +4391,7 @@ public void run() {
queue.add(schedulee);
}

public void cancelIt() {
public void cancel(ThreadContext tc) {
cancel();
}
}
Expand All @@ -4412,7 +4412,7 @@ public static SixModelObject timer(SixModelObject queue, SixModelObject schedule
public static SixModelObject cancel(SixModelObject handle, ThreadContext tc) {
AsyncTaskInstance task = (AsyncTaskInstance) handle;
if (task.handle instanceof IIOCancelable) {
((IIOCancelable)task.handle).cancelIt();
((IIOCancelable)task.handle).cancel(tc);
} else {
throw ExceptionHandling.dieInternal(tc, "This handle does not support cancel");
}
Expand Down

0 comments on commit 7a36ff2

Please sign in to comment.