I know there are three ways in I/O multiplexing: select, poll and epoll in Linux.I can't figure out if the C# function Socket.Select() just use select or it will use epoll When OS support.
If it don't use epoll which function does?Such as selector.select in java,it will use epoll when OS support
Thanks.
CodePudding user response:
It uses poll()
.
You'll need to P/Invoke the epoll()
calls on Linux yourself.
CodePudding user response:
.net core uses epoll for async Socket.xxxAsync
operations.
https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-core-3-0/
For Socket.Select() call chain is Socket.Select() -> SocketPal.Unix.cs -> SelectViaPoll -> Interop.Sys.Poll -> Interop.Poll -> [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Poll")] internal static extern unsafe Error Poll(PollEvent* pollEvents, uint eventCount, int timeout, uint* triggered); -> Common_Poll -> inline static int32_t Common_Poll(PollEvent* pollEvents, uint32_t eventCount, int32_t milliseconds, uint32_t* triggered) -> poll()
For async ops:
Socket.RecieveFromAsync() -> SocketAsyncContext.Unix ReceiveFromAsync() -> _receiveQueue.StartAsyncOperation() -> SocketAsyncEngine.TryRegister();
Then we go to SocketAsyncEngine.EventLoop() -> Interop.SocketEvent.cs _> SystemNative_WaitForSocketEvents -> WaitForSocketEventsInner -> epoll()
See PAL code on Github. If the system has epoll it will be compiled in.