Information Technology Reference
In-Depth Information
Client:
charrequest[RequestSize];
charreply[ReplySize]
//..compute..
//puttherequestintothebuffer
//sendthebuffertotheserver
write(output,request,RequestSize);
//waitforresponse
read(input,reply,ReplySize);
//..compute..
Server:
charrequest[RequestSize];
charreply[ReplySize];
//loopwaitingforrequests
while(1){
//readincomingcommand
read(input,request,RequestSize);
//dooperation
//sendresult
write(output,reply,ReplySize);
}
Figure3.11: Example code for client-server interaction.
3.4.2
Client-server communication
We can generalize the above to illustrate client-server communication, shown in
Figure 3.10. Instead of a single pipe, we create two, one for each direction. To
make a request, the client writes the data into one pipe, and reads the response
from the other. The server does the opposite: it reads requests from the first
pipe, performs whatever is requested (provided the client has permission to
make the request), and writes the response onto the second pipe.
The client and server code are shown in Figure 3.11. To simplify the code,
we assume that the requests and responses are fixed size.
Frequently, we want to allow many clients to talk to the same server. For
example, there is one server to manage the print queue, although there can be
many processes that want to be able to print. For this, the server uses the
select system call, to identify the pipe containing the request to be read, as
shown in Figure 3.12. The client code is unchanged.
3.5
Operating system structure
We started this chapter with a list of functionality that users and applications
need from the operating system. We have shown that by careful design of the
 
Search WWH ::




Custom Search