linux - How a thread service two data sockets (not control sockets) equally? -
suppose have single-thread application, , needs service 2 clients writing 1g bytes data 2 separate tcp sockets (one socket per client) respectively, in situcation how can thread work on 2 tasks equally , continually?
i think problem exists in server applications apache, take apache web server example, apache sets max thread limit itself, max_threads, , if there (max_threads + 1) outstanding requests , sockets there means @ least 1 thread must handle 2 sockets equally. how apache handle situation?
steve
usually when want handle several sockets in single threaded application 1 of following system calls used
select (http://en.wikipedia.org/wiki/select_%28unix%29)
more on these calls can found in man pages.
the general idea make single thread not blocked waiting resource , periodically check if data available send or receive
Comments
Post a Comment