CS452 - Real-Time Programming - Fall 2009

Lecture 11 - The Name Server

Reminders


Why Do We Need a Name Server

Names constant across applications & executions interface Associated with a set of services (an API)
Task Ids vary across applications & executions implementation Associated with a particular set of instructions and data (an execution)

How do You Get the Task Id of the Name Server?

Name Server API

int RegisterAs( char *name );
int WhoIs( char *name );

Name Server Semantics

RegisterAs

WhoIs

Comments

Name Server Implementation

User Code

typedef struct {
    int type;
    char *name;
} NSstruct;
int RegisterAs( char *name ) {
    int result;
    NSstruct req;
    req.type = REGISTERAS;
    req.name = name;
    bytes = Send( NSTid, &req, sizeof(NSstruct), (char *) result, sizeof(int) );
    if ( bytes != sizeof(int) ) {
        // Do something error-like
    } else return result;
}

There are lots of possible variations, and this one is by no means the best.

Server Code

typedef struct {
    int type;
    char *name;
} NSstruct;
int bytes, tid;
NSstruct req;
// initialize tables
FOREVER {
    bytes = Receive( &tid, &req, sizeof(NSstruct) );
    if ( bytes != sizeof(NSstruct) ) {
        // Reply with error
    } else {
        switch( req.type ) {
        case REGISTERAS:
            insert( name, tid );
            Reply( tid, SUCCESS, sizeof(int) );
            break;
        case WHOIS:
            result = lookup( name );
            Reply( tid, result, sizeof(int) );
            break;
        default
            Reply( tid, ERROR, sizeof(int) );
            break;
        }
    }
}

Comments

  1. This code wouldn't work. Why?
  2. How much will this code run?
  3. How would you implement insert & lookup?
  4. You could send a hash of name.
  5. What should be allowable as a name?

Return to: