Пример #1
0
 public WebsocketTopicClient(Uri uri, DelegateConnected connected, CompletionQueue completion_queue)
 {
     message_client = new WebsocketMessageClient(
         uri, WebsocketTopicServer.protocol, connected, MessageWaiting, completion_queue);
     topic_client = new TopicClient(message_client);
     this.completion_queue = completion_queue;
 }
Пример #2
0
 public SendQueue(CompletionQueue completion_queue, ISendAsync iSendAsync)
 {
     this.completion_queue = completion_queue;
     if (null == completion_queue) throw new ArgumentException();
     this.iSendAsync = iSendAsync;
     if (null == iSendAsync) throw new ArgumentException();
 }
Пример #3
0
 public WebsocketSendAsync(WebSocket webSocket, CompletionQueue completion_queue)
 {
     if (null == webSocket) throw new ArgumentException();
     this.webSocket = webSocket;
     if (null == completion_queue) throw new ArgumentException();
     this.completion_queue = completion_queue;
 }
Пример #4
0
 public TcpTopicClientSAE(IPEndPoint ipEndPoint, DelegateConnected connected, 
     CompletionQueue completion_queue)
 {
     message_client = new TcpMessageClientSAE(
         ipEndPoint, connected, MessageWaiting, completion_queue);
     topic_client = new TopicClient(message_client);
     this.completion_queue = completion_queue;
 }
Пример #5
0
 public TcpSendIAR(Socket socket, CompletionQueue completion_queue)
 {
     if (null == socket) throw new ArgumentException();
     this.socket = socket;
     if (null == completion_queue) throw new ArgumentException();
     this.completion_queue = completion_queue;
     writer = new BinaryWriter(ms);
 }
Пример #6
0
 void ISendAsync.SendMessage(Message message, CompletionQueue.DelegateCompletionCallback callback)
 {
     //todo, assert overlap depth = 1
     ArraySegment<byte> buffer = new ArraySegment<byte>(message.SerializeBytes());
     webSocket.SendAsync(buffer, WebSocketMessageType.Text, true, System.Threading.CancellationToken.None).ContinueWith((task) =>
     {
         completion_queue.Enqueue(callback);
     });
 }
Пример #7
0
 public TcpSendSAE(Socket socket, CompletionQueue completion_queue)
 {
     if (null == socket) throw new ArgumentException();
     this.socket = socket;
     if (null == completion_queue) throw new ArgumentException();
     this.completion_queue = completion_queue;
     eventArgs.Completed += eventArgs_Completed;
     ms = new MemoryStream(send_buffer);
     writer = new BinaryWriter(ms);
 }
Пример #8
0
 public TcpReaderIAR(Socket socket, DelegateBufferWaiting buffer_callback, CompletionQueue completion_queue)
 {
     if (null == socket) throw new ArgumentException();
     this.socket = socket;
     if (null == buffer_callback) throw new ArgumentException();
     this.buffer_callback = buffer_callback;
     if (null == completion_queue) throw new ArgumentException();
     this.completion_queue = completion_queue;
     socket.BeginReceive(recv_buffer, 0, recv_buffer.Length, SocketFlags.None, ReceiveAsyncLoop, socket);
 }
Пример #9
0
 public WebsocketMessageServer(string prefix, string protocol, int accept_depth, 
     SessionManager.DelegateSessionMessage onMessage, CompletionQueue completion_queue)
 {
     this.protocol = protocol;
     this.completion_queue = completion_queue;
     session_manager = new SessionManager(onMessage, completion_queue);
     listener.Prefixes.Add(prefix);
     listener.Start();
     for (int i = 0; i < accept_depth; i++)
         GetContextAsyncLoop();
 }
Пример #10
0
 public TcpReaderSAE(Socket socket, DelegateBufferWaiting buffer_callback, CompletionQueue completion_queue)
 {
     if (null == socket) throw new ArgumentException();
     this.socket = socket;
     if (null == buffer_callback) throw new ArgumentException();
     this.buffer_callback = buffer_callback;
     if (null == completion_queue) throw new ArgumentException();
     this.completion_queue = completion_queue;
     recvAsyncEventArgs.Completed += recvAsyncEventArgs_Completed;
     ReceiveAsync();
 }
Пример #11
0
 void ISendAsync.SendMessage(Message message, CompletionQueue.DelegateCompletionCallback callback)
 {
     //todo, assert overlap depth = 1
     if (null == callback) throw new ArgumentException();
     this.callback = callback;
     byte[] buffer = message.SerializeBytes();
     writer.Seek(0, SeekOrigin.Begin);
     writer.Write((Int32)buffer.Length);
     writer.Write(buffer);
     writer.Flush();
     byte[] send_buffer = ms.ToArray();
     socket.BeginSend(send_buffer, 0, (Int32)writer.BaseStream.Position, SocketFlags.None, SendCallback, socket);
 }
Пример #12
0
 void ISendAsync.SendMessage(Message message, CompletionQueue.DelegateCompletionCallback callback)
 {
     //todo, assert overlap depth = 1
     if (null == callback) throw new ArgumentException();
     this.callback = callback;
     byte[] buffer = message.SerializeBytes();
     writer.Seek(0, SeekOrigin.Begin);
     writer.Write((Int32)buffer.Length);
     writer.Write(buffer);
     writer.Flush();
     eventArgs.SetBuffer(send_buffer, 0, (Int32)writer.BaseStream.Position);
     if (!socket.SendAsync(eventArgs))
         eventArgs_Completed(socket, eventArgs);
 }
Пример #13
0
 public TcpMessageClientIAR(IPEndPoint server, DelegateConnected connected_callback,
     DelegateMessageWaiting message_callback, CompletionQueue completion_queue)
 {
     send_queue = new SendQueue(completion_queue, new TcpSendIAR(client, completion_queue));
     if (null == server) throw new ArgumentException();
     this.server = server;
     if (null == connected_callback) throw new ArgumentException();
     this.OnConnected = connected_callback;
     if (null == message_callback) throw new ArgumentException();
     this.OnMessageWaiting = message_callback;
     if (null == message_callback) throw new ArgumentException();
     this.completion_queue = completion_queue;
     new TcpConnectIAR(client, server, ConnectedThread);
 }
Пример #14
0
 public TcpMessageServer(int accept_depth, short port,
     SessionManager.DelegateSessionMessage onMessage, CompletionQueue completion_queue)
 {
     listener.Bind(new IPEndPoint(IPAddress.Any, port));
     this.completion_queue = completion_queue;
     session_manager = new SessionManager(onMessage, completion_queue);
     listener.Listen(5); //SOMAXCONN
     for (int i = 0; i < accept_depth; i++)
     {
         SocketAsyncEventArgs accept_event = new SocketAsyncEventArgs();
         accept_event.Completed += accept_event_Completed;
         listener.AcceptAsync(accept_event);
     }
 }
Пример #15
0
 public WebSocketSession(WebSocket webSocket, DelegateGotMessage gotMessage, CompletionQueue completion_queue)
 {
     this.completion_queue = completion_queue;
     this.send_queue = new SendQueue(completion_queue, new WebsocketSendAsync(webSocket, completion_queue));
     if (null == webSocket)
         throw new Exception("no websocket context");
     this.webSocket = webSocket;
     if (null == gotMessage)
         throw new Exception("no recv message callback");
     this.gotMessage = gotMessage;
     this._Id = Guid.NewGuid();
     ReceiveAsyncLoop();
     SendSessionId();
 }
Пример #16
0
 public TcpMessageClient(IPEndPoint server, DelegateConnected connected_callback,
     DelegateMessageWaiting message_callback, CompletionQueue completion_queue, DelegateFactoryTcpReader factoryTcpReader)
 {
     send_queue = new SendQueue(completion_queue, new TcpSendIAR(client, completion_queue));
     if (null == server) throw new ArgumentException();
     this.server = server;
     if (null == connected_callback) throw new ArgumentException();
     this.OnConnected = connected_callback;
     if (null == message_callback) throw new ArgumentException();
     this.OnMessageWaiting = message_callback;
     if (null == message_callback) throw new ArgumentException();
     this.completion_queue = completion_queue;
     if (null == factoryTcpReader) throw new ArgumentException();
     this.factoryTcpReader = factoryTcpReader;
     SocketAsyncEventArgs connectAsyncEventArgs = new SocketAsyncEventArgs();
     connectAsyncEventArgs.RemoteEndPoint = server;
     connectAsyncEventArgs.Completed += connectAsyncEventArgs_Completed;
     client.ConnectAsync(connectAsyncEventArgs);
 }
Пример #17
0
        private static CompletionQueue MapCq(int ringFd, size_t cqSize, io_uring_params *p, UnmapHandle sqHandle, out UnmapHandle cqHandle)
        {
            void *ptr;

            if ((p->features & IORING_FEAT_SINGLE_MMAP) != 0)
            {
                ptr      = sqHandle.DangerousGetHandle().ToPointer();
                cqHandle = sqHandle;
            }
            else
            {
                ptr = mmap(NULL, cqSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, ringFd, (long)IORING_OFF_CQ_RING);
                if (ptr == MAP_FAILED)
                {
                    ThrowErrnoException();
                }

                cqHandle = new UnmapHandle(ptr, cqSize);
            }

            return(CompletionQueue.CreateCompletionQueue(ptr, &p->cq_off));
        }
Пример #18
0
        Ring(int entries, object?hack, RingOptions? ringOptions = default)
#endif
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || !KernelVersion.Supports.IoUring)
            {
                ThrowPlatformNotSupportedException();
            }
            if (entries < 1)
            {
                ThrowArgumentOutOfRangeException(ExceptionArgument.entries);
            }

            io_uring_params p  = default;
            int             fd = Setup((uint)entries, &p, ringOptions);

            _ringFd = new CloseHandle();
            _ringFd.SetHandle(fd);

            _flags    = p.flags;
            _features = p.features;

            var(sqSize, cqSize) = GetSize(&p);

            try
            {
                _sq = MapSq(fd, sqSize, &p, SubmissionPollingEnabled, IoPollingEnabled, out _sqHandle, out _sqeHandle);
                _cq = MapCq(fd, cqSize, &p, _sqHandle, IoPollingEnabled, out _cqHandle);
                _supportedOperations = FetchSupportedOperations(fd);
            }
            catch (ErrnoException)
            {
                // Ensure we don't leak file handles on error
                Dispose();
                throw;
            }
        }
Пример #19
0
 public TestTcpTopicClientIAR(IPEndPoint ipEndPoint, CompletionQueue completion_queue)
 {
     this.client = new TcpTopicClientIAR(ipEndPoint, Connected,
         completion_queue);
 }
 public TestWebsocketMessageServer(string prefix, CompletionQueue completion_queue)
 {
     message_server = new WebsocketMessageServer(prefix, "test", Constants.accept_depth, MessageWaiting, completion_queue);
 }
Пример #21
0
 public HybridTopicServer(CompletionQueue completion_queue)
 {
     this.completion_queue = completion_queue;
     topic_server = new TopicServer();
 }
Пример #22
0
 static void Main(string[] args)
 {
     try
     {
         Node.Lib.ArgsParser argsParser = new Node.Lib.ArgsParser(args);
         CompletionQueue completion_queue = new CompletionQueue();
         List<object> keep_alive = new List<object>();
         if (argsParser.ContainsKey("/websocket_messaging"))
         {
             keep_alive.Add(new TestWebsocketMessageServer(
                 Constants.server_prefix, completion_queue));
             for (int i = 0; i < 4; i++)
                 keep_alive.Add(new TestWebsocketMessageClient(
                     new Uri(Constants.client_prefix), completion_queue));
         }
         else if (argsParser.ContainsKey("/websocket_pubsub"))
         {
             keep_alive.Add(new WebsocketTopicServer(
                 Constants.server_prefix, 1, completion_queue));
             for (int i = 0; i < 4; i++)
             {
                 string tag = "client_" + i + "_";
                 keep_alive.Add(new TestWebsocketTopicClient(
                     new Uri(Constants.client_prefix), tag, completion_queue));
             }
         }
         else if (argsParser.ContainsKey("/hybrid_pubsub"))
         {
             keep_alive.Add(new HybridTopicServer(completion_queue));
             keep_alive.Add(new TcpTopicServer(Constants.accept_depth, Constants.tcp_port, completion_queue));
             keep_alive.Add(new WebsocketTopicServer(
                 Constants.server_prefix, 1, completion_queue));
             for (int i = 0; i < 4; i++)
             {
                 string tag = "client_" + i + "_";
                 keep_alive.Add(new TestTcpTopicClientIAR(
                     new IPEndPoint(IPAddress.Loopback, Constants.tcp_port),
                     completion_queue));
             }
             for (int i = 0; i < 4; i++)
             {
                 string tag = "client_" + i + "_";
                 keep_alive.Add(new TestTcpTopicClientIAR(
                     new IPEndPoint(IPAddress.Loopback, Constants.tcp_port),
                     completion_queue));
             }
             for (int i = 0; i < 4; i++)
             {
                 string tag = "ws_" + i + "_";
                 keep_alive.Add(new TestWebsocketTopicClient(
                     new Uri(Constants.client_prefix), tag, completion_queue));
             }
         }
         else if (argsParser.ContainsKey("/browser_client"))
         {
             keep_alive.Add(new TcpTopicServer(Constants.accept_depth, Constants.tcp_port, completion_queue));
             keep_alive.Add(new WebsocketTopicServer(
                 Constants.server_prefix, 1, completion_queue));
             keep_alive.Add(new HttpWebServer(
                 Constants.server_prefix + "pages/", 1, completion_queue, "../../../Node.Web"));
         }
         completion_queue.Run();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Пример #23
0
 public TcpTopicServer(int accept_depth, short port, CompletionQueue completion_queue)
 {
     topic_server = new TopicServer();
     var message_server = new TcpMessageServer(accept_depth, port, OnMessage, completion_queue);
     topic_server.AddMessageServer(message_server);
 }
Пример #24
0
 public TestTcpMessageClientSAE(IPEndPoint ipEndPoint, CompletionQueue completion_queue)
 {
     this.completion_queue = completion_queue;
     message_client = new TcpMessageClientSAE(
         ipEndPoint, Connected, MessageWaiting, completion_queue);
 }