iocp

What's the best way to ping many network devices in parallel?

假如想象 提交于 2019-12-03 08:16:28
I poll a lot of devices in network (more than 300) by iterative ping. The program polls the devices sequentially, so it's slow. I'd like to enhance the speed of polling. There some ways to do this in Delphi 7: Each device has a thread doing ping. Manage threads manually. Learn and use Indy 10. Need examples. Use overlapped I/O based on window messages. Use completion ports based on events. What is faster, easier? Please, provide some examples or links for example. Flooding the network with ICMP is not a good idea. You might want to consider some kind of thread pool and queue up the ping

select,iocp,epoll,kqueue及各种I/O复用机制

大憨熊 提交于 2019-12-03 06:07:29
首先,介绍几种常见的I/O模型及其区别 ,如下: blocking I/O nonblocking I/O I/O multiplexing (select and poll) signal driven I/O (SIGIO) asynchronous I/O (the POSIX aio_functions) blocking I/O 这个不用多解释吧,阻塞套接字。下图是它调用过程的图示: 重点解释下上图,下面例子都会讲到。首先application调用 recvfrom()转入kernel,注意kernel有2个过程,wait for data和copy data from kernel to user。直到最后copy complete后,recvfrom()才返回。此过程一直是阻塞的。 nonblocking I/O: 与blocking I/O对立的,非阻塞套接字,调用过程图如下: 可以看见,如果直接操作它,那就是个轮询。。直到内核缓冲区有数据。 I/O multiplexing (select and poll) 最常见的I/O复用模型,select。 select先阻塞,有活动套接字才返回。与 blocking I/O 相比,select会有两次系统调用,但是select能处理多个套接字。 signal driven I/O (SIGIO) 只有UNIX系统支持

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

一笑奈何 提交于 2019-12-03 02:32:41
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 StartProc(LPVOID lpParam) { WSADATA WsaData; if (WSAStartup(0x202,&WsaData)!=0) return 1; sListen =

windows下的IOCP

匿名 (未验证) 提交于 2019-12-03 00:34:01
对应Linux下的epoll,windows下也有实现IO复用的方法,那就是IOCP,又叫重叠IO,其实和异步IO没什么区别,《TCPIP网络编程》这本书也没有对重叠IP和异步IO做明确的区分。 首先,创建重叠IO的套接字。 SOKET WSAocket( int af, int type , int protocol , LPWSAPROTOCOL_INFO lpProtocolInfo , GROUP g , DWORD dwFlags ); 成功时返回套接字句柄,失败时返回INVALID_SOKET。 af 协议族信息 前三个参数和普通套接字一致,后三个分别为 lpProtocolInfo 包含创建的套接字信息的WSAPROTOCOL_INFO结构体变量地址值,不需要时传递NULL。 g 为扩展函数而预约的参数,可以使用0。 dwFlags 套接字属性信息。 执行重叠IO的WSASend函数 int WSASend(SOKET s,LPWSABUF lpBuffers,DWORD dwBufferCount,LPDWORD lpNumberOfBytesSent,DWORD dwFlags,LPWSAOVERLAPPED lpOverlapped,LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); 1

[转帖]Epoll和IOCP的比较

主宰稳场 提交于 2019-12-02 10:20:56
Epoll和IOCP的比较 https://yq.aliyun.com/articles/53621/ kryptosx 2016-05-27 23:32:51 浏览6181 原来整理过一个《 六种Socket I/O模型幽默讲解 》,里面是windows的六种socket I/O模型,大学时的windows网络编程就是讲的这几个。今天听了一个网络技术讲座,突然想起了这两个模型还是没搞清楚。 但是,貌似服务器中用的最多的还是linux,相对于windwos最尖端的IOCP而言,linux祭出的则是它的Epoll。 Epoll 和 IOCP 都是为高性能网络服务器而设计的高效 I/O 模型;都是基于事件驱动的。事件驱动有个著名的好莱坞原则(“不要打电话给我们,我们会打电话给你”)。 不同之处: Epoll 用于 Linux 系统;而 IOCP 则是用于 Windows; Epoll 是当事件资源满足时发出可处理通知消息;而 IOCP 则是当事件完成时发出完成通知消息。 从应用程序的角度来看, Epoll 本质上来讲是 同步非阻塞的,而 IOCP 本质上来讲则是异步操作;这是才二者最大的不同。 这么说来,其实Epoll有点像上面说的第四种Socket I/O模型。不过,Epoll只告诉你几个句柄收到消息和收到消息的句柄队列,然后你自己去扫描。 一个例子 有个文档需要拿到打印室打印

[转帖]EPOLL和IOCP比较

那年仲夏 提交于 2019-12-02 10:20:29
EPOLL和IOCP比较 https://blog.csdn.net/educast/article/details/15503179IOCP 异步非阻塞EPOLL 异步阻塞 EPOLL是半成品,IOCP是成品,底层机制一样,协议栈的状态检查不需要用户去查询,由作业系统来通知。 其实这是任何守护性逻辑高性能的基础机制。 但是EPOLL只是告诉你现在可以读和写,即协议栈的读写缓冲被初始化或重设(对于写,上次数据已经提交并写缓冲重设为空,对于读,栈议栈读缓冲已经开始接受数据。) 但是写和读的过程还是由用户来控制,系统只是告诉你已经为你准备好了和网络驱动对接好的读写的通道。如果某个通道的读写很慢,我们其实自己可以控制,比如要读8K字节,但经过x秒只读到几个字节,这说明这个通道很差,我们可以将这个IO通道从EPOLL中分离出来把它投递到一个阻塞的socket中,而不影响整个EPOLL的性能。所以EPOLL虽然是半成品,但用户有更高的控制权。 而对于IOCP,从名称就可以知道,系统不仅控制IO通道的状态,而且把读写操作都做完了才通知用户。对于读,系统已经把数据读好放在buffer中,其实相当于是RBF,对于写,已经是写出了n长度的字节,所以即使某个IO通道上的传输很慢,你也无法控制,因为当你收到通知时,系统已经是读好数据或写出数据。所以IOCP在用户的控制上没有灵活的空间。

Using SslStream with IOCP

走远了吗. 提交于 2019-12-02 09:36:19
问题 I have written a TCP server using the Socket class's asynchronous/IOCP methods, BeginSend()/BeginRead()/etc. I would like to add SSL capability using SslStream, but from the interface it looks like Socket and SslStream are not intended to work together, in particular because I'm not using Streams at all and SslStream appears to depend on having a Stream to work with. Is this possible, or am I looking in the wrong place? Do I need to fashion my own Stream subclass that feeds into my Socket

Using SslStream with IOCP

跟風遠走 提交于 2019-12-02 06:59:33
I have written a TCP server using the Socket class's asynchronous/IOCP methods, BeginSend()/BeginRead()/etc. I would like to add SSL capability using SslStream, but from the interface it looks like Socket and SslStream are not intended to work together, in particular because I'm not using Streams at all and SslStream appears to depend on having a Stream to work with. Is this possible, or am I looking in the wrong place? Do I need to fashion my own Stream subclass that feeds into my Socket instances and point SslStream at that? It's important to me that my server use IOCP due to scaling

I/O Completion Ports *LAST* called callback, or: where it's safe to cleanup things

让人想犯罪 __ 提交于 2019-12-01 04:11:23
问题 I guess this argument is important and deserve some space here. Let's consider the most common design of I/O Completion Ports in C/C++, having a structure (or a class) which abstract the HANDLE, and some of its properties, like this: class Stream { enum { Open = 1, Closed = 0 }; // Dtor virtual ~Stream() { if (m_read_packet != 0) delete_packet(m_read_packet); // the same for write packet } // Functions: bool read(...) { if (m_read_packet != 0) m_read_packet = allocate_packet(); ReadFile(m

Windows 2012 R2 closesocket() hangs on listening socket

扶醉桌前 提交于 2019-11-30 20:17:13
I have a weird situation on a production server. We have network application written on C++ which serves users requests by TCP written using IOCP. Two days ago we did an update of Windows 2012 R2 (it installed latest security updates. The previous update was 6 month ago). And after the update when trying to stop the service we see in logs that server hangs on call to close listening socket closesocket(session->listen_socket); The schema of stopping the network system is the next: PostQueuedCompletionStatus(m_completion_port, 0, NULL, NULL); x the number of worker threads Wait all worker