10
10
import java .nio .charset .CharsetDecoder ;
11
11
import java .nio .charset .CharsetEncoder ;
12
12
import java .nio .charset .CoderResult ;
13
+ import java .nio .charset .CodingErrorAction ;
13
14
14
15
import org .perl6 .nqp .runtime .ExceptionHandling ;
15
16
import org .perl6 .nqp .runtime .HLLConfig ;
@@ -47,26 +48,33 @@ public void connect(final ThreadContext tc, String host, int port,
47
48
final CompletionHandler <Void , AsyncTaskInstance > handler
48
49
= new CompletionHandler <Void , AsyncTaskInstance >() {
49
50
51
+ HLLConfig hllConfig = tc .curFrame .codeRef .staticInfo .compUnit .hllConfig ;
52
+ final SixModelObject IOType = hllConfig .ioType ;
53
+ final SixModelObject Array = hllConfig .listType ;
54
+ final SixModelObject Str = hllConfig .strBoxType ;
55
+
50
56
@ Override
51
57
public void completed (Void v , AsyncTaskInstance task ) {
52
58
ThreadContext curTC = tc .gc .getCurrentThreadContext ();
53
59
54
- SixModelObject IOType = curTC .curFrame .codeRef .staticInfo .compUnit .hllConfig .ioType ;
55
60
IOHandleInstance ioHandle = (IOHandleInstance ) IOType .st .REPR .allocate (curTC ,
56
61
IOType .st );
57
62
ioHandle .handle = task .handle ;
58
-
59
- SixModelObject Array = curTC .curFrame .codeRef .staticInfo .compUnit .hllConfig .listType ;
60
- SixModelObject result = Array .st .REPR .allocate (curTC , Array .st );
61
- result .push_boxed (curTC , task .schedulee );
62
- result .push_boxed (curTC , ioHandle );
63
-
64
- ((ConcBlockingQueueInstance ) task .queue ).push_boxed (curTC , result );
63
+ callback (curTC , task , ioHandle , Str );
65
64
}
66
65
67
66
@ Override
68
- public void failed (Throwable exc , AsyncTaskInstance task ) {
67
+ public void failed (Throwable t , AsyncTaskInstance task ) {
68
+ ThreadContext curTC = tc .gc .getCurrentThreadContext ();
69
+ callback (curTC , task , IOType , Ops .box_s (t .toString (), Str , curTC ));
70
+ }
69
71
72
+ protected void callback (ThreadContext tc , AsyncTaskInstance task , SixModelObject ioHandle , SixModelObject err ) {
73
+ SixModelObject result = Array .st .REPR .allocate (tc , Array .st );
74
+ result .push_boxed (tc , task .schedulee );
75
+ result .push_boxed (tc , ioHandle );
76
+ result .push_boxed (tc , err );
77
+ ((ConcBlockingQueueInstance ) task .queue ).push_boxed (tc , result );
70
78
}
71
79
};
72
80
@@ -82,28 +90,33 @@ public void writeStr(final ThreadContext tc, final AsyncTaskInstance task, Strin
82
90
try {
83
91
ByteBuffer buffer = enc .encode (CharBuffer .wrap (toWrite ));
84
92
93
+ HLLConfig hllConfig = tc .curFrame .codeRef .staticInfo .compUnit .hllConfig ;
94
+ final SixModelObject Array = hllConfig .listType ;
95
+ final SixModelObject Int = hllConfig .intBoxType ;
96
+ final SixModelObject Null = hllConfig .nullValue ;
97
+ final SixModelObject Str = hllConfig .strBoxType ;
98
+
85
99
CompletionHandler <Integer , AsyncTaskInstance > handler
86
100
= new CompletionHandler <Integer , AsyncTaskInstance >() {
87
101
88
102
@ Override
89
- public void completed (Integer bytesWritten , AsyncTaskInstance attachment ) {
90
- SixModelObject Array = tc .curFrame .codeRef .staticInfo .compUnit .hllConfig .listType ;
91
- SixModelObject Int = tc .curFrame .codeRef .staticInfo .compUnit .hllConfig .intBoxType ;
92
- SixModelObject Null = tc .curFrame .codeRef .staticInfo .compUnit .hllConfig .nullValue ;
93
-
103
+ public void completed (Integer bytesWritten , AsyncTaskInstance task ) {
94
104
ThreadContext curTC = tc .gc .getCurrentThreadContext ();
95
-
96
- SixModelObject result = Array .st .REPR .allocate (curTC , Array .st );
97
- result .push_boxed (curTC , task .schedulee );
98
- result .push_boxed (curTC , Ops .box_i (bytesWritten , Int , curTC ));
99
- result .push_boxed (curTC , Null );
100
-
101
- ((ConcBlockingQueueInstance ) task .queue ).push_boxed (curTC , result );
105
+ callback (curTC , task , Ops .box_i (bytesWritten , Int , curTC ), Null );
102
106
}
103
107
104
108
@ Override
105
- public void failed (Throwable exc , AsyncTaskInstance attachment ) {
106
- // TODO Auto-generated method stub
109
+ public void failed (Throwable t , AsyncTaskInstance attachment ) {
110
+ ThreadContext curTC = tc .gc .getCurrentThreadContext ();
111
+ callback (curTC , task , Str , Ops .box_s (t .toString (), Str , curTC ));
112
+ }
113
+
114
+ protected void callback (ThreadContext tc , AsyncTaskInstance task , SixModelObject bytesWritten , SixModelObject err ) {
115
+ SixModelObject result = Array .st .REPR .allocate (tc , Array .st );
116
+ result .push_boxed (tc , task .schedulee );
117
+ result .push_boxed (tc , bytesWritten );
118
+ result .push_boxed (tc , err );
119
+ ((ConcBlockingQueueInstance ) task .queue ).push_boxed (tc , result );
107
120
}
108
121
};
109
122
@@ -162,7 +175,7 @@ public void completed(Integer numRead, AsyncTaskInstance task) {
162
175
@ Override
163
176
public void failed (Throwable t , AsyncTaskInstance task ) {
164
177
ThreadContext curTC = tc .gc .getCurrentThreadContext ();
165
- callback (curTC , task , -1 , Str , Ops .box_s (t .getMessage (), Str , tc ));
178
+ callback (curTC , task , -1 , Str , Ops .box_s (t .toString (), Str , tc ));
166
179
}
167
180
168
181
protected void callback (ThreadContext tc , AsyncTaskInstance task , long seq , SixModelObject str , SixModelObject err ) {
0 commit comments