I was given this task to implement an API with these definitions below which allow processes to memory map sections of a file located on a remote server. I am also required to implement a client/server example.
// Type definition for remote file location
struct fileloc {
struct in_addr ipaddress; // Remote IP
int port; // Remote port
char *pathname; // Remote file to be memory mapped
};
typedef struct fileloc fileloc_t;
// Create a new memory mapping in the virtual address space of the calling process
// location: Remote file to be memory mapped
void *rmmap(fileloc_t location, off_t offset);
// Deletes mapping for the specified address range
// addr: Address returned by mmap
int rmunmap(void *addr);
// Attempt to read up to count bytes from memory mapped area pointed
// to by addr + offset into buff
ssize_t mread(void *addr, off_t offset, void *buff, size_t count);
// Attempt to write up to count bytes to memory mapped area pointed
// to by addr + offset from buff
ssize_t mwrite(void *addr, off_t offset, void *buff, size_t count);
I am facing some design challenges. Here is what I have thought of:
- The client for the first time calls
rmmap()
, predefining the server location and the requested file, along with an offset.The server returns a fixed chunk of the file back to the client. - the server will take note of which client requested which chunk of file. It will also keep a table of ClientIDs, rquested offsets, and flag status (locked or not). Conflict handling refers to this table.
- the read and write functions will be used locally on the client and will have no connection to the server. (although I'm wondering if it's possible connect to the server before writing such that a client can only write when no one is reading).
- The
unmap()
will be used to "commit" changes to the server.
I'm still not sure on locking files and solving conflicts, however am I on the right track?