Ejemplo n.º 1
0
        private void BeginSendTo(Event e)
        {
            int handle = e._Handle;

            EndPoint endPoint;
            using (new ReadLock(rwlock))
            {
                int count = map.Count;

                if (count == 0)
                {
                    Log.Error("{0} no known peers - dropped event {1}", Name, e);
                    goto next;
                }

                if (count == 1 && handle == 0)
                {
                    endPoint = map.Values[0];
                }
                else
                {
                    if (!map.TryGetValue(handle, out endPoint))
                    {
                        Log.Error("{0} unknown handle {1} - dropped event {2}",
                            Name, handle, e);
                        goto next;
                    }
                }
            }

            // Apply the datagram length limit.
            int length = e.GetLength();
            if (length > txBuffer.BlockSize)
            {
                Log.Error("{0} dropped big event {1}", Name, e);
                goto next;
            }

            txBuffer.Reset();
            Serializer serializer = new Serializer(txBuffer);
            serializer.Write(e.GetTypeId());
            e.Serialize(serializer);

            if (BufferTransform != null)
            {
                BufferTransform.Transform(txBuffer, (int)txBuffer.Length);
            }

            try
            {
                SendToInternal(endPoint);

                Diag.IncrementEventsSent();

                Log.Debug("{0} {1} sent event {2}", Name, handle, e);

                return;
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (Exception ex)
            {
                Log.Info("{0} send error {1}", Name, ex);
            }

            next:
            OnSendToInternal(0);
        }