/// <summary>
 ///  Initializes a new instance of the <see cref="T:ExitGames.Diagnostics.Monitoring.CounterSampleSender"/> class.
 /// </summary>
 /// <param name="senderId"> The sender id.</param>
 /// <param name="publishInterval">The publish interval.</param>
 /// <param name="socketSender"> The socket sender.</param>
 public CounterSampleSender(string senderId, int publishInterval, ISocketSender socketSender)
 {
     this.queue           = new LinkedList <byte[]>();
     this.senderId        = senderId;
     this.publishInterval = publishInterval;
     this.socketSender    = socketSender;
 }
 private void Stop()
 {
     lock (syncRoot)
     {
         if (!this.running)
         {
             return;
         }
         this.running = false;
     }
     if (this.counterSenderSubsciption != null)
     {
         this.counterSenderSubsciption.Dispose();
         this.counterSenderSubsciption = null;
     }
     if (this.counterSender != null)
     {
         this.counterSender.OnDisconnected -= new EventHandler(this.OnCounterSenderDisconnected);
         this.counterSender.OnError        -= new EventHandler <UnhandledExceptionEventArgs>(this.OnCounterSenderError);
         this.counterSender.Dispose();
         this.counterSender = null;
     }
     if (this.socketSender != null)
     {
         this.socketSender.Dispose();
         this.socketSender = null;
     }
 }
Example #3
0
 public Connection(IFireflyService services, AppDelegate app, ISocket socket, Action<ISocket> disconnected)
 {
     _services = services;
     _app = app;
     _socket = socket;
     _socketSender = new SocketSender(_services, _socket);
     _disconnected = disconnected;
 }
Example #4
0
 public Connection(IFireflyService services, AppDelegate app, ISocket socket, Action <ISocket> disconnected)
 {
     _services     = services;
     _app          = app;
     _socket       = socket;
     _socketSender = new SocketSender(_services, _socket);
     _disconnected = disconnected;
 }
 public CounterSampleSender(string senderId, int publishInterval, ISocketSender socketSender, int maxItemsInQueue, int maxSendRetries, int maxCounterPerPackage)
 {
     this.queue                = new LinkedList <byte[]>();
     this.senderId             = senderId;
     this.publishInterval      = publishInterval;
     this.socketSender         = socketSender;
     this.MaxQueueLength       = maxItemsInQueue;
     this.MaxRetryCount        = maxSendRetries;
     this.maxCounterPerPackage = maxCounterPerPackage;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ExitGames.Net.Sockets.PooledSender"/> class.
 /// </summary>
 /// <param name="sender">The <see cref="T:ExitGames.Net.Sockets.ISocketSender"/> that is used to send the data.</param>
 /// <param name="sendBatched">Indicates whether multiple data should be send batched.</param>
 /// <param name="packageSize">The size for batch packages.</param>
 public PooledSender(ISocketSender sender, bool sendBatched, int packageSize)
 {
     //Action<IList<ArraySegment<byte>>> action = null;
     //Action<ArraySegment<byte>> action2 = null;
     //Action<ArraySegment<byte>> action3 = null;
     this.batchMessage          = new BatchMessage();
     this.sender                = sender;
     this.packageSize           = packageSize;
     sendArraySegmentListAction = new Action <IList <ArraySegment <byte> > >(sender.Send);
     if (sendBatched)
     {
         enqueueAction = new Action <ArraySegment <byte> >(batchMessage.AddMessage);
         fiber         = new PoolFiber(new SendBatchedExecutor(this));
     }
     else
     {
         // action3 = delegate(ArraySegment<byte> s) { SendArraySegmentList(new ArraySegment<byte>[] { s }); };
         enqueueAction = s => SendArraySegmentList(new ArraySegment <byte>[] { s });
         fiber         = new PoolFiber();
     }
     fiber.Start();
 }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ExitGames.Net.Sockets.PooledSender"/> class.
 /// </summary>
 /// <param name="sender">The <see cref="T:ExitGames.Net.Sockets.ISocketSender"/> that is used to send the data.</param>
 public PooledSender(ISocketSender sender)
     : this(sender, true, DefaultBatchSize)
 {
 }
 public void Start()
 {
     lock (syncRoot)
     {
         if (this.running)
         {
             return;
         }
         this.running = true;
     }
     if (this.enabled)
     {
         try
         {
             if (this.protocol == ProtocolType.Pgm)
             {
                 PgmSender sender;
                 if (!NetworkInterface.GetIsNetworkAvailable())
                 {
                     log.Warn("CounterPublisher could not started because no network connection is available.");
                     return;
                 }
                 try
                 {
                     sender = new PgmSender(this.endPoint);
                     if (this.sendInterface == null)
                     {
                         sender.Connect();
                     }
                     else
                     {
                         sender.Connect(this.sendInterface.ToString());
                     }
                 }
                 catch (Exception exception)
                 {
                     log.WarnFormat("CounterPublisher could not started. To publish counter values the PGM protocol must be installed.\r\n: Error={0}", new object[] { exception });
                     throw;
                 }
                 this.socketSender = sender;
             }
             else if (this.protocol == ProtocolType.Udp)
             {
                 UdpSender sender2 = new UdpSender(this.endPoint);
                 sender2.Start();
                 this.socketSender = sender2;
             }
             else
             {
                 this.socketSender = new HttpSender(this.address);
             }
             this.counterSender                 = new CounterSampleSender(this.senderId, this.sendInterval, this.socketSender, this.maxRequestsInQueue, -1, this.maxItemsPerRequest);
             this.counterSenderSubsciption      = this.counterSender.SubscribeToChannel(this.counterPublisher.Channel);
             this.counterSender.OnDisconnected += new EventHandler(this.OnCounterSenderDisconnected);
             this.counterSender.OnError        += new EventHandler <UnhandledExceptionEventArgs>(this.OnCounterSenderError);
             this.counterPublisher.Start();
             this.counterSender.Start();
             log.InfoFormat("CounterPublisher started on: {0}", new object[] { this.address });
         }
         catch (SocketException exception2)
         {
             log.WarnFormat("CounterPublisher could not be created: ReturnCode={0}, Message={1}", new object[] { exception2.SocketErrorCode, exception2.Message });
             throw;
         }
     }
 }
Example #9
0
 public SocketAuthenLogic(ISocketSender sender, ISocketReceiver receiver)
 {
     _sender   = sender;
     _receiver = receiver;
 }
Example #10
0
            private async Task SendNextReadyBuffersAsync(Socket endpointSocket, int serialId, ISocketSender sender)
            {
                while (true)
                {
                    EndpointSendBufferState sendBufferState;
                    lock (this)
                    {
                        if (!UnpackedDataBuffers.TryGetValue(++serialId, out sendBufferState) || !sendBufferState.Ready)
                        {
                            UnpackingSerialId = serialId;
                            break;
                        }
                    }

                    var sendbuffer = sendBufferState.Buffer;
                    await sender.SendDataAsync(endpointSocket, sendbuffer.Array, sendbuffer.Offset, sendBufferState.BytesInBuffer);

                    RemoveAndReleaseBuffers(serialId);
                }
            }
Example #11
0
 public SocketBusinessLogic(ISocketSender sender, ISocketReceiver receiver)
 {
     _sender   = sender;
     _receiver = receiver;
 }
 public CounterSampleSender(string senderId, int publishInterval, ISocketSender socketSender, int maxCounterPerPackage)
     : this(senderId, publishInterval, socketSender)
 {
     this.maxCounterPerPackage = maxCounterPerPackage;
 }