Ejemplo n.º 1
0
        // used by Send and SendReg (message types with payload)
        protected void DoSend(ErlOutputStream header, ErlOutputStream payload = null)
        {
            bool tw = ErlApp.TraceEnabled(TraceLevel, ErlTraceLevel.Wire);
            bool ts = ErlApp.TraceEnabled(TraceLevel, ErlTraceLevel.Send);

            if (tw || ts)
            {
                var h = header.InputStream(5).Read(true);

                m_Home.OnTrace(ErlTraceLevel.Wire, Direction.Outbound, () =>
                {
                    var hb = header.ToBinary();
                    return("{0} {1} (header_sz={2}{3})\n   Header: {4}{5}"
                           .Args(HeaderType(h), h.ToString(), hb.Length,
                                 payload == null ? string.Empty : ", msg_sz={0}".Args(payload.Length),
                                 hb.ToBinaryString(),
                                 payload == null ? string.Empty : "\n   Msg:    {0}".Args(payload.ToBinaryString())));
                });

                m_Home.OnTrace(ErlTraceLevel.Send, Direction.Outbound, () =>
                {
                    var o = payload == null ? "" : payload.InputStream(0).Read(true).ToString();
                    return("{0} {1} {2}".Args(HeaderType(h), h.ToString(), o));
                });
            }

            var written = (int)header.Length;

            lock (m_TcpClient)
            {
                try
                {
                    header.WriteTo(m_TcpClient.GetStream());
                    if (payload != null)
                    {
                        written += (int)payload.Length;
                        payload.WriteTo(m_TcpClient.GetStream());
                    }

                    m_SentBytes += written;
                    m_SentMsgs++;
                }
                catch (Exception e)
                {
                    Close();
                    throw e;
                }
            }

            onReadWrite(Direction.Outbound, written, m_SentBytes, m_SentMsgs);
        }
Ejemplo n.º 2
0
        // used by Send and SendReg (message types with payload)
        protected void DoSend(ErlOutputStream header, ErlOutputStream payload = null)
        {
            bool tw = ErlApp.TraceEnabled(TraceLevel, ErlTraceLevel.Wire);
              bool ts = ErlApp.TraceEnabled(TraceLevel, ErlTraceLevel.Send);

              if (tw || ts)
              {
            var h = header.InputStream(5).Read(true);

            m_Home.OnTrace(ErlTraceLevel.Wire, Direction.Outbound, () =>
            {
              var hb = header.ToBinary();
              return "{0} {1} (header_sz={2}{3})\n   Header: {4}{5}"
              .Args(HeaderType(h), h.ToString(), hb.Length,
                  payload == null ? string.Empty : ", msg_sz={0}".Args(payload.Length),
                  hb.ToBinaryString(),
                  payload == null ? string.Empty : "\n   Msg:    {0}".Args(payload.ToBinaryString()));
            });

            m_Home.OnTrace(ErlTraceLevel.Send, Direction.Outbound, () =>
            {
              var o = payload == null ? "" : payload.InputStream(0).Read(true).ToString();
              return "{0} {1} {2}".Args(HeaderType(h), h.ToString(), o);
            });
              }

              var written = (int)header.Length;

              lock (m_Transport)
              {
            try
            {
              header.WriteTo(m_Transport.GetStream());
              if (payload != null)
              {
            written += (int)payload.Length;
            payload.WriteTo(m_Transport.GetStream());
              }

              m_SentBytes += written;
              m_SentMsgs++;
            }
            catch (Exception e)
            {
              Close();
              throw e;
            }
              }

              onReadWrite(Direction.Outbound, written, m_SentBytes, m_SentMsgs);
        }