Beispiel #1
0
        private void Send(HandlerMessage message)
        {
            try
            {
                message.Context.SendReady.Wait(message.Context.Cancellation.Token); // block until previous message is in the socket buffer
            }
            catch (OperationCanceledException)
            {
                return;
            }

            try
            {
                if (message.Context.Connected)
                {
                    List <ArraySegment <byte> > data = message.IsRaw ? message.DataFrame.AsRaw() : message.DataFrame.AsFrame();
                    message.Context.SendEventArgs.UserToken  = message; // 2014-02-04 moved here from beginning of method. When SendEventArgs_Completed is called the message must correspond to the one that was sent!
                    message.Context.SendEventArgs.BufferList = data;
                    message.Context.Connection.Client.SendAsync(message.Context.SendEventArgs);
                }
            }
            catch
            {
                message.Context.Disconnect();
            }
        }
 static Task SendHandlerMessage(IMessageSession endpointInstance)
 {
     Console.WriteLine();
     Console.WriteLine("HandlerMessage sent");
     var message = new HandlerMessage();
     return endpointInstance.SendLocal(message);
 }
    static Task SendHandlerMessage(IMessageSession endpointInstance)
    {
        Console.WriteLine();
        Console.WriteLine("HandlerMessage sent");
        var message = new HandlerMessage();

        return(endpointInstance.SendLocal(message));
    }
Beispiel #4
0
    static void SendHandlerMessage(IBus bus)
    {
        var message = new HandlerMessage();

        bus.SendLocal(message);

        Console.WriteLine();
        Console.WriteLine("HandlerMessage sent");
    }
Beispiel #5
0
 /// <summary>
 /// Sends the specified data.
 /// </summary>
 /// <param name="dataFrame">The data.</param>
 /// <param name="context">The user context.</param>
 /// <param name="raw">whether or not to send raw data</param>
 /// <param name="close">if set to <c>true</c> [close].</param>
 public void Send(DataFrame dataFrame, Context context, bool raw = false, bool close = false)
 {
     if (context.Connected)
     {
         HandlerMessage message = new HandlerMessage {
             DataFrame = dataFrame, Context = context, IsRaw = raw, DoClose = close
         };
         MessageQueue.Enqueue(message);
     }
 }
Beispiel #6
0
        private void Send(HandlerMessage message)
        {
            message.Context.SendEventArgs.UserToken = message;
            message.Context.SendReady.Wait();

            try
            {
                List <ArraySegment <byte> > data = message.IsRaw ? message.DataFrame.AsRaw() : message.DataFrame.AsFrame();
                message.Context.SendEventArgs.BufferList = data;
                message.Context.Connection.Client.SendAsync(message.Context.SendEventArgs);
            }
            catch
            {
                message.Context.Disconnect();
            }
        }
Beispiel #7
0
 /// <summary>
 /// Sends the specified data.
 /// </summary>
 /// <param name="dataFrame">The data.</param>
 /// <param name="context">The user context.</param>
 /// <param name="raw">whether or not to send raw data</param>
 /// <param name="close">if set to <c>true</c> [close].</param>
 public void Send(DataFrame dataFrame, Context context, bool raw = false, bool close = false)
 {
     try
     {
         if (context.Connected)
         {
             HandlerMessage message = new HandlerMessage {
                 DataFrame = dataFrame, Context = context, IsRaw = raw, DoClose = close
             };
             MessageQueue.Enqueue(message);
         }
     }
     catch (ObjectDisposedException)
     {
     }
 }
Beispiel #8
0
        void SendEventArgs_Completed(object sender, SocketAsyncEventArgs e)
        {
            HandlerMessage message = (HandlerMessage)e.UserToken;

            if (e.SocketError != SocketError.Success)
            {
                message.Context.Disconnect();
                return;
            }

            message.Context.SendReady.Release();
            message.Context.UserContext.OnSend();

            if (message.DoClose)
            {
                message.Context.Disconnect();
            }
        }
Beispiel #9
0
        private void Send(HandlerMessage message)
        {
            message.Context.SendEventArgs.UserToken = message;

            try
            {
              message.Context.SendReady.Wait(cancellation.Token);
            }
            catch (OperationCanceledException)
            {
              return;
            }

            try
            {
                List<ArraySegment<byte>> data = message.IsRaw ? message.DataFrame.AsRaw() : message.DataFrame.AsFrame();
                message.Context.SendEventArgs.BufferList = data;
                message.Context.Connection.Client.SendAsync(message.Context.SendEventArgs);
            }
            catch
            {
                message.Context.Disconnect();
            }
        }
Beispiel #10
0
 /// <summary>
 /// Sends the specified data.
 /// </summary>
 /// <param name="dataFrame">The data.</param>
 /// <param name="context">The user context.</param>
 /// <param name="raw">whether or not to send raw data</param>
 /// <param name="close">if set to <c>true</c> [close].</param>
 public void Send(DataFrame dataFrame, Context context, bool raw = false, bool close = false)
 {
     if (context.Connected)
     {
         HandlerMessage message = new HandlerMessage { DataFrame = dataFrame, Context = context, IsRaw = raw, DoClose = close };
         MessageQueue.Enqueue(message);
     }
 }
Beispiel #11
0
        private void Send(HandlerMessage message)
        {
            message.Context.SendEventArgs.UserToken = message;
            message.Context.SendReady.Wait();

            try
            {
                // mjb

                /*
                List<ArraySegment<byte>> data = message.IsRaw ? message.DataFrame.AsRaw() : message.DataFrame.AsFrame();
                message.Context.SendEventArgs.BufferList = data;
                message.Context.Connection.Client.SendAsync(message.Context.SendEventArgs);
                 */

                if (message.Context.SslStream != null)
                {
                    SendWorker sw = new SendWorker() { message = message };
                    Thread wt = new Thread(sw.Send);
                    wt.Start();
                }
                else
                {
                    List<ArraySegment<byte>> data = message.IsRaw ? message.DataFrame.AsRaw() : message.DataFrame.AsFrame();
                    message.Context.SendEventArgs.BufferList = data;
                    message.Context.Connection.Client.SendAsync(message.Context.SendEventArgs);
                }

            }
            catch
            {
                message.Context.Disconnect();
            }
        }
Beispiel #12
0
        private void Send(HandlerMessage message)
        {
            try
            {
              message.Context.SendReady.Wait(message.Context.Cancellation.Token); // block until previous message is in the socket buffer
            }
            catch (OperationCanceledException)
            {
              return;
            }

            try
            {
                if (message.Context.Connected)
                {
                    List<ArraySegment<byte>> data = message.IsRaw ? message.DataFrame.AsRaw() : message.DataFrame.AsFrame();
                    message.Context.SendEventArgs.UserToken = message; // 2014-02-04 moved here from beginning of method. When SendEventArgs_Completed is called the message must correspond to the one that was sent!
                    message.Context.SendEventArgs.BufferList = data;
                    message.Context.Connection.Client.SendAsync(message.Context.SendEventArgs);
                }
            }
            catch
            {
                message.Context.Disconnect();
            }
        }