iocp

IO Completion Ports and socket WSARecv()

岁酱吖の 提交于 2020-01-02 22:00:15
问题 I am trying to understand how IOCP works with sockets. I need to understand if this is how they work: I create a completion port, which is nothing but a queue that will receive notifications when some operation completes, and then I associate my socket with it, and then I process incoming notifications. Now I want to know how this relates to receiving of data from a socket, so when I call WSARecv() what exactly happens, does WSARecv() returns immediately when I call it (does not block) and

When I call WSASend(), will all the data be sent?

孤者浪人 提交于 2020-01-01 17:15:26
问题 When using IOCP, if I call WSASend() with let's say 2 KB of data. When I receive a completion notification, will this completion notification indicate that the entire 2 KB were sent, or there could be some bytes that were not sent? 回答1: Under normal circumstances, yes, your completion will receive notification that the entire 2 KB was sent, as long as the socket is using overlapped I/O. The only scenario where it may return less than the size of the data sent is when the connection is

Visual C++ program crashed, but no dumpfile generated. why?

烈酒焚心 提交于 2019-12-29 08:00:23
问题 I have a very strange situation. I'm running IOCP Server Program programmed by Visual studio 2010 in C++. It uses 'minidump', so When there is a logical bug like pointer misuse, Program crashes with dump file so I can find out where is the crash point in codes. Sometimes (very rarely), the program crashes and there are no dump files. What situation makes SetUnhandledExceptionFilter() not working? Anybody knows this problem? I can't figure out. 回答1: Well, of course you don't know because you

聊聊IOCP,聊聊异步编程

∥☆過路亽.° 提交于 2019-12-28 03:53:23
/*--> */ /*--> */ /*--> */ /*--> */ 前言 IO完成端口(IO completion ports)在多核计算机的并行异步IO请求方面提供了一种高效的线程模型。当进程创建一个IO完成端口时,系统创建一个相关联的队列,其唯一目的是服务与那些请求。IO完成端口通常和预先分配的线程池配合,相比于一个一个创建线程,这使其更快更高效。IOCP在进程之间并不共享,一个IOCP及其句柄只和创建它的进程关联,但是一个进程中的多个线程可共享。IOCP最关键的地方就是,IOCP在IO请求和接收动作完成之后,激活线程池中的任意线程继续操作,而不是在IO请求和接受完成之后,激活原等待中的线程。这样的好处是防止等待线程闲置,和必须激活/切换到原等待线程的开销。 大多应用存在的问题 曾见过很多服务,几台,几十台,几百台服务器的,它们cpu大多数时间处于空闲状态,也许需要大量计算的应用并没有那么多,我们常见的应用大多主要读写关系数据库,读写内存数据库/缓存,RPC调用接口。IO耗时过多,CPU大量闲置,导致没看到服务器资源大量消耗,便已不能承受日益增加的访问量,再加服务器,依然大量浪费了资源。 CPU资源昂贵,每一个核心,同一时刻只能有一个线程在运行,超线程cpu同一时刻可以有两个逻辑线程运行,所以说线程不是创建的越多越好,过多的线程只会增加线程切换带来的成本。试想一下

Is Node.js production-ready on Windows? [closed]

半城伤御伤魂 提交于 2019-12-25 04:07:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . In the new 0.5.1 branch, there is an official Windows executable of Node.js. The Linux version of Node.js uses established libraries

How to simulate a blocking send() using WSASend() and IOCP?

浪子不回头ぞ 提交于 2019-12-25 04:05:03
问题 Edit: This question is not necessary, as the WSASend() function can inherently be used in a blocking mode, even if the socket has the overlapped attribute and is associated with a completion port. To use it in a blocking mode: just don't supply an overlapped structure or a completion routine when calling WSASend() . I want to make sure that when I send data, the function will only return when this data has been placed in the send buffer. So this is what I come up with (pseudo code): void

IO Completion ports: separate thread pool to process the dequeued packets?

爷,独闯天下 提交于 2019-12-24 18:41:41
问题 NOTE : I have added the C++ tag to this because a) the code is C++ and b) people using C++ may well have used IO completion ports. So please don't shout. I am playing with IO completion ports, and have eventually fully understood (and tested, to prove) - both with help from RbMm - the meaning of the NumberOfConcurrentThreads parameter within CreateIoCompletionPort() . I have the following small program which creates 10 threads all waiting on the completion port. I tell my completion port to

SetFileCompletionNotificationModes seems to not work properly

这一生的挚爱 提交于 2019-12-24 12:16:45
问题 I'm using SetFileCompletionNotificationModes() API to optimize my I/O completion ports loops, but it seems to not work properly. Even if I set FILE_SKIP_COMPLETION_PORT_ON_SUCCESS for sockets and HANDLEs, an I/O port's completion callback is still called also if ReadFile() WriteFile() WSARecv() WSASend() do return synchronosly . I'm sure that the 3 conditions that MSDN says must be true (A completion port is associated with the file handle, The file is opened for asynchronous I/O, A request

Reusable test code that waits for IO

旧城冷巷雨未停 提交于 2019-12-23 16:34:11
问题 I'm experimenting with using async/await on WCF exposed methods/services. Everything works fine but I'd like to simulate the service method actually waiting for IO so that the service call will be registered with an IO completion port, and the thread put back into the thread pool. To clarify, I'm just experimenting to confirm usage of IO completion ports and to get a better understanding of the mechanics of what's actually going on. So e.g. my test service currently looks like this:

CreateFile() returns INVALID_HANDLE_VALUE but GetLastError() is ERROR_SUCCESS

跟風遠走 提交于 2019-12-23 08:30:10
问题 I am opening a serial port using CreateFile(). I've got a testcase (too complicated to redistribute) that consistently causes CreateFile() to return INVALID_HANDLE_VALUE and GetLastError() to return ERROR_SUCCESS . By the looks of it, this bug only occurs if one thread opens the port at the exact same time that another port closes it. The thread opening the port runs across this problem. I don't know if this makes a difference, but later on in the code I associate the port with a