private void processReceiveCore(SocketState state) { var readNow = state.BytesTransferred; if (state.SocketError != SocketError.Success || readNow <= 0) { Dispose(); ReleaseMemChunksAfterAsyncOperations();//socket closed/client has disconnected return; } m_ReceiveChunk.Position += readNow; var hasSize = state.HasMsgSize; if (!hasSize && m_ReceiveChunk.Position >= sizeof(int)) { state.WireMsgSize = m_ReceiveChunk.GetBuffer().ReadBEInt32(); hasSize = true; //check max msg size if (state.WireMsgSize < 1 || state.WireMsgSize > Transport.Binding.MaxMsgSize) { Instrumentation.ServerGotOverMaxMsgSizeErrorEvent.Happened(Transport.Node); Transport.Binding.WriteLog(LogSrc.Server, Log.MessageType.Error, StringConsts.GLUE_MAX_MSG_SIZE_EXCEEDED_ERROR.Args(state.WireMsgSize, Transport.Binding.MaxMsgSize, "processReceive()"), "{0}.processRecive()".Args(GetType().Name)); // This is unrecoverable error - close the channel! Dispose(); ReleaseMemChunksAfterAsyncOperations();//socket closed return; } if (state.WireMsgSize > m_ReceiveChunk.Length) //grow chunk if it is not large enough { m_ReceiveChunk.SetLength(state.WireMsgSize); } } var got = (int)m_ReceiveChunk.Position; if (hasSize && got >= state.WireMsgSize) //got all { WireMsg msg = new WireMsg(m_ReceiveChunk); msg.UpdateBufferStats(); this.InvokeReceive(msg); initiateReceive(); return; } state.SetBuffer(m_ReceiveChunk.GetBuffer(), got, (hasSize ? state.WireMsgSize : sizeof(int)) - got); continueReceive(); }
protected override void DoSend(WireMsg data) { if (!Active) { throw new ProtocolException(StringConsts.GLUE_MPX_SOCKET_SEND_CLOSED_ERROR, closeChannel: true); } try { data.UpdateBufferStats(); m_Client.GetStream().Write(data.Buffer, 0, data.BufferUsedSize); } catch (Exception error) { Dispose(); throw new ProtocolException(error.Message, error, closeChannel: true); } }
private void processReceiveCore(SocketState state) { var readNow = state.BytesTransferred; if (state.SocketError != SocketError.Success || readNow <=0) { Dispose(); ReleaseMemChunksAfterAsyncOperations();//socket closed/client has disconnected return; } m_ReceiveChunk.Position+=readNow; var hasSize = state.HasMsgSize; if (!hasSize && m_ReceiveChunk.Position>=sizeof(int)) { state.WireMsgSize = m_ReceiveChunk.GetBuffer().ReadBEInt32(); hasSize = true; //check max msg size if (state.WireMsgSize < 1 || state.WireMsgSize>Transport.Binding.MaxMsgSize) { Instrumentation.ServerGotOverMaxMsgSizeErrorEvent.Happened(Transport.Node); Transport.Binding.WriteLog(LogSrc.Server, Log.MessageType.Error, StringConsts.GLUE_MAX_MSG_SIZE_EXCEEDED_ERROR.Args(state.WireMsgSize, Transport.Binding.MaxMsgSize, "processReceive()"), "{0}.processRecive()".Args(GetType().Name)); // This is unrecoverable error - close the channel! Dispose(); ReleaseMemChunksAfterAsyncOperations();//socket closed return; } if (state.WireMsgSize>m_ReceiveChunk.Length) //grow chunk if it is not large enough m_ReceiveChunk.SetLength(state.WireMsgSize); } var got = (int)m_ReceiveChunk.Position; if (hasSize && got >= state.WireMsgSize) //got all { WireMsg msg = new WireMsg(m_ReceiveChunk); msg.UpdateBufferStats(); this.InvokeReceive(msg); initiateReceive(); return; } state.SetBuffer(m_ReceiveChunk.GetBuffer(), got, (hasSize ? state.WireMsgSize : sizeof(int)) - got); continueReceive(); }
protected override void DoSend(WireMsg data) { if (!Active) throw new ProtocolException(StringConsts.GLUE_MPX_SOCKET_SEND_CLOSED_ERROR, closeChannel: true); try { data.UpdateBufferStats(); m_Client.GetStream().Write(data.Buffer, 0, data.BufferUsedSize); } catch(Exception error) { Dispose(); throw new ProtocolException(error.Message, error, closeChannel: true); } }