iocp

Simple description of worker and I/O threads in .NET

前提是你 提交于 2019-12-17 04:50:01
问题 It's very hard to find detailed but simple description of worker and I/O threads in .NET What's clear to me regarding this topic (but may not be technically precise): Worker threads are threads that should employ CPU for their work; I/O threads (also called "completion port threads") should employ device drivers for their work and essentially "do nothing", only monitor the completion of non-CPU operations. What is not clear: Although method ThreadPool.GetAvailableThreads returns number of

Simple description of worker and I/O threads in .NET

时间秒杀一切 提交于 2019-12-17 04:49:28
问题 It's very hard to find detailed but simple description of worker and I/O threads in .NET What's clear to me regarding this topic (but may not be technically precise): Worker threads are threads that should employ CPU for their work; I/O threads (also called "completion port threads") should employ device drivers for their work and essentially "do nothing", only monitor the completion of non-CPU operations. What is not clear: Although method ThreadPool.GetAvailableThreads returns number of

“Un-associate” socket from completion port

99封情书 提交于 2019-12-12 09:49:39
问题 CreateIoCompletionPort() is used to associate a socket with a completion port. However, when this socket is closed, then I need to "un-associate" it from the completion port. How can I do that? 回答1: A handle that is associated with an I/O Completion Port is removed from the port when the handle is closed. In case of a network socket, the handle is closed by calling closesocket(). The documentation for CreateIoCompletionPort contains remarks on resource handling: The handle passed in the

Windows limitation on number of simultaneously opened sockets/connections per machine

蹲街弑〆低调 提交于 2019-12-12 07:16:37
问题 Let's say I have Windows 7 with one real network interface and few loopback interfaces. I have IOCP enabled server that accepts connections from clients. I'm trying to simulate as much as possible real client connections to the server. My client code simply establishes X amount of socket connections (note that client binds to a given interface): const Int32 remotePort = 12345; const Int32 MaxSockets = 60000; Socket[] s = new Socket[MaxSockets]; IPEndPoint bindEndpoint = new IPEndPoint

Is WSASend with IOCP ordered?

被刻印的时光 ゝ 提交于 2019-12-11 06:55:13
问题 I would like to create a IOCP application to received TCP data, Once received, I will have to processing the data and write out the bytes partially. Understand that WSASend with IOCP can do the job. But I am worrying whether WSASend to the queue and does GetQueuedCompletionStatus synchronizely?. For Example:- void processing_from_other_thread(...) { ... DWORD state = still_doing1; WSASend( ..,..,.., &state, .. ); DWORD state = still_doing2; WSASend( ..,..,.., &state, .. ); DWORD state = still

GQCS gets notification, when WSAsend returns 0?

半腔热情 提交于 2019-12-11 06:09:42
问题 Although I have read a lot about WSAsend (msdn), I still need some clarifications. Part of my code: int rc; rc=WSASend(Socket,....); if (rc==0) {....} else if ((rc == SOCKET_ERROR) && (WSA_IO_PENDING != (err = WSAGetLastError()))) { printf("WSASend failed with error: %d Socket(%d) \n", err,(pTmp1->Socket)); .... } There is said in msdn that WSAsend operation may sometimes completes immediately returning zero (it never happened during my test server ). So if this happens, the

I/O Completion Port, How to free Per Socket Context and Per I/O Context?

99封情书 提交于 2019-12-10 00:47:57
问题 I'm using IOCP on UDP socket, and the UDP socket may be closed in another thread. So, how can I free Per Socket Context and Per I/O Context which associated with SOCKET safely? When I close the socket, there will still be un-completed I/O request in kernel queue. If I free context just when socket closed, the GetQueueCompletionStatus may failed. Now, my question is when to free context? 回答1: I use reference counting on all of my per socket and per I/O data structures. It makes this kind of

Overlapped I/O: How to wake a thread on a completion port event or a normal event?

為{幸葍}努か 提交于 2019-12-08 05:52:46
问题 I want to use a thread pool to both initiate/cancel overlapped read operations -- using ReadFile() and CancelIo() respectively -- as well as handling any completion port events when read operations complete. Any thread can initiate a read operation Any thread can handle a read-complete event Only the thread that initiated a read may cancel it (this is a CancelIo() limitation) I'm not sure how to implement this. One normally calls GetQueuedCompletionStatus() to wait on completion port events

How do Completion Port Threads of the Thread Pool behave during async I/O in .NET / .NET Core?

自作多情 提交于 2019-12-08 02:01:14
问题 The .NET / .NET Core Thread Pool uses two different categories of threads internally: worker threads and I/O Completion Port (IOCP) threads. Both are just usual managed threads, but used for different purposes. Via different APIs (e.g. Task.Start or ThreadPool.QueueUserWorkItem ) I can start CPU-bound async operations on the worker threads (which shouldn't block, otherwise the Thread Pool would probably create additional worker threads). But what about performing I/O-bound asynchronous

SocketAsyncEventArgs.Completed doesn't fire in Windows 8

可紊 提交于 2019-12-07 09:05:20
问题 When I compile this code on a machine with Windows 7 Ultimate and .NET 4 installed, it works just fine but when I try it on one with Windows 8 RTM and .NET 4.5 installed, Complete event never fires. class Program { private static Socket _Socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); private static void Main(string[] args) { _Socket.Bind(new IPEndPoint(IPAddress.Any, 5012)); _Socket.Listen(100); var arguments = new SocketAsyncEventArgs(); arguments