Due Date: Monday Nov 16
1. Implement a thread-safe set of functions for accessing a fixed-record length flatfile database. That is, the database is a single file containing a collection of records, all the same length. The functions consist of:
typedef ... DBFILE; // a descriptor for the database file DBFILE dbopen(char *filename, int recordlength) - open the file and set the record length. Note that to keep things simpler, the recordlength isn't stored in the file. dbopen() only needs to be called once in the program for a given file, the DBFILE descriptor then being made available to all threads.
dbseek(DBFILE dbf, int recordnumber) - seek to a specific record number. The first record in the file is record 0.
dbnextrecord(DBFILE dbf, void *buffer) - reads the current record into the buffer and advances to the next record. It is the programmer's responsibility to insure that the buffer is large enough.
dbwrite(DBFILE dbf, void *buffer) - writes the buffer to the current record (overwriting existing data) and advances to the next record.
dbsort(DBFILE dbuf, int (*comparefn)(void *, void *) - sorts the database based on the comparison function passed as the second argument. You may assume that the database is small enough to fit entirely in memory (i.e., you can basically make this function a wrapper for qsort).
How you handle end-of-file and out of range seeks is up to you, but it should make sense.
The functions must be thread-safe. Furthermore, seek, read, and write operations in different threads should happen independently. For example, if two threads have a loop that calls dbnextrecord() until hitting end of file, then both threads should get all the records, rather than splitting the records between them.
2. Serverize the above code. I.e., create a concurrent server that allows clients to connect, open databaase files, and access the functions.
3. Several people have written "watch" type programs that print messages when users log on and off a system. Most such programs simply report on the host on which the program is running, typically examining /var/adm/wtmp at regular intervals (see the wtmp man page for information on the format of this file).
Discuss possible designs for a 'netwatch' system that would
report on logins over a network. Users would type the command
"netwatch
Implement one of your designs.
IMPORTANT: Do not run servers for this program on hops. Only
run them on malt and the insux machines. Also, be very careful
that you do not leave servers running when you log off. Taking
care to use shared resources in a considerate manner is important
and if I receive reports that servers have been left running, it
will affect the grade on this program.