Diff for /rpl/src/instructions_r4.c between versions 1.54 and 1.55

version 1.54, 2012/06/18 15:15:31 version 1.55, 2012/06/19 09:34:54
Line 851  instruction_read(struct_processus *s_eta Line 851  instruction_read(struct_processus *s_eta
     int                             c;      int                             c;
     int                             ios;      int                             ios;
   
       integer8                        ancienne_longueur_effective;
     integer8                        element;      integer8                        element;
     integer8                        i;      integer8                        i;
     integer8                        id;      integer8                        id;
Line 863  instruction_read(struct_processus *s_eta Line 864  instruction_read(struct_processus *s_eta
     integer8                        position_finale;      integer8                        position_finale;
     integer8                        position_initiale;      integer8                        position_initiale;
   
   
     logical1                        indicateur_48;      logical1                        indicateur_48;
     logical1                        presence_chaine;      logical1                        presence_chaine;
     logical1                        presence_indicateur;      logical1                        presence_indicateur;
Line 900  instruction_read(struct_processus *s_eta Line 900  instruction_read(struct_processus *s_eta
     unsigned char                   caractere;      unsigned char                   caractere;
     unsigned char                   *clef_utf8;      unsigned char                   *clef_utf8;
     unsigned char                   *commande;      unsigned char                   *commande;
       unsigned char                   poubelle[256];
     unsigned char                   *ptr;      unsigned char                   *ptr;
     unsigned char                   *tampon_lecture;      unsigned char                   *tampon_lecture;
     unsigned char                   *tampon;      unsigned char                   *tampon;
Line 2210  printf("L=%d\n", longueur_enregistrement Line 2211  printf("L=%d\n", longueur_enregistrement
         if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')          if ((*((struct_socket *) (*s_objet_argument_1).objet)).binaire == 'N')
         { // Socket formatée          { // Socket formatée
             longueur_questure = 256;              longueur_questure = 256;
               longueur_effective = 0;
               tampon_lecture = NULL;
   
             do              do
             {              {
                 if ((tampon_lecture = malloc((longueur_questure + 1) *                  presence_indicateur = d_faux;
                         sizeof(unsigned char))) == NULL)  
                   if ((tampon_lecture = realloc(tampon_lecture,
                           (longueur_effective + longueur_questure)
                           * sizeof(unsigned char))) == NULL)
                 {                  {
                     (*s_etat_processus).erreur_systeme =                      (*s_etat_processus).erreur_systeme =
                             d_es_allocation_memoire;                              d_es_allocation_memoire;
Line 2234  printf("L=%d\n", longueur_enregistrement Line 2240  printf("L=%d\n", longueur_enregistrement
                 attente.tv_sec = 0;                  attente.tv_sec = 0;
                 attente.tv_nsec = GRANULARITE_us * 1000;                  attente.tv_nsec = GRANULARITE_us * 1000;
   
                 for(;;)                  if ((*((struct_socket *) (*s_objet_argument_1).objet))
                           .domaine == PF_UNIX)
                   {
                       longueur_adresse = sizeof(adresse_unix);
                       ios = recvfrom((*((struct_socket *)
                               (*s_objet_argument_1).objet)).socket,
                               tampon_lecture + longueur_effective,
                               longueur_questure,
                               MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
                               &adresse_unix, &longueur_adresse);
                   }
                   else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                           .domaine == PF_INET)
                   {
                       longueur_adresse = sizeof(adresse_ipv4);
                       ios = recvfrom((*((struct_socket *)
                               (*s_objet_argument_1).objet)).socket,
                               tampon_lecture + longueur_effective,
                               longueur_questure,
                               MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
                               &adresse_ipv4, &longueur_adresse);
                   }
                   else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                           .domaine == PF_INET6)
                   {
   #                   ifdef IPV6
                       longueur_adresse = sizeof(adresse_ipv6);
                       ios = recvfrom((*((struct_socket *)
                               (*s_objet_argument_1).objet)).socket,
                               tampon_lecture + longueur_effective,
                               longueur_questure,
                               MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)
                               &adresse_ipv6, &longueur_adresse);
   #                   else
                       if ((*s_etat_processus).langue == 'F')
                       {
                           printf("+++Attention : Support du protocole"
                                   " IPv6 indisponible\n");
                       }
                       else
                       {
                           printf("+++Warning : IPv6 support "
                                   "unavailable\n");
                       }
   
                       longueur_adresse = 0;
                       longueur_effective = 0;
                       ios = 0;
   #                   endif
                   }
                   else
                   {
                       free(tampon_lecture);
                       liberation(s_etat_processus, s_objet_argument_1);
   
   #                   ifndef SEMAPHORES_NOMMES
                           while(sem_wait(&((*s_etat_processus)
                                   .semaphore_fork)) != 0)
   #                   else
                           while(sem_wait((*s_etat_processus)
                                   .semaphore_fork) != 0)
   #                   endif
                       {
                           (*s_etat_processus).erreur_systeme =
                                   d_es_processus;
                       }
   
                       (*s_etat_processus).erreur_execution =
                               d_ex_erreur_acces_fichier;
                       return;
                   }
   
                   if (ios < 0)
                   {
                       nanosleep(&attente, NULL);
                       INCR_GRANULARITE(attente.tv_nsec);
                       scrutation_injection(s_etat_processus);
                   }
   
                   if ((*s_etat_processus).var_volatile_requete_arret == -1)
                   {
                       longueur_effective += ios;
                       break;
                   }
   
                   // Une donnée a été reçue.
   
                   if (ios >= 0)
                 {                  {
                       ancienne_longueur_effective = longueur_effective;
                       longueur_effective += ios;
                       position_initiale = 0;
                       presence_indicateur = d_faux;
   
                       do
                       {
                           if (tampon_lecture[position_initiale] == '{')
                           {
                               presence_indicateur = d_vrai;
                               break;
                           }
   
                           position_initiale++;
                       } while(position_initiale < longueur_effective);
   
                       if (presence_indicateur == d_vrai)
                       {
                           position_finale = position_initiale + 1;
                           presence_chaine = d_faux;
                           presence_indicateur = d_faux;
                           niveau = 1;
   
                           while(position_finale < longueur_effective)
                           {
                               caractere = tampon_lecture[position_finale];
   
                               if (caractere == '"')
                               {
                                   presence_chaine =
                                           (presence_chaine == d_vrai)
                                           ? d_faux : d_vrai;
                               }
                               else
                               {
                                   if (presence_chaine == d_faux)
                                   {
                                       if (caractere == '{')
                                       {
                                           niveau++;
                                       }
                                       else if (caractere == '}')
                                       {
                                           niveau--;
                                       }
                                   }
                               }
   
                               if (niveau == 0)
                               {
                                   presence_indicateur = d_vrai;
                                   break;
                               }
   
                               position_finale++;
                           }
                       }
   
                       // On retire du buffer position_finale -
                       // ancienne_longueur_effective octets.
   
                     if ((*((struct_socket *) (*s_objet_argument_1).objet))                      if ((*((struct_socket *) (*s_objet_argument_1).objet))
                             .domaine == PF_UNIX)                              .domaine == PF_UNIX)
                     {                      {
                         longueur_adresse = sizeof(adresse_unix);                          longueur_adresse = sizeof(adresse_unix);
                         longueur_effective = recvfrom((*((struct_socket *)                          ios = recvfrom((*((struct_socket *)
                                 (*s_objet_argument_1).objet)).socket,                                  (*s_objet_argument_1).objet)).socket,
                                 tampon_lecture, longueur_questure,                                  poubelle, position_finale
                                 MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)                                  - ancienne_longueur_effective,
                                   MSG_DONTWAIT, (struct sockaddr *)
                                 &adresse_unix, &longueur_adresse);                                  &adresse_unix, &longueur_adresse);
                     }                      }
                     else if ((*((struct_socket *) (*s_objet_argument_1).objet))                      else if ((*((struct_socket *) (*s_objet_argument_1)
                             .domaine == PF_INET)                              .objet)).domaine == PF_INET)
                     {                      {
                         longueur_adresse = sizeof(adresse_ipv4);                          longueur_adresse = sizeof(adresse_ipv4);
                         longueur_effective = recvfrom((*((struct_socket *)                          ios = recvfrom((*((struct_socket *)
                                 (*s_objet_argument_1).objet)).socket,                                  (*s_objet_argument_1).objet)).socket,
                                 tampon_lecture, longueur_questure,                                  poubelle, position_finale
                                 MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)                                  - ancienne_longueur_effective,
                                   MSG_DONTWAIT, (struct sockaddr *)
                                 &adresse_ipv4, &longueur_adresse);                                  &adresse_ipv4, &longueur_adresse);
                     }                      }
                     else if ((*((struct_socket *) (*s_objet_argument_1).objet))                      else if ((*((struct_socket *) (*s_objet_argument_1)
                             .domaine == PF_INET6)                              .objet)) .domaine == PF_INET6)
                     {                      {
 #                       ifdef IPV6  #                       ifdef IPV6
                         longueur_adresse = sizeof(adresse_ipv6);                          longueur_adresse = sizeof(adresse_ipv6);
                         longueur_effective = recvfrom((*((struct_socket *)                          ios = recvfrom((*((struct_socket *)
                                 (*s_objet_argument_1).objet)).socket,                                  (*s_objet_argument_1).objet)).socket,
                                 tampon_lecture, longueur_questure,                                  poubelle, position_finale
                                 MSG_PEEK | MSG_DONTWAIT, (struct sockaddr *)                                  - ancienne_longueur_effective,
                                   MSG_DONTWAIT, (struct sockaddr *)
                                 &adresse_ipv6, &longueur_adresse);                                  &adresse_ipv6, &longueur_adresse);
 #                       else  #                       else
                         if ((*s_etat_processus).langue == 'F')                          if ((*s_etat_processus).langue == 'F')
Line 2279  printf("L=%d\n", longueur_enregistrement Line 2436  printf("L=%d\n", longueur_enregistrement
                         }                          }
   
                         longueur_adresse = 0;                          longueur_adresse = 0;
                         longueur_effective = 0;  
 #                       endif  #                       endif
                     }                      }
                     else  
                       if (presence_indicateur == d_faux)
                     {                      {
                         free(tampon_lecture);                          poll_fd.fd = (*((struct_socket *)
                         liberation(s_etat_processus, s_objet_argument_1);                                  (*s_objet_argument_1).objet)).socket;
                           poll_fd.events = POLLIN;
   
 #                       ifndef SEMAPHORES_NOMMES                          while((ios = poll(&poll_fd, 1, 100)) <= 0)
                             while(sem_wait(&((*s_etat_processus)  
                                     .semaphore_fork)) != 0)  
 #                       else  
                             while(sem_wait((*s_etat_processus)  
                                     .semaphore_fork) != 0)  
 #                       endif  
                         {                          {
                             (*s_etat_processus).erreur_systeme =                              // La fin de la trame n'est pas atteinte
                                     d_es_processus;                              // et il reste quelque chose à lire.
                         }  
   
                         (*s_etat_processus).erreur_execution =                              switch(ios)
                                 d_ex_erreur_acces_fichier;                              {
                         return;                                  case EINTR:
                     }                                  {
                                       break;
                     if (longueur_effective < 0)                                  }
                     {  
                         nanosleep(&attente, NULL);  
                         INCR_GRANULARITE(attente.tv_nsec);  
                         scrutation_injection(s_etat_processus);  
                     }  
   
                     // Une donnée a été reçue.                                  case 0:
                                   {
                                       liberation(s_etat_processus,
                                               s_objet_argument_1);
                                       free(tampon_lecture);
   
                     if (((*s_etat_processus).var_volatile_requete_arret == -1)                                      (*s_etat_processus).erreur_execution =
                             || (longueur_effective >= 0))                                              d_ex_fin_de_fichier_atteinte;
                     {                                      return;
                         break;                                  }
                               }
                           }
                     }                      }
                 }                  }
   
Line 2357  printf("L=%d\n", longueur_enregistrement Line 2509  printf("L=%d\n", longueur_enregistrement
                             d_ex_erreur_acces_fichier;                              d_ex_erreur_acces_fichier;
                     return;                      return;
                 }                  }
   
                 position_initiale = 0;  
                 presence_indicateur = d_faux;  
   
                 do  
                 {  
                     if (tampon_lecture[position_initiale] == '{')  
                     {  
                         presence_indicateur = d_vrai;  
                         break;  
                     }  
   
                     position_initiale++;  
                 } while(position_initiale < longueur_effective);  
   
   
                 if (presence_indicateur == d_vrai)  
                 {  
                     position_finale = position_initiale + 1;  
                     presence_chaine = d_faux;  
                     presence_indicateur = d_faux;  
                     niveau = 1;  
   
                     while(position_finale < longueur_effective)  
                     {  
                         caractere = tampon_lecture[position_finale];  
   
                         if (caractere == '"')  
                         {  
                             presence_chaine = (presence_chaine == d_vrai)  
                                     ? d_faux : d_vrai;  
                         }  
                         else  
                         {  
                             if (presence_chaine == d_faux)  
                             {  
                                 if (caractere == '{')  
                                 {  
                                     niveau++;  
                                 }  
                                 else if (caractere == '}')  
                                 {  
                                     niveau--;  
                                 }  
                             }  
                         }  
   
                         if (niveau == 0)  
                         {  
                             presence_indicateur = d_vrai;  
                             break;  
                         }  
   
                         position_finale++;  
                     }  
                 }  
   
                 if (presence_indicateur == d_faux)  
                 {  
                     if (longueur_effective < longueur_questure)  
                     {  
                         poll_fd.fd = (*((struct_socket *)  
                                 (*s_objet_argument_1).objet)).socket;  
                         poll_fd.events = POLLIN;  
   
                         if (poll(&poll_fd, 1, 0) > 0)  
                         {  
                             free(tampon_lecture);  
                             continue;  
                         }  
   
                         liberation(s_etat_processus, s_objet_argument_1);  
                         free(tampon_lecture);  
   
                         (*s_etat_processus).erreur_execution =  
                                 d_ex_fin_de_fichier_atteinte;  
                         return;  
                     }  
   
                     free(tampon_lecture);  
                     longueur_questure *= 2;  
                 }  
             } while(presence_indicateur == d_faux);              } while(presence_indicateur == d_faux);
   
             tampon_lecture[++position_finale] = d_code_fin_chaine;              tampon_lecture[++position_finale] = d_code_fin_chaine;
Line 2531  printf("L=%d\n", longueur_enregistrement Line 2601  printf("L=%d\n", longueur_enregistrement
                     (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))                      (strcmp((*((struct_socket *) (*s_objet_argument_1).objet))
                     .type, "SEQUENTIAL DATAGRAM") == 0))                      .type, "SEQUENTIAL DATAGRAM") == 0))
             {              {
                 longueur_adresse = 0;  
                 recvfrom((*((struct_socket *)  
                         (*s_objet_argument_1).objet)).socket, tampon_lecture,  
                         longueur_effective, MSG_DONTWAIT,  
                         NULL, &longueur_adresse);  
   
                 (*s_objet_adresse).objet = NULL;                  (*s_objet_adresse).objet = NULL;
             }              }
             else if ((*((struct_socket *) (*s_objet_argument_1).objet))              else if ((*((struct_socket *) (*s_objet_argument_1).objet))
                     .domaine == PF_INET)                      .domaine == PF_INET)
             {              {
                 longueur_adresse = sizeof(adresse_ipv4);  
                 recvfrom((*((struct_socket *)  
                         (*s_objet_argument_1).objet)).socket, tampon_lecture,  
                         longueur_effective, MSG_DONTWAIT,  
                         (struct sockaddr *) &adresse_ipv4, &longueur_adresse);  
   
                 if (((*s_objet_adresse).objet =                  if (((*s_objet_adresse).objet =
                         allocation_maillon(s_etat_processus)) == NULL)                          allocation_maillon(s_etat_processus)) == NULL)
                 {                  {
Line 2622  printf("L=%d\n", longueur_enregistrement Line 2680  printf("L=%d\n", longueur_enregistrement
                     .domaine == PF_INET6)                      .domaine == PF_INET6)
             {              {
 #               ifdef IPV6  #               ifdef IPV6
                 longueur_adresse = sizeof(adresse_ipv6);  
                 recvfrom((*((struct_socket *)  
                         (*s_objet_argument_1).objet)).socket, tampon_lecture,  
                         longueur_effective, MSG_DONTWAIT,  
                         (struct sockaddr *) &adresse_ipv6, &longueur_adresse);  
   
                 if (((*s_objet_adresse).objet =                  if (((*s_objet_adresse).objet =
                         allocation_maillon(s_etat_processus)) == NULL)                          allocation_maillon(s_etat_processus)) == NULL)
                 {                  {

Removed from v.1.54  
changed lines
  Added in v.1.55


CVSweb interface <joel.bertrand@systella.fr>