So select system called 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 set data structure.
That is file descriptor set.
So this is a standard data structure that is provided our C 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.
The 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.
So Select system Calls allows the server machine to monitor multiple clients connected connections and
check which client has sent the data to the process.
So Select System Call is used to monitor multiple clients which are already connected with the server
and using select system call.
The server keeps monitoring the multiple clients connections and check that which client has sent data
and which client needs a service.
So you can understand it like this.
Suppose there is a client.
C1 There is a client.
C2 and there is a client.
C3 All these clients are connected to the server.
Right.
So all these clients that is C, one, C, two, C, three are already connected with the servers.
So at any point of time the client C one can send a data to the server as a client.
C two can send data to the server as or a client.
C three can send a data to the server as.
So using select system, call the server s monitors the connections of the client C one, C, two and
C three at the same time.
That is, in whatever order or in whatever sequence any of these client sends a data to the servers.
The server s will be in a position to identify that which client has sent a data and which client needs
a service.
Right.
So select system call helps the server to achieve.
Simultaneous monitor of connected clients.
In addition, suppose there is a client C4 which is not connected to the server s but sends a new connection
initiation request to the server.
S so using select system call the server s not only can monitor the existing connected clients, but
it can also monitor the new connection initiation request that is sent by the new client to the server.
Right.
So Select System Call is actually used to monitor multiple file descriptors.
So you can relate it to this example that just like in a class, the monitor that is the class monitor
keeps an eye on all the students of the class at the same time using select system call.
The server also keeps an eye on all the file descriptors of connected clients as well as it also monitors
the arrival of new connection initiation requests from new clients.
And appropriately, servers can take an action.
Select System call is a blocking system call.
That is the moment the server calls the select system call.
The select system call gets blocked.
Right.
So blocking system call means that when the select system call is executed, the code execution halts.
For example, you may have written your own small programs in which you have in which you must have
used the functions like scanf or get H.
Right.
And you must have experienced that the call to these functions actually halt the execution of a program.
Similarly, the select system call also blocks the execution of a program.
So such calls are called as blocking system call and select System call is one such blocking system
call, select system call and blocks.
When either of the two things happen on the server side, that is, either a server receives the new
connection request from new client.
That is when the new client server sends the new connection initiation request to the server s the server
s and blocks from the select system call.
So this is the scenario one and the server s and blocks from the select system call when data requests
from existing connected client arrives.
So this is the scenario with client C one, C two and C three.
Right?
So the server and blocks from the select system call when either the event one happens or either the
event two happens.
So when select system call and blocks server needs to check whether it's a new connection request or
new data request on existing connection.
Right?
So in the latter case, server needs to find which client has sent the data.
Right?
Because the server can unblock from the select system call when either the client c two has send the
data or when the client C three has sent the data.
So when the server is unblocked from the select system call, it has to identify that it is unblocked
from the select system call because of which client.
So when server starts, the first thing it does is to create a master socket.
A socket to detect arrival of new connection requests from new client.
So this master socket, once it is created by the server, it is used to give birth to the rest of the
communication file descriptor for the clients.
So C provides a predefined data structure called feed underscore set, which is a collection of file
descriptors.
So you can define the variable read feeds, set of data type feed, underscore set.
So feed underscore set is actually a data type that is provided by standard C APIs and it is used as
a collection of file descriptors.
So remember, file descriptors are simple integers.
So f underscore set is nothing, but it is a collection of file descriptors which the server is maintaining.
So we will discuss more about this underscore set, when we will be actually discussing the implementation
of TCP server.