Ejemplo n.º 1
0
        internal MpxWinClientSocket(MpxClientTransport transport,
            IPEndPoint remoteServer,
            ClientSite clientSite,
            MpxSocketReceiveAction<MpxClientTransport> receiveAction)
            : base(transport, remoteServer, clientSite, receiveAction)
        {
            m_Client = new TcpClient();
            m_Client.Connect(m_EndPoint);
            m_Socket = m_Client.Client;

            m_Client.NoDelay = true;
            m_Client.LingerState.Enabled = true;
            m_Client.LingerState.LingerTime = m_Transport.Binding.SocketLingerSec;

            m_Client.ReceiveBufferSize =  m_Transport.Binding.ClientReceiveBufferSize;
            m_Client.SendBufferSize    =  m_Transport.Binding.ClientSendBufferSize;

            m_Client.ReceiveTimeout    =  m_Transport.Binding.ClientReceiveTimeout;
            m_Client.SendTimeout       =  m_Transport.Binding.ClientSendTimeout;

            //Send ClientSite right away
            m_SendChunk.Position = 0;
            var sz = m_ClientSite.Serialize( m_SendChunk );
            m_Client.GetStream().Write(m_SendChunk.GetBuffer(), 0, sz);
            //------------------

            m_RArgs = new SocketState(m_Client.Client, m_ReceiveChunk.GetBuffer());
            m_RArgs.Completed += socketCallback;

            initiateReceive();
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
0
 private void processReceive(SocketState state)
 {
     try
     {
       processReceiveCore(state);
     }
     catch(Exception error)
     {
       Transport.Binding.WriteLog(LogSrc.Server,
                            Log.MessageType.Error,
                            "processReceiveCore() leaked: " + error.ToMessageWithType(),
                             "{0}.processRecive()".Args(GetType().Name), error);
       Dispose();//if process receive aborted then channel is irreperable
     }
 }
Ejemplo n.º 4
0
        internal MpxWinServerSocket(MpxListener listener,
            TcpClient client,
            ClientSite clientSite,
            MpxSocketReceiveAction<MpxServerTransport> receiveAction
            )
            : base(listener, (IPEndPoint)client.Client.RemoteEndPoint, clientSite, receiveAction)
        {
            m_Client = client;
            m_Socket = m_Client.Client;

            m_RArgs = new SocketState(m_Client.Client, m_ReceiveChunk.GetBuffer());
            m_RArgs.Completed += socketCallback;

            initiateReceive();
        }