Пример #1
0
        /// <summary>
        /// WriteCommand is a thread safe method to write a Command
        /// to this connection, and flush.
        /// </summary>
        public void WriteCommand(Command cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            try
            {
                lock (_mtx)
                {
                    int size = cmd.GetByteCount();
                    if (size > _bigBufSize)
                    {
                        _bigBuf     = new byte[size];
                        _bigBufSize = size;
                    }

                    cmd.WriteTo(this, _bigBuf);

                    Flush();
                }
            }
            catch (Exception ex)
            {
                log(LogLevel.Error, string.Format("IO error - {0}", ex));
                _delegate.OnIOError(this, ex);
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// WriteCommand is a thread safe method to write a Command
        /// to this connection, and flush.
        /// </summary>
        public void WriteCommand(Command cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            try
            {
                lock (_mtx)
                {
                    int size = cmd.GetByteCount();
                    if (size > _bigBufSize)
                    {
                        _bigBuf     = new byte[size];
                        _bigBufSize = size;
                    }

                    cmd.WriteTo(this, _bigBuf);

                    Flush();
                }
            }
            catch (Exception ex)
            {
                object msg = (ex is ConnectionClosedException) ? ex.Message : (object)ex;
                log(LogLevel.Error, string.Format("Conn.WriteCommand IO error - {0}", msg));
                _delegate.OnIOError(this, ex);
                throw;
            }
        }