next up previous contents
Next: The client Up: A file server Previous: Design of interface

Server implementation

You need to write the server implementation of the rfopen(), rfread(), etc. The rfopen() functions merely fopen()s the file, and record the FILE* pointer in the global fd_table and return the index to the client.

The rfread() function is listed below,

int   rfread(void *ptr, int size, int nm, rFILE * stream)
{
    FILE           *fp;
    int             index = stream->fd;

    /* first check if the index is valid, 
       if true, get the FILE pointer */
    if (index < 0 || index >= MAXFILE 
        || (fp = fd_table[index]) == 0) 
    {
        fprintf(stderr, "Invalid rFILE pointer!\n");
        return -1;
    }
    return fread(ptr, size, nm, fp);
}

That is it! The rfwrirte() function is defined by replacing the word read in the above with write.

The rchdir() function is even simpler.

int   rchdir(char *path)
{
    return chdir(path);
}

The rlistdir() function is a bit more complicated, but probaly you can make it simpler by writing a more elegant linked list.



Copyright (C) Netbula LLC, 1996