@@ -386,32 +386,6 @@ determining whether the other end is done, or just busy with something else.
386386files. Don't try this on Windows. On Windows, ``select `` works with sockets
387387only. Also note that in C, many of the more advanced socket options are done
388388differently on Windows. In fact, on Windows I usually use threads (which work
389- very, very well) with my sockets. Face it, if you want any kind of performance,
390- your code will look very different on Windows than on Unix.
389+ very, very well) with my sockets.
391390
392391
393- Performance
394- -----------
395-
396- There's no question that the fastest sockets code uses non-blocking sockets and
397- select to multiplex them. You can put together something that will saturate a
398- LAN connection without putting any strain on the CPU. The trouble is that an app
399- written this way can't do much of anything else - it needs to be ready to
400- shuffle bytes around at all times.
401-
402- Assuming that your app is actually supposed to do something more than that,
403- threading is the optimal solution, (and using non-blocking sockets will be
404- faster than using blocking sockets). Unfortunately, threading support in Unixes
405- varies both in API and quality. So the normal Unix solution is to fork a
406- subprocess to deal with each connection. The overhead for this is significant
407- (and don't do this on Windows - the overhead of process creation is enormous
408- there). It also means that unless each subprocess is completely independent,
409- you'll need to use another form of IPC, say a pipe, or shared memory and
410- semaphores, to communicate between the parent and child processes.
411-
412- Finally, remember that even though blocking sockets are somewhat slower than
413- non-blocking, in many cases they are the "right" solution. After all, if your
414- app is driven by the data it receives over a socket, there's not much sense in
415- complicating the logic just so your app can wait on ``select `` instead of
416- ``recv ``.
417-
0 commit comments