Advertisement
Guest User

part2

a guest
May 3rd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** sol13.15.c
  2.  ** ------------------------------------------------------------
  3.     A version of lclnt2 that asks for a new ticket if its
  4.     current ticket is not valid is
  5.       sol13.15.c.
  6.  
  7.     Another extension would be for the program to sleep for
  8.     a short while and try again.  The program could ask if
  9.     it should continue to wait for a ticket to become available
  10.     or just wrap up and try again later.
  11.  
  12.     An interesting extension of this problem would be to
  13.     replace the sleep with a request for a signal.  Say the
  14.     client asks for a ticket but is told there are none.  The
  15.     client could send its pid to the server and ask to be
  16.     sent a signal when a ticket becomes available.  The client
  17.     could then pause until the server sends a signal.  The
  18.     client would present its pid and ask for its ticket.
  19.  
  20.  ** ------------------------------------------------------------
  21.  **
  22.  **
  23.  *   Version of lclnt2.c that tries to get a new ticket if ticket
  24.  *   validation fails.  This allows the client to continue if the
  25.  *   had been restarted or has otherwise lost a record of this client's
  26.  *   ticket.
  27.  *
  28.  *   build: cc sol13.15.c lclnt_funcs2.c dgram.c -o sol13.15
  29.  */
  30.  
  31. /****************************************************************************
  32.  * lclnt2.c
  33.  * License server client version 2
  34.  *  link with lclnt_funcs.o dgram.o
  35.  */
  36.  
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <unistd.h>
  40.  
  41. int get_ticket();
  42. void    do_regular_work();
  43. void    release_ticket();
  44. void    shut_down();
  45. int validate_ticket();
  46. int setup();
  47.  
  48. int main(int ac, char *av[])
  49. {
  50.     setup();
  51.     if (get_ticket() != 0 )
  52.         exit(0);   
  53.  
  54.     do_regular_work();
  55.  
  56.     release_ticket();
  57.     shut_down();
  58.     return 0;
  59.  
  60. }
  61. /****************************************************************************
  62.  * do_regular_work  the main work of the application goes here
  63.  */
  64. void do_regular_work()
  65. {
  66.     printf("SuperSleep version 1.0 Running - Licensed Software\n");
  67.     sleep(15)/* our patented sleep algorithm */
  68.  
  69.     if ( validate_ticket() != 0 && get_ticket() != 0 ){
  70.         printf("Server errors. Please Try later.\n");
  71.         return;
  72.     }
  73.     sleep(15);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement