Skip to content

Commit 7ca649e

Browse files
committed
Implement asyncwritebytes on JVM.
1 parent 5647945 commit 7ca649e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/vm/jvm/runtime/org/perl6/nqp/io/AsyncSocketHandle.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,30 @@ protected void callback(ThreadContext tc, AsyncTaskInstance task, SixModelObject
8686
}
8787
}
8888

89-
public void writeStr(final ThreadContext tc, final AsyncTaskInstance task, String toWrite) {
89+
public void writeStr(ThreadContext tc, AsyncTaskInstance task, String toWrite) {
9090
try {
9191
ByteBuffer buffer = enc.encode(CharBuffer.wrap(toWrite));
92+
writeByteBuffer(tc, task, buffer);
93+
} catch (Throwable e) {
94+
throw ExceptionHandling.dieInternal(tc, e);
95+
}
96+
}
97+
98+
public void writeBytes(ThreadContext tc, AsyncTaskInstance task, SixModelObject toWrite) {
99+
ByteBuffer buffer = Ops.decode8(toWrite, tc);
100+
writeByteBuffer(tc, task, buffer);
101+
}
92102

103+
protected void writeByteBuffer(final ThreadContext tc, final AsyncTaskInstance task, ByteBuffer buffer) {
104+
try {
93105
HLLConfig hllConfig = tc.curFrame.codeRef.staticInfo.compUnit.hllConfig;
94106
final SixModelObject Array = hllConfig.listType;
95107
final SixModelObject Int = hllConfig.intBoxType;
96108
final SixModelObject Null = hllConfig.nullValue;
97109
final SixModelObject Str = hllConfig.strBoxType;
98110

99111
CompletionHandler<Integer, AsyncTaskInstance> handler
100-
= new CompletionHandler<Integer, AsyncTaskInstance>() {
112+
= new CompletionHandler<Integer, AsyncTaskInstance>() {
101113

102114
@Override
103115
public void completed(Integer bytesWritten, AsyncTaskInstance task) {
@@ -126,10 +138,6 @@ protected void callback(ThreadContext tc, AsyncTaskInstance task, SixModelObject
126138
}
127139
}
128140

129-
public void writeBytes(final ThreadContext tc, final AsyncTaskInstance task, SixModelObject toWrite) {
130-
131-
}
132-
133141
public void readChars(final ThreadContext tc, final AsyncTaskInstance task) {
134142
final ByteBuffer readBuffer = ByteBuffer.allocate(32768);
135143
final CharBuffer decodedBuffer = CharBuffer.allocate(32768);

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3321,7 +3321,7 @@ else if (encoding.equals("utf32")) {
33213321
}
33223322
}
33233323

3324-
protected static ByteBuffer decode8(SixModelObject buf, ThreadContext tc) {
3324+
public static ByteBuffer decode8(SixModelObject buf, ThreadContext tc) {
33253325
ByteBuffer bb;
33263326
if (buf instanceof VMArrayInstance_i8) {
33273327
VMArrayInstance_i8 bufi8 = (VMArrayInstance_i8)buf;

0 commit comments

Comments
 (0)