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

后端 未结 10 936
迷失自我
迷失自我 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 19:57

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

    Well, Indy has been the 'standard' library for socket I/O for a long while now - and it's based on blocking sockets. This means if you want asynchronous behaviour, you use additional thread(s) to connect/read/write data. To my mind this is actually a major advantage, as there's no need to manage any kind of state machine navigation, or worry about callback procs or similar stuff. I find the logic of my 'reading' thread is less cluttered and much more portable than non-blocking sockets would allow.

    Indy 9 has been mostly bombproof, fast and reliable for us. However the move to Indy 10 for Tiburon is causing me a little concern.

    @Mike: "...the need to kill sockets to free threads...".

    This made go "huh?" until I remembered our threading library uses an exception-based technique to kill 'waiting' threads safely. We call QueueUserAPC to queue a function which raises a C++ exception (NOT derived from class Exception) which should only be caught by our thread wrapper procedure. All destructors get called so the threads all terminate cleanly and tidy up on the way out.

提交回复
热议问题