How a thread service two data sockets (not control sockets) equally?

Suppose that we have a single-thread application, and it needs to service two clients by writing 1G bytes data to two separate tcp sockets (one socket per client) respectively, in this situcation how can the thread work on the two tasks equally and continually?

I think this problem exists in server applications like Apache, take the Apache Web Server as an example, the Apache sets a max thread limit for itself, say it is MAX_THREADS, and if there are (MAX_THREADS + 1) outstanding requests and sockets there which means at least one thread must handle two sockets equally. Then how would apache handle this situation?



Usually when we want to handle several sockets in a single threaded application then one of the following system calls are generally used

select (

poll (

epoll (

More on these calls can be found in the man pages.

the general idea is to make the single thread not get blocked waiting to get a resource and periodically check if data is available to send or receive

Need Your Help

Exiting Python Debugger ipdb

python debugging workflow exit ipdb

I use ipdb fairly often in a way to just jump to a piece of code that is isolated i.e. it is hard to write a real script that uses it. Instead I write a minimal test case with mocking and jump into...

Calculating array values

php arrays

I have a measurand like 55.9 mm and I want to divide it in different gauge blocks. Just like:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.