Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21– 1 –15-441, Fall 2003Advice on ProgrammingSept. 4, 2003TopicsTopicsRobust ProgrammingVersion ControlUsing scripting languagesClass02b15-441– 1 –15-441, Fall 2003About This LectureVersion control / Source controlVersion control / Source controlPresented today: RCS(by a rogue instructor)Rogue instructor's opinion of RCS: extremelyextremely obsolete(Though it can be used effectively as a building block)Why will we discuss RCS today?“Received wisdom” says...»It's really hard to get students to use source control.»Many refuse.»The quickest thing to explain is RCS.»Maybe if we describe something simple people might use it.– 1 –15-441, Fall 2003About This LectureHope, fear, loathing, ...Hope, fear, loathing, ...We hope you will use something to safeguard your sanityEasiest thing to explain is RCSRCS is fine for Project 1Your “friends” may have already introduced you to CVS“Friends don't let friends branch CVS”It's fine with us if you use CVS»(necessary evolutionary step, like tube worms)For a conceptually clearer time...Try PRCSIt's small (not as small as RCS, not as big as CVS)Most-important features of source control are default behaviors!See last semester's PRCS intro from 15-410, posted on 441 site– 1 –15-441, Fall 2003Client / ServerSessionClient/Server CodeClientServersocket socketbindlistenrio_readlinebrio_writenrio_readlinebrio_writenConnectionrequestrio_readlinebclosecloseEOFAwait connectionrequest fromnext clientopen_listenfdopen_clientfdacceptconnect– 1 –15-441, Fall 2003Robustness PrinciplesClientClientNothing user does/types should make program crashMust perform complete checking for user errorsServerServerNothing a client does should cause server to malfunctionPossibly malicious clientsThings to Worry AboutThings to Worry AboutError return codes by system callsString overflowsMalformed messagesMemory/resource leaksEspecially for server– 1 –15-441, Fall 2003Echo Client Main Routine#include "csapp.h" /* usage: ./echoclient host port */int main(int argc, char **argv){ int clientfd, port; char *host, buf[MAXLINE]; rio_t rio; host = argv[1]; port = atoi(argv[2]); clientfd = Open_clientfd(host, port); Rio_readinitb(&rio, clientfd); while (Fgets(buf, MAXLINE, stdin) != NULL) { Rio_writen(clientfd, buf, strlen(buf)); Rio_readlineb(&rio, buf, MAXLINE); Fputs(buf, stdout); } Close(clientfd); exit(0); } No checking of command line argumentsWrappers exit on errorfgets does not insert \n when string too long– 1 –15-441, Fall 2003Robust Version of Echo Client (1) #include <limits.h>/* To demonstrate truncation */#define LINELEN 20/* Maximum number of errors to tolerate before exiting */int errlimit = 5;void errcheck(char *message, int fatal){ if (--errlimit == 0 || fatal) { fprintf(stderr, "Error: %s. Exiting\n", message); exit(1); } fprintf(stderr, "Error: %s. Continuing\n", message);}void usage(char *progname) { fprintf(stderr, "Usage: %s host port\n", progname); exit(0);}– 1 –15-441, Fall 2003Robust Version of Echo Client (2) int main(int argc, char **argv) { int clientfd, port; char *host, buf[LINELEN]; rio_t rio; if (argc != 3) usage(argv[0]); host = argv[1]; port = atoi(argv[2]); if (port <= 0 || port > SHRT_MAX) errcheck("Invalid Port", 1); clientfd = open_clientfd(host, port); if (clientfd < 0) errcheck("Couldn't open connection to server", 1); rio_readinitb(&rio, clientfd); ...– 1 –15-441, Fall 2003Robust Version of Echo Client (3) ... while (fgets(buf, LINELEN, stdin) != NULL) { int n; if (strlen(buf) == LINELEN-1 && buf[LINELEN-1] != '\n') strcpy(buf+LINELEN-5, "...\n"); /* Truncate string */ if (rio_writen(clientfd, buf, strlen(buf)) < 0) { errcheck("Failed to send message", 0); continue; } if ((n = rio_readlineb(&rio, buf, LINELEN) <= 0)) { if (n == 0)errcheck("Unexpected EOF from server\n", 1); elseerrcheck("Failed to receive reply from server", 0); } if (fputs(buf, stdout) < 0) errcheck("Couldn't print reply\n", 0); } ...– 1 –15-441, Fall 2003Robust Version of Echo Client (4) ... if (close(clientfd) < 0) errcheck("Couldn't close connection to server", 1); exit(0);}– 1 –15-441, Fall 2003Design IssuesError Classification & RecoveryError Classification & RecoveryFatal vs. nonfatal errorsServer code should only have fatal error when something is wrong on server machineWhat to do when when encounter nonfatal errorSkip to next activityServer might close connection to malfunctioning clientOther Types of ErrorsOther Types of ErrorsClient dormant too longAdd timeouts to codeGets very messyDenial of service attacksDifficult to detect and/or handle– 1 –15-441, Fall 2003Version ControlTypical Problems in Managing Software ProjectTypical Problems in Managing Software ProjectMultiple people simultaneously edit single fileWant to prevent this or have some way to merge updatesBug appears in new version that was not detected in earlier versionWant to run tests on older versionCustomer reports problem with program. Turns out he/she has old version of codeWant to back up to earlier version of programCode evolves along incompatible paths by two groupsWant to reconcile into common versionSolutionSolutionImplement some form of automatic version control– 1 –15-441, Fall 2003RCSRevision Control SystemRevision Control SystemBasic Unix program(s) for managing software projectWritten by Walter Tichy, CMU PhD 1980Basic IdeaBasic IdeaCode file foo.c has RCS version foo.c,vComplete history of all versions of fileStored in compacted formUser can “check out” copy of fileEither read-only or writableEven when writable, only single user can do soCan check out older versions of programWhen file modified, can “check in” fileIncrements version numberBecomes available for other users to check out– 1 –15-441, Fall 2003RCS ExampleCode for Echo ServerCode for Echo Server% lsMakefile csapp.c csapp.h echoserver.c% mkdir RCS # Directory for RCS files% ci Makefile csapp.c csapp.h echoserver.c# RCS prompts for descriptions of
View Full Document