EventStore.Transport.Tcp.TcpConnection.TrySend C# (CSharp) Метод

TrySend() приватный Метод

private TrySend ( ) : void
Результат void
        private void TrySend()
        {
            lock (_sendingLock)
            {
                lock (_sendQueueLock)
                    if (_isSending || _sendQueue.Count == 0 || _socket == null)
                        return;

                if (TcpConnectionMonitor.Default.IsSendBlocked())
                {
                    return;
                }
                _isSending = true;
            }

            _memoryStream.SetLength(0);

            ArraySegment<byte> sendPiece;
            lock (_sendQueueLock)
                while (_sendQueue.Count > 0)
                {
                    sendPiece = _sendQueue.Dequeue();
                    _memoryStream.Write(sendPiece.Array, sendPiece.Offset, sendPiece.Count);

                    if (_memoryStream.Length >= MaxSendPacketSize)
                        break;
                }
            Interlocked.Add(ref _bytesSent, _memoryStream.Length);
            _sendSocketArgs.SetBuffer(_memoryStream.GetBuffer(), 0, (int) _memoryStream.Length);

            if (_sendSocketArgs.Count == 0)
            {
                lock (_sendingLock) {
                    _isSending = false;
                    return;
                }
            }

            try
            {
                Interlocked.Increment(ref _sentAsyncs);

                //Console.WriteLine(String.Format("{0:mmss.fff}", DateTime.Now) + " sending " + _memoryStream.Length + " bytes.");
                NotifySendStarting((uint) _sendSocketArgs.Count);
                var firedAsync = _sendSocketArgs.AcceptSocket.SendAsync(_sendSocketArgs);
                NotifyStartSendingCompleted();
                if (!firedAsync)
                    ProcessSend(_sendSocketArgs);
            }
            catch (ObjectDisposedException)
            {
                ReturnSendingSocketArgs();
            }
        }

Usage Example

Пример #1
0
        internal static TcpConnection CreateConnectingTcpConnection(IPEndPoint remoteEndPoint,
                                                                    TcpClientConnector connector,
                                                                    Action <TcpConnection> onConnectionEstablished,
                                                                    Action <TcpConnection, SocketError> onConnectionFailed)
        {
            var connection = new TcpConnection(remoteEndPoint);

            connector.InitConnect(remoteEndPoint,
                                  (_, socket) =>
            {
                connection.InitSocket(socket);
                if (onConnectionEstablished != null)
                {
                    onConnectionEstablished(connection);
                }
                connection.TrySend();
            },
                                  (_, socketError) =>
            {
                if (onConnectionFailed != null)
                {
                    onConnectionFailed(connection, socketError);
                }
            });
            return(connection);
        }
All Usage Examples Of EventStore.Transport.Tcp.TcpConnection::TrySend