private void HandleOneRequest(OnDemandData request) { waiting = true; byte[] data = null; if (clientInstance.caches[0] != null) { data = clientInstance.caches[request.dataType + 1].decompress((int)request.id); } if (!crcMatches(versions[request.dataType][request.id], crcs[request.dataType][request.id], data)) { data = null; } lock (mandatoryRequests) { if (data == null) { unrequested.pushBack(request); } else { request.InitializeBuffer(data); lock (complete) { complete.pushBack(request); } } } }
private void readData() { try { int j = socket.Available; if (expectedSize == 0 && j >= 6) { waiting = true; for (int k = 0; k < 6; k += inputStream.Read(payload, k, 6 - k)) { ; } int l = payload[0] & 0xff; int j1 = ((payload[1] & 0xff) << 8) + (payload[2] & 0xff); int l1 = ((payload[3] & 0xff) << 8) + (payload[4] & 0xff); int i2 = payload[5] & 0xff; current = null; for (OnDemandData onDemandData = (OnDemandData)requested .peekFront(); onDemandData != null; onDemandData = (OnDemandData)requested.getPrevious()) { if (onDemandData.dataType == l && onDemandData.id == j1) { current = onDemandData; } if (current != null) { onDemandData.loopCycle = 0; } } if (current != null) { loopCycle = 0; if (l1 == 0) { signlink.reporterror("Rej: " + l + "," + j1); current.ClearBuffer(); if (current.incomplete) { lock (complete) { complete.pushBack(current); } } else { current.unlink(); } current = null; } else { if (current.buffer == null && i2 == 0) { current.InitializeBuffer(new byte[l1]); } if (current.buffer == null && i2 != 0) { throw new IOException("missing start of file"); } } } completedSize = i2 * 500; expectedSize = 500; if (expectedSize > l1 - i2 * 500) { expectedSize = l1 - i2 * 500; } } if (expectedSize > 0 && j >= expectedSize) { waiting = true; byte[] abyte0 = payload; int i1 = 0; if (current != null) { abyte0 = current.buffer; i1 = completedSize; } for (int k1 = 0; k1 < expectedSize; k1 += inputStream.Read(abyte0, k1 + i1, expectedSize - k1)) { ; } if (expectedSize + completedSize >= abyte0.Length && current != null) { if (clientInstance.caches[0] != null) { clientInstance.caches[current.dataType + 1].put(abyte0.Length, abyte0, (int)current.id); } if (!current.incomplete && current.dataType == 3) { current.incomplete = true; current.dataType = 93; } if (current.incomplete) { lock (complete) { complete.pushBack(current); } } else { current.unlink(); } } expectedSize = 0; } } catch (IOException ioexception) { try { socket.Close(); } catch (Exception _ex) { } socket = null; inputStream = null; outputStream = null; expectedSize = 0; } }