iocp

CreateFile() returns INVALID_HANDLE_VALUE but GetLastError() is ERROR_SUCCESS

血红的双手。 提交于 2019-12-23 08:30:02
问题 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

storage and management of overlapped structure in multithreaded IOCP server

柔情痞子 提交于 2019-12-23 00:52:12
问题 Is it good idea to use LINKED LIST to store overlapped structure? my overlapped structure looks like this typedef struct _PER_IO_CONTEXT { WSAOVERLAPPED Overlapped; WSABUF wsabuf; .... some other per operation data .... struct _PER_IO_CONTEXT *pOverlappedForward; struct _PER_IO_CONTEXT *pOverlappedBack; } PER_IO_CONTEXT, *PPER_IO_CONTEXT; When iocp server starts i allocate (for example) 5000 of them in Linked List. The start of this list is stored in global variable PPER_IO_CONTEXT OvlList. I

Delphi TClientSocket replacement using winsock2 and IOCP?

梦想与她 提交于 2019-12-22 18:46:45
问题 Is there such a thing? It needs to be asynchronous (no Indy). 回答1: Try HPScktSrvr - http://www.torry.net/pages.php?id=220#939383 回答2: These may or may not be what you are looking for, but worth a shot: Ararat Synapse - For Delphi 2009 support you need to get the latest from SVN. /n Software's IP*Works - Commercial, but very full featured. Good luck! 回答3: Check http://voipobjects.com/index.php?page=delphi-iocp-library It is migrated iocpclasses.sourceforge.net (i'm an author). Enjoy :) 来源:

Timer that supports overlapped I/O (for IOCP)?

我的梦境 提交于 2019-12-21 16:17:29
问题 I need to add timers support in an application based on I/O Completion Ports (IOCP). I would like to avoid the use of a specific thread to manage timers. On Linux, you can create a timer that delivers expiration notifications via a file descriptor (see timerfd.h man), so it's great to use it for example with epoll if your application is based on epoll. On Windows, you can use "waitable timers" with an asynchronous procedure call (ACP) (see http://msdn.microsoft.com/en-us/library/ms686898(v=VS

【转】从“async”到async—Node异步流程控制总结

不羁岁月 提交于 2019-12-20 14:44:13
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Node的异步概念 理解异步非阻塞 提到Node, 异步非阻塞 会是第一个需要你理解的概念。很多人会把这实际上是两个概念的词混为一谈,认为异步就是非阻塞的,而同步就是阻塞的。从实际的效果出发,异步IO和非阻塞IO实际上都能达到我们对于IO繁重的网络应用并行IO的追求。但是实际上这是两个很不一样的概念。 从操作系统的内核角度出发 ,I/O调用 只有两种方式,阻塞和非阻塞 。二者的区别在于,对于使用阻塞IO调用,应用程序需要等待IO的整个过程都全部完成,即完成整个IO目的,此期间CPU进行等待,无法得到充分的利用。而对于使用非阻塞IO调用来说,应用程序发起IO请求之后不等待数据就立即返回,接下来的CPU时间片可用于其他任务,由于整个IO的过程并没有完成,所以还需要使用 轮询技术 去试探数据是否完整准备好。关于轮询技术细节和发展,此处不过多赘述,很推荐朴灵老师《深入浅出NodeJs》的第三章。 不难理解, 从应用程序的角度出发 ,我不管你操作系统内核是阻塞的IO调用还是非阻塞的IO调用,只要是我要的数据并没有给我,那么这就是同步的,因为我依旧是在等数据。所以对于这种情况下,应用程序的那“一根筋”就可以选择用同步还是异步的方式去面对该情况。同步即等待操作系统给到数据再进行下面的代码(单线程)

GetQueuedCompletionStatus can't dequeue IO from IOCP if the thread which originally issued the IO is blocking in ReadFile under windows 8

我们两清 提交于 2019-12-20 12:19:06
问题 My app stop working after switching to windows 8. I spend hours to debug the problem, found out IOCP behave differently between windows 8 and previous versions. I extract the necessary code to demonstrate and reproduce the problem. SOCKET sListen; DWORD WINAPI WorkerProc(LPVOID lpParam) { ULONG_PTR dwKey; DWORD dwTrans; LPOVERLAPPED lpol; while(true) { GetQueuedCompletionStatus((HANDLE)lpParam, &dwTrans, &dwKey, (LPOVERLAPPED*)&lpol, WSA_INFINITE); printf("dequeued an IO\n"); } } DWORD WINAPI

WSAsend to all connected socket in multithreaded iocp server

扶醉桌前 提交于 2019-12-19 11:34:48
问题 I work on IOCP Server (Overlapped I/O , 4 threads, CreateIoCompletionPort , GetQueuedCompletionStatus , WSASend etc). I also created an auto-reset event and put the handle in the OVERLAPPED structure for each asynchronous I/O operations. And the question is: How to send buffer too all connected sockets properly? Each socket is stored in linked list of context info structures. I'm not sure is that approach below is ok? ... DWORD WINAPI WorkerThread() { // 1 of 4 workthread ...

IOCP模型与EPOLL模型的比较

眉间皱痕 提交于 2019-12-19 10:22:11
一:IOCP和Epoll之间的异同。 异: 1:IOCP是WINDOWS系统下使用。Epoll是Linux系统下使用。 2:IOCP是IO操作完毕之后,通过Get函数获得一个完成的事件通知。 Epoll是当你希望进行一个IO操作时,向Epoll查询是否可读或者可写,若处于可读或可写状态后,Epoll会通过epoll_wait进行通知。 3:IOCP封装了异步的消息事件的通知机制,同时封装了部分IO操作。但Epoll仅仅封装了一个异步事件的通知机制,并不负责IO读写操作。Epoll保持了事件通知和IO操作间的独立性,更加简单灵活。 4: 基于上面的描述,我们可以知道Epoll不负责IO操作,所以它只告诉你当前可读可写了,并且将协议读写缓冲填充,由用户去读写控制,此时我们可以做出额 外的许多操作。IOCP则直接将IO通道里的读写操作都做完了才通知用户,当IO通道里发生了堵塞等状况我们是无法控制的。 同: 1:它们都是异步的事件驱动的网络模型。 2:它们都可以向底层进行指针数据传递,当返回事件时,除可通知事件类型外,还可以通知事件相关数据。 二:描述一下IOCP: 扯远点。首先传统服务器的网络IO流程如下: 接到一个客户端连接->创建一个线程负责这个连接的IO操作->持续对新线程进行数据处理->全部数据处理完毕->终止线程。 但是这样的设计代价是: 1:每个连接创建一个线程

where/how can I find whether a .net class uses IOCP?

℡╲_俬逩灬. 提交于 2019-12-18 11:47:44
问题 Update I asked the wrong question, rephrased (based on the great info on answers and comments): Is there any good source on .net's async operations being real async, thus either IOCP or async(overlapped)? Is there any quick way to find out if several classes are doing so? Example of not trusting framework developers blindly The natural starting point for creating a FileStream is the static File.Open() method, the documentation for which mentions nothing about synchronicity of the FileStream

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

拈花ヽ惹草 提交于 2019-12-17 04:50: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