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)

poll (http://linux.die.net/man/2/poll)

epoll (http://en.wikipedia.org/wiki/epoll)

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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -