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; }
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(); }
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; }
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; }
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); }
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); }); }
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); }
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); }
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(); }
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(); }
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); }
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); }
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); }
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); } }
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(); }
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); }
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)); }
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; } }
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); }
public HybridTopicServer(CompletionQueue completion_queue) { this.completion_queue = completion_queue; topic_server = new TopicServer(); }
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); } }
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); }
public TestTcpMessageClientSAE(IPEndPoint ipEndPoint, CompletionQueue completion_queue) { this.completion_queue = completion_queue; message_client = new TcpMessageClientSAE( ipEndPoint, Connected, MessageWaiting, completion_queue); }