In this assignment you will extend the programs you wrote in Assignment 1 to work with named pipes. In Part 8 you will write a client that will request a program (a file) from a server (written in Part 9). The server will send the client a program list. The client will choose a program from the list and the server will send that program. For Parts 8 and 9 you may want to use some of the routines you wrote for Assignment 1.
Part 0:
If you haven't already done so, finish Part 10 of Assignment 1.
Part 1:
Make a directory called assign3 under your cs3733 directory.
Get a copy of the files restart.c and restart.h.
These can be gotten from the
USP programs web page for Appendix B.
You may want to use some of the programs in the restart library to
simplify your code. To use these functions,
your programs should include restart.h.
You should not modify either restart.h or restart.c.
Create a makefile that uses separate compilation to compile your programs and link them to the restart library.
Part 2:
Write a function called read_int_as_line that takes one integer
parameter, an open file descriptor and returns an integer. It reads one line
from the file descriptor and tries to convert it to a non-negative integer.
If successful it returns the integer value.
Otherwise it returns -1 and sets errno.
You may assume that it is an error if the line being read is longer than
60 bytes. Use the readline function from the restart library.
To convert to an integer, skip over leading blanks. It is an error
if the remaining characters up to the newline are not decimal digits.
Do not worry about overflow.
Part 3:
Write a main program to completely test the function from Part 2.
Part 4:
Write a function called send_int_as_line that takes two parameters, an
open file descriptor and an integer. It converts the second parameter to a
line (an array ending with a newline) and sends it to the open file
descriptor.
It returns 0 on success and -1 (with errno set) on failure.
Note that this is sending a line not a string. No null characters should
be sent.
Part 5:
Write a main programs to completely test the function from Part 4 with the
function in Part 2. Use a pipe to send and integer from one program
to another.
Part 6:
Write a function send_num_bytes that takes three parameters, two
open file descriptors and one integer. The function reads exactly the number
of bytes given by the last parameter from the file descriptor given by the
first parameter and writes them to the file descriptor given by the second
parameter.
It returns 0 on success and -1 (with errno set) on failure.
This function should not assume that everything to be sent will fit in memory
and it should do reads in small blocks of size at most 1024.
Part 7:
Write a main program to completely test the function from Part 6.
Part 8:
Write a main program called program_client that takes two command
line parameters that are named pipes. The first parameter will be referred
to as to_server and the second will be referred to as
to_client.
Part 9:
Write a main program called program_server that takes three command
line parameters: a filename and two named pipes.
The first parameter will be referred to as infile and the named pipes
will be referred to as to_server and to_client.
This program will be similar to the show_programs from Assignment 1,
but it will read from and send to named pipes.
Handing in your program:
Use this cover sheet. Consecutively number all of
the other pages you turn in. Each page that contains your work should have
a number on it. Turn this in at the beginning of lecture on the due date.