private void StartSend(object packet)
        {
            if (!_issueCountFlag.Increment())
                return;

            var packetLen = Settings.PacketSerializer.EstimateLength(packet);
            var tailSize = 0;
            if (packetLen > _sendBuffer.Length)
                tailSize = packetLen - _sendBuffer.Length;

            var stream = new HeadTailWriteStream(new ArraySegment<byte>(_sendBuffer), tailSize);
            try
            {
                Settings.PacketSerializer.Serialize(stream, packet);
            }
            catch (Exception e)
            {
                if (_logger != null)
                    _logger.WarnFormat("Exception raised in serializing", e);
                HandleSerializeError(SerializeError.SerializeExceptionRaised);
                return;
            }

            var streamLength = (int)stream.Length;
            if (streamLength <= _sendBuffer.Length)
            {
                // 전송 버퍼안으로 보낼 수 있으므로 Normal 모드

                _sendOffset = 0;
                _sendLength = streamLength;
            }
            else
            {
                // 패킷 크기가 최대 크기보다 큰지 확인

                if (streamLength > Settings.SendBufferMaxSize)
                {
                    HandleSerializeError(SerializeError.SerializeSizeExceeded);
                    return;
                }

                // 전송 버퍼를 넘어서는 크기이므로 Large 모드로 전환

                _sendOffset = 0;
                _sendLength = _sendBuffer.Length;

                _sendLargeBuffer = stream.Tail;
                _sendLargeOffset = 0;
                _sendLargeLength = streamLength - _sendBuffer.Length;

                Debug.Assert(_sendLargeBuffer != null && _sendLargeLength > 0, "It should be valid");
            }

            IssueSend();
        }
        private void StartSend(object packet)
        {
            if (!_issueCountFlag.Increment())
            {
                return;
            }

            var packetLen = Settings.PacketSerializer.EstimateLength(packet);
            var tailSize  = 0;

            if (packetLen > _sendBuffer.Length)
            {
                tailSize = packetLen - _sendBuffer.Length;
            }

            var stream = new HeadTailWriteStream(new ArraySegment <byte>(_sendBuffer), tailSize);

            try
            {
                Settings.PacketSerializer.Serialize(stream, packet);
            }
            catch (Exception e)
            {
                if (_logger != null)
                {
                    _logger.WarnFormat("Exception raised in serializing", e);
                }
                HandleSerializeError(SerializeError.SerializeExceptionRaised);
                return;
            }

            var streamLength = (int)stream.Length;

            if (streamLength <= _sendBuffer.Length)
            {
                // 전송 버퍼안으로 보낼 수 있으므로 Normal 모드

                _sendOffset = 0;
                _sendLength = streamLength;
            }
            else
            {
                // 패킷 크기가 최대 크기보다 큰지 확인

                if (streamLength > Settings.SendBufferMaxSize)
                {
                    HandleSerializeError(SerializeError.SerializeSizeExceeded);
                    return;
                }

                // 전송 버퍼를 넘어서는 크기이므로 Large 모드로 전환

                _sendOffset = 0;
                _sendLength = _sendBuffer.Length;

                _sendLargeBuffer = stream.Tail;
                _sendLargeOffset = 0;
                _sendLargeLength = streamLength - _sendBuffer.Length;

                Debug.Assert(_sendLargeBuffer != null && _sendLargeLength > 0, "It should be valid");
            }

            IssueSend();
        }