private void readSocket(final ThreadContext tc, final AsyncTaskInstance task, final Decoder decoder) {
final ByteBuffer readBuffer = ByteBuffer.allocate(32768);
HLLConfig hllConfig = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig;
final SixModelObject Array = hllConfig.listType;
final SixModelObject Int = hllConfig.intBoxType;
final SixModelObject Str = hllConfig.strBoxType;
final SixModelObject Null = hllConfig.nullValue;
CompletionHandler<Integer, AsyncTaskInstance> handler
= new CompletionHandler<Integer, AsyncTaskInstance>() {
@Override
public void completed(Integer numRead, AsyncTaskInstance task) {
ThreadContext curTC = tc.gc.getCurrentThreadContext();
try {
if (numRead == -1) {
task.seq = -1;
callback(curTC, task, -1, Str, Null);
} else {
readBuffer.flip();
SixModelObject decoded = decoder.decode(tc, readBuffer, numRead);
readBuffer.compact();
callback(curTC, task, task.seq++, decoded, Null);
channel.read(readBuffer, task, this);
}
} catch (Throwable t) {
failed(t, task);
}
}
@Override
public void failed(Throwable t, AsyncTaskInstance task) {
ThreadContext curTC = tc.gc.getCurrentThreadContext();
SixModelObject err = (t instanceof AsynchronousCloseException)
? Str : Ops.box_s(t.toString(), Str, curTC);
callback(curTC, task, -1, Str, err);
}
protected void callback(ThreadContext tc, AsyncTaskInstance task, long seq, SixModelObject str, SixModelObject err) {
SixModelObject result = Array.st.REPR.allocate(tc, Array.st);
result.push_boxed(tc, task.schedulee);
result.push_boxed(tc, Ops.box_i(seq, Int, tc));
result.push_boxed(tc, str);
result.push_boxed(tc, err);
((ConcBlockingQueueInstance) task.queue).push_boxed(tc, result);
}
};
try {