Exemple #1
0
        private void sendSocketResponse(MpxServerSocket socket, ResponseMsg response)
        {
            var chunk = socket.GetSendChunk();

            try
            {
                var frame = new WireFrame(WireFrame.SLIM_FORMAT, true, response.RequestID);
                var size  = serialize(chunk, frame, response);
                var wm    = new WireMsg(chunk);


                Binding.DumpMsg(true, response, chunk.GetBuffer(), 0, (int)chunk.Position);

                if (size > Binding.MaxMsgSize)
                {
                    Instrumentation.ServerSerializedOverMaxMsgSizeErrorEvent.Happened(Node);
                    throw new MessageSizeException(size, Binding.MaxMsgSize, "sendResponse(" + response.RequestID + ")");
                }

                socket.Send(wm);

                stat_MsgSent();
                stat_BytesSent(size);
            }
            catch
            {
                stat_Errors();
                throw;
            }
            finally
            {
                socket.ReleaseSendChunk();
            }
        }
Exemple #2
0
            public bool RemoveSocket(MpxServerSocket socket)
            {
                if (Transport.Binding.InstrumentServerTransportStat)
                {
                    Instrumentation.ClientDisconnectedEvent.Happened(socket.ClientSite.Name);
                }

                Interlocked.Decrement(ref Transport.m_OpenChannels);
                lock (m_Sockets) return(m_Sockets.Remove(socket));
            }
Exemple #3
0
            public void AddSocket(MpxServerSocket socket)
            {
                if (Transport.Binding.InstrumentServerTransportStat)
                {
                    Instrumentation.ClientConnectedEvent.Happened(socket.ClientSite.Name);
                }

                Interlocked.Increment(ref Transport.m_OpenChannels);
                lock (m_Sockets) m_Sockets.Add(socket);
            }
Exemple #4
0
        private bool sendResponse(ResponseMsg response)
        {
            try
            {
                MpxServerSocket socket = getSocket(response);
                if (socket == null || !socket.Active)
                {
                    return(false);
                }

                try
                {
                    sendSocketResponse(socket, response);
                }
                catch (Exception err1)
                {
                    var commError = err1 is SocketException ||
                                    err1 is System.IO.IOException ||
                                    (err1 is ProtocolException && ((ProtocolException)err1).CloseChannel);
                    stat_Errors();
                    if (commError)
                    {
                        throw;     //do nothing - just close the channel
                    }
                    if (response != null)
                    {
                        try
                        {
                            var response2 = Glue.ServerHandleRequestFailure(response.RequestID, false, err1, response.BindingSpecificContext);
                            sendSocketResponse(socket, response2);
                        }
                        catch (Exception e)
                        {
                            Binding.WriteLog(
                                LogSrc.Server,
                                Log.MessageType.Warning,
                                StringConsts.GLUE_CLIENT_THREAD_ERROR + "couldn't deliver response to client's request: " + e.Message,
                                relatedTo: response.RequestID.ToGuid(),
                                from: "MpxServerTransport.sendResponse",
                                exception: e);
                        }
                    }
                }
                return(true);
            }
            catch (Exception error)
            {
                Binding.WriteLog(LogSrc.Server, Log.MessageType.Error, error.ToMessageWithType(), "MpxServerTransport.sendResponse()", error);
                if (error is MessageSizeException)
                {
                    return(true);
                }
                return(false);
            }
        }
Exemple #5
0
        /// <summary>
        /// Notifies the transport that site connection has arrived so the transport may allocate some site/socket-specific state.
        /// Called from listener
        /// </summary>
        internal void ClientSiteConnected(MpxServerSocket socket)
        {
            var sites = m_ClientSites;

            if (sites == null)
            {
                return;
            }

            var existing = sites.GetOrRegister(socket.ClientSite.Name, (_) => new clientSiteState(this, socket.ClientSite), true);

            existing.AddSocket(socket);
        }
Exemple #6
0
        /// <summary>
        /// Notifies the transport that site connection has closed/broke so the transport may de-allocate some site/socket-specific state.
        /// Called from listener
        /// </summary>
        internal void ClientSiteDisconnected(MpxServerSocket socket)
        {
            var sites = m_ClientSites;

            if (sites == null)
            {
                return;
            }

            var existing = sites[socket.ClientSite.Name];

            if (existing == null)
            {
                return;
            }

            existing.RemoveSocket(socket);
        }