What's the idiomatic way to do async socket programming in Delphi?

后端 未结 10 987
迷失自我
迷失自我 2021-01-04 19:18

What is the normal way people writing network code in Delphi use Windows-style overlapped asynchronous socket I/O?

Here\'s my prior research into this question:

10条回答
  •  佛祖请我去吃肉
    2021-01-04 19:57

    @Chris Miller - What you've stated in your answer is factually inaccurate.

    Windows message-style async, as available through WSAAsyncSelect, is indeed largely a workaround for lack of a proper threading model in Win 3.x days.

    .NET Begin/End, however, is not using extra threads. Instead, it is using overlapped I/O, using the extra argument on WSASend / WSARecv, specifically the overlapped completion routine, to specify the continuation.

    This means that the .NET style harnesses the Windows OS's async I/O support to avoid burning a thread by blocking on a socket.

    Since threads are generally speaking expensive (unless you specify a very small stack size to CreateThread), having threads blocking on sockets will stop you from scaling to 10,000s of concurrent connections.

    This is why it's important that async I/O be used if you want to scale, and also why .NET is not, I repeat, is not, simply "using threads, [...] just managed by the Framework".

提交回复
热议问题