Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. if (fork()==0)
  2.  
  3.       {
  4.  
  5.      
  6.  
  7.        //FIGLIO
  8.  
  9.        
  10.  
  11.         close(listenfd);
  12.  
  13.         printf("Dentro il figlio, pid=%i\n", getpid());
  14.  
  15.        
  16.  
  17.         host=gethostbyaddr( (char *) &cliaddr.sin_addr, sizeof(cliaddr.sin_addr), AF_INET);
  18.  
  19.        
  20.  
  21.           if (host == NULL)
  22.  
  23.           {
  24.  
  25.             printf("client host information not found\n"); continue;
  26.  
  27.           }
  28.  
  29.           else printf("Server (figlio): host client e' %s \n", host->h_name);
  30.  
  31.  
  32.  
  33.         // ----------------- RICEZIONE -----------------
  34.  
  35.         i= 0;
  36.         while (app != '\0')
  37.         {
  38.  
  39.             read(connfd,&app,1);
  40.             buff[i] = app;
  41.             i++;
  42.         }
  43.  
  44.        
  45.  
  46.        
  47.  
  48.         // ELABORAZIONE DATI
  49.  
  50.         for(i = 0; i < DIM; i++)
  51.         {
  52.             j = 0;
  53.             if (strcmp(campeggio[i].prenotazione, buff) == 0)
  54.             {
  55.                 while (campeggio[i].immagine[j] != '\0')
  56.                 {
  57.                     write(connfd,&campeggio[i].immagine[j],1);
  58.                     j++;
  59.                 }
  60.                 write(connfd,"\0",1);
  61.  
  62.                 if((fd=open(campeggio[i].immagine, O_RDONLY))<0)
  63.                 {
  64.                     perror("open file sorgente");
  65.                     continue;
  66.                 }
  67.  
  68.                 lung = lseek(fd, 0, SEEK_END);
  69.                 lseek(fd, 0, 0);
  70.  
  71.                 printf("%d\n", lung);
  72.                
  73.                 write(connfd,&lung, sizeof(int));              
  74.  
  75.                 while ( read(fd, &app, 1) > 0)
  76.                 {
  77.                     write(connfd,&app, 1);                 
  78.                 }
  79.            
  80.                
  81.             }
  82.    
  83.         }
  84.         write(connfd,"X", 1);
  85.  
  86.          
  87.  
  88.         // ----------------- INVIO -----------------
  89.  
  90.        
  91.  
  92.          
  93.  
  94.         close(connfd);
  95.  
  96.         // CHIUSURA RISORSE APERTE
  97.  
  98.  
  99.  
  100.         printf("Figlio %i: termino\n", getpid());
  101.  
  102.         exit(0);
  103.  
  104.  
  105.  
  106.       }//figlio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement