So guys, in this lecture we will going to study the concept of multiplexing.
So what exactly multiplexing is?
Multiplexing is a mechanism through which the server process can monitor multiple clients at the same
time.
So without multiplexing, server process can entertain only one client at a time and cannot entertain
other clients request until it finishes with the current client.
So we have already seen this problem in our previous demonstration of server client communication that
when the server was entertaining or processing the request of one client, it do not respond to the
connection initiation request sent by another client.
Right.
So basically our server was responsible to entertain only one client at a time.
And this is a huge drawback for being a server process.
Server process should have a capability to handle multiple clients at the same time.
And therefore we have a concept called multiplexing using which server can entertain multiple connected
client simultaneously.
So the following pictures demonstrate the concept of multiplexing and what happens when you don't have
a multiplexing on the left hand side, You can see a long queue and you can see that while the person
which is at the front of the queue receives the service, all other persons standing behind him have
to wait for their turns.
And once the person who is at the front of the queue receives the service, then if he wishes to receive
the same service again, he has to join the queue right from the back.
So this situation is equivalent to the situation where once the current client is serviced by the server,
client has to join the queue right from the last that is, he will rejoin the queue.
But from the last it means that the client has to send the fresh connection initiation request to the
server to get another service from the server.
Whereas the picture on the right hand side depicts a person which has multiplexing capabilities.
He can do multiple tasks at the same time, so server can service multiple clients at the same time
using the concept of multiplexing.
So Linux provide a special system call which enable the developer to implement multiplex based communication.
And that system call is a select system call.
So select system call help us to monitor all clients activity at the same time.
So these are those clients which are connected to our server and using select system call.
Our server can monitor all those clients at the same time.
That is, which client has sent the data and which client has not sent the data and which client has
sent the new connection initiation request.
So using this system call our server can actually monitor the state of all connected clients at the
same time.
So let us discuss select system call now.
Server process has to maintain client handles.
So remember, client handles are also called communication file descriptors.
So server maintain multiple communication file descriptors to carry out communication with connected
clients.
So you can see in the diagram on the right hand side, at this point of time, our server is maintaining
three file descriptors.
One is the master socket file descriptor, and at this point of time two clients are connected to our
server and corresponding to those two connected clients.
Our server is maintaining two communication file descriptors, which is C one and C two.
So in addition, several process has to maintain connection socket or master socket file descriptor
as well, which is M.
So this is master socket file descriptor and the purpose of master socket file descriptor is to process
new connection initiation requests from new clients.
So Linux provides an inbuilt data structure to maintain the set of socket file descriptors.
So you can see at this point of time in this diagram, our server is actually maintaining three file
descriptors, that is master socket file descriptors and two communication file descriptors.
Now of course you need some data structure in order to maintain these file descriptors.
So Linux provides an inbuilt data structure which makes the maintenance of socket file descriptors easy.
That data structure is called Ft set data structure that is file descriptor set.
So this is a standard data structure that is provided our API.
So you can see that FD underscore set is actually a set of file descriptors which are maintained by
the server at any point of time.
So select system call monitor all socket file descriptors which are present in the set data structure.
So you can see we have a select system call and this select system call operate on FD set data structure.
In other words, our select system call operate on a set of file descriptors which are maintained by
a server.
So the argument to the select system call is definitely.
PhD set data structure, which contains some set of file descriptors.
So this is a high level overview.
Regarding how select system call works and what is the relationship between select system call and set
data structure?
Now, next, let us have a detailed discussion on select system call.
That is how exactly select system call works.
And once you understand the mechanism of select system call it is it will be very easy for you to implement
a server which has multiplexing capabilities.