private void InitializeMessageProcessing() { lock (this.syn_msg) { this.ReInitializeMessageProcessing(); this.message_state = TCPIPClient.EMessageProcessingState.MESSAGE_HEADER; } }
private void OnDataRead(IAsyncResult ar) { int asyncState = (int)ar.AsyncState; try { this.buffer_bytes_available += this.ns.EndRead(ar); if (this.buffer_bytes_available == 0) { return; } } catch (Exception ex) { } lock (this.syn_msg) { while (this.buffer_bytes_available > 0) { switch (this.message_state) { case TCPIPClient.EMessageProcessingState.MESSAGE_HEADER: int num1 = (int)Math.Min((long)(10U - this.msg_cursor), (long)this.buffer_bytes_available); Array.Copy((Array)this.buffer, (long)this.buffer_cursor, (Array)this.msg_header_storage, (long)this.msg_cursor, (long)num1); this.msg_cursor += (uint)num1; this.buffer_cursor += num1; this.buffer_bytes_available -= num1; if (this.msg_cursor == 10U) { this.importAndQualifyHeader(); this.msg_data = new byte[this.msg_len]; Array.Copy((Array)this.msg_header_storage, (Array)this.msg_data, 10); if ((long)this.msg_cursor == (long)this.msg_len) { this.TriggerMessageEvent(this.msg_ver, this.msg_type, this.msg_id, this.msg_data); this.ReInitializeMessageProcessing(); this.message_state = TCPIPClient.EMessageProcessingState.MESSAGE_HEADER; continue; } this.message_state = TCPIPClient.EMessageProcessingState.MESSAGE_BODY; continue; } continue; case TCPIPClient.EMessageProcessingState.MESSAGE_BODY: int num2 = (int)Math.Min((long)this.msg_len - (long)this.msg_cursor, (long)this.buffer_bytes_available); Array.Copy((Array)this.buffer, (long)this.buffer_cursor, (Array)this.msg_data, (long)this.msg_cursor, (long)num2); this.msg_cursor += (uint)num2; this.buffer_cursor += num2; this.buffer_bytes_available -= num2; if ((long)this.msg_cursor == (long)this.msg_len) { this.TriggerMessageEvent(this.msg_ver, this.msg_type, this.msg_id, this.msg_data); this.ReInitializeMessageProcessing(); this.message_state = TCPIPClient.EMessageProcessingState.MESSAGE_HEADER; continue; } continue; default: continue; } } } try { this.StartNewBufferReceive(); } catch { } }