MCPcopy Create free account
hub / github.com/DeNA/PacketProxy / run

Method run

src/main/java/core/packetproxy/Simplex.java:194–314  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

192 }
193
194 @Override
195 public void run() {
196 if (in == null) {
197
198 return;
199 }
200 ByteArrayOutputStream bout = new ByteArrayOutputStream();
201 ExecutorService executor = Executors.newSingleThreadExecutor();
202 Callable<Integer> readTask = new Callable<Integer>() {
203
204 public Integer call() throws Exception {
205 int ret;
206 try {
207
208 ret = in.read(input_data);
209 } catch (SSLException e) {
210
211 // System.err.println(String.format("SSLException: %s", e.getMessage()));
212 ret = -1; // should be finished
213 } catch (SocketException e) {
214
215 // System.err.println(String.format("SocketException: %s", e.getMessage()));
216 ret = -1; // should be finished
217 }
218 return ret;
219 }
220 };
221
222 try {
223
224 while (!flag_break_loop) {
225
226 Future<Integer> future = executor.submit(readTask);
227 int timeout = bout.size() > 0 ? TIMEOUT : 24 * 60 * 60 * 1000;
228 int length = future.get(timeout, TimeUnit.MILLISECONDS);
229 if (length == -1) {
230
231 break;
232 }
233
234 bout.write(input_data, 0, length);
235 while (bout.size() > 0) {
236
237 int accepted_input_size = callOnPacketReceived(bout.toByteArray());
238 if (accepted_input_size < 0 || accepted_input_size > bout.size()) {
239
240 break;
241 }
242 byte[] accepted_array = ArrayUtils.subarray(bout.toByteArray(), 0, accepted_input_size);
243 byte[] unaccepted_array = ArrayUtils.subarray(bout.toByteArray(), accepted_input_size, bout.size());
244 bout.reset();
245 bout.write(unaccepted_array);
246
247 callOnChunkArrived(accepted_array);
248
249 for (byte[] pass_through_data = callOnChunkPassThrough(); pass_through_data != null
250 && pass_through_data.length > 0; pass_through_data = callOnChunkPassThrough()) {
251

Callers

nothing calls this directly

Calls 14

callOnPacketReceivedMethod · 0.95
callOnChunkArrivedMethod · 0.95
callOnChunkAvailableMethod · 0.95
callOnChunkReceivedMethod · 0.95
sendMethod · 0.95
errWithStackTraceMethod · 0.80
writeMethod · 0.65
logMethod · 0.65
sizeMethod · 0.45
getMethod · 0.45
toByteArrayMethod · 0.45

Tested by

no test coverage detected