コード例 #1
0
ファイル: MessagePump.cs プロジェクト: telefrek/ldap
        /// <summary>
        /// public method to watch the reader and notify when new messages are available
        /// </summary>
        async Task Pump()
        {
            _log.LogInformation("LDAP pump started");
            // Need something to track if we should abandon existing tasks...etc.

            while (!_isClosed)
            {
                //if (_raw.DataAvailable)
                try
                {
                    // Ensure we can safely read the contents
                    if (await _reader.ReadAsync())
                    {
                        // read the next operation available
                        var message = await _reader.ReadResponseAsync();

                        if (message != null)
                        {
                            _log.LogInformation("Message received {0}", message.Operation);
                            if (_size == 0)     // new
                            {
                                _head.Message = message;
                                _tail         = _head;
                                _size         = 1;
                            }
                            else if (_size >= 16)     // shouldn't hardcode the 16
                            {
                                _head      = _head.Next;
                                _tail.Next = new MessagePumpNode {
                                    Message = message, Next = null
                                };
                                _tail = _tail.Next;
                            }
                            else
                            {
                                _tail.Next = new MessagePumpNode {
                                    Message = message, Next = null
                                };
                                _tail = _tail.Next;
                                _size++;
                            }

                            _event.Set();
                        }
                    }
                }
                catch (LDAPException ldapEx)
                {
                    _log.LogError(ldapEx.ToString());
                }
                catch (Exception ex)
                {
                    _log.LogError(ex.ToString());
                }
                // else
                // {
                //     await Task.Delay(250);
                // }
            }
        }
コード例 #2
0
ファイル: MessagePump.cs プロジェクト: telefrek/ldap
 public MessagePumpEnumerator(MessagePumpNode node, EventWaitHandle evt, int messageId, CancellationToken token)
 {
     _node      = node;
     _event     = evt;
     _messageId = messageId;
     _token     = token;
 }
コード例 #3
0
ファイル: MessagePump.cs プロジェクト: telefrek/ldap
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="reader">The reader to pump messages from</param>
 /// <param name="raw">The raw stream backing the reader</param>
 /// <param name="log"></param>
 public MessagePump(LDAPReader reader, NetworkStream raw, ILogger log)
 {
     _reader = reader;
     _raw    = raw;
     _head   = new MessagePumpNode();
     _tail   = null;
     _event  = new AutoResetEvent(false);
     _log    = log;
 }
コード例 #4
0
ファイル: MessagePump.cs プロジェクト: telefrek/ldap
        public bool MoveNext()
        {
            // No messages yet, keep reading until we find one
            if (Current != null && Current.IsTerminating)
            {
                return(false);
            }

            // Keep going until we find another message
            while (true)
            {
                if (_token.IsCancellationRequested)
                {
                    return(false);
                }

                if (_node.Message == null)
                {
                    _event.WaitOne(1000);
                }

                if (_node.Message != Current && _node.Message.MessageId == _messageId)
                {
                    Current = _node.Message;
                    return(true);
                }

                if (_node.Next != null)
                {
                    _node = _node.Next;
                }
                else
                {
                    _event.WaitOne(1000);
                }
            }
        }