- df_open(filenumber, mode)
- df_close(filenumber)
- df_read(filenumber, databuffer, datasize)
- df_write(filenumber, databuffer, datasize)
The implementation of these calls must be consistent with the following requirements:
To simplify things, assume all files are of size 1Kbytes.
You will need to multi-thread the client and server sides. A dispatcher thread in the server can receive client requests and fork worker threads to handle them. At the client side, we must allow the client to execute whatever code it wants mixed in with calls to read and write files. This means that we cannot assume that the client will receive and handle messages that arrive at it in a timely fashion. The problem of getting the client's attention when a message arrives can be solved in a number of ways. For example, we can use a Cthreads thread running on a separate logical processor as a handler thread. This handler thread waits on messages to arrive and handles them when they are received. Other options include periodic polling via the select() call or the use of signals.
You can assume that the server is started first and it is initialized with copies of N files (you can set N to 64 -- files are numbered 0 -- 63). The inital state of all files should be a string of 1024 '.' characters. The socket address of the server is well known. To avoid the problems that arise due to unreliable communication, you can use TCP sockets. You can also assume that the set of clients (say 4) is statically determined. Each client cache can hold 8 files.
In addition to the client API defined above, you can use
an InitSystem() call that is executed before
any read/writes are done. The read and write calls access the
file number specified in the call parameter.
You need to implement a replacement algorithm for the client caches. You are free to choose whatever replacement algorithm you like (as long as it is a reasonable one).
Finally, for performance comparisons, you should do the following measurements:
Getting accurate times for the above operations is quite tricky in a shared environment. Also, you may not have access to a fine-grain timer to measure these times. You can repeat an operation many times and can choose the average time to deal with some of these problems.
# This is a comment
O 14 r
C 14
W 14 This is a test message
R 14 22
Q
Note: these test sequences have not yet been debugged; if something seems funny, feel free to email Lex about it.
Test 1:
Test 2:
Test 3:
df_open(), df_read(), etc., should
be in a different file or files from the test code's
main().