/* * Kyle Box * EECS 338 Spring 2007 * Assignment 7: RPC Programming * * Written and compiled on Debian Linux 2.4.29 * Compiled on gcc version 3.3.5 with: * gcc -Wall mother.c client_svc.c -o mother */ #include "cookie.h" // getmemycookie_1_svc // Handles handing out cookies to Tina and Judy int *getmemycookie_1_svc(int *argp, struct svc_req *rqstp) { static int result, tina = 0, cookies = 20; if (cookies <= 0) { // No cookies left result = -2; } else if (*argp == 0) { // Tina tina++; cookies--; result = 1; } else if (*argp == 1) { // Judy if (tina < 2) { result = -1; } else { tina = 0; cookies--; result = 1; } } else { // Invalid parameter result = -3; } return &result; } // terminate_1_svc // Tina and Judy call this when they terminate // When both are terminated, mother will terminate as well void *terminate_1_svc(int *argp, struct svc_req *rqstp) { static int tina = 0, judy = 0; if (*argp == 0) { // Tina has terminated tina = 1; } else { // Judy has terminated judy = 1; } // If both have terminated, exit if (tina && judy) { exit(0); } return NULL; }