Пример #1
0
        private void ScheduleReconnect()
        {
            Task.Run(async() =>
            {
                while (true)
                {
                    await Task.Delay(_reconnectPeriod).ConfigureAwait(false);

                    var stream = _sink.TryInitializeStream();

                    if (stream != null)
                    {
                        lock (_syncObj)
                        {
                            _stream = stream;

                            byte[] data;

                            while ((data = _queue.Get()) != null)
                            {
                                if (!TrySendData(data))
                                {
                                    break;
                                }
                            }

                            if (_stream != null)
                            {
                                return;
                            }
                        }
                    }
                }
            });
        }
Пример #2
0
        public static TcpSender Initialize(string hostname, int port, TcpSenderSettings senderSets)
        {
            var sink  = new TcpSink(hostname, port, TimeSpan.FromSeconds(senderSets.WriteTimeoutSec), TimeSpan.FromSeconds(senderSets.ConnectTimeoutSec));
            var queue = new RingBuffer <byte[]>(senderSets.QueueSize);

            var sender = new TcpSender(sink, queue, TimeSpan.FromSeconds(senderSets.ReconnectPeriodSec))
            {
                _stream = sink.TryInitializeStream()
            };

            if (sender._stream == null)
            {
                sender.ScheduleReconnect();
            }

            return(sender);
        }