File:  [local] / rpl / src / instructions_p8.c
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Mon Dec 5 19:49:41 2011 UTC (12 years, 5 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Typo.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.5
    4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
    5: 
    6:   This file is part of RPL/2.
    7: 
    8:   RPL/2 is free software; you can redistribute it and/or modify it
    9:   under the terms of the CeCILL V2 License as published by the french
   10:   CEA, CNRS and INRIA.
   11:  
   12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
   13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
   15:   for more details.
   16:  
   17:   You should have received a copy of the CeCILL License
   18:   along with RPL/2. If not, write to info@cecill.info.
   19: ================================================================================
   20: */
   21: 
   22: 
   23: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Fonction 'poll'
   29: ================================================================================
   30:   Entrées : pointeur sur une structure struct_processus
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_poll(struct_processus *s_etat_processus)
   40: {
   41:     int                     erreur;
   42:     int                     ios;
   43:     int                     timeout;
   44: 
   45:     logical1                drapeau;
   46: 
   47:     struct_liste_chainee    *l_element_courant;
   48: 
   49:     struct_objet            *s_objet_argument_1;
   50:     struct_objet            *s_objet_argument_2;
   51:     struct_objet            *s_objet_argument_3;
   52:     struct_objet            *s_objet_resultat;
   53: 
   54:     struct pollfd           s_poll;
   55: 
   56:     unsigned char           *registre;
   57: 
   58:     if ((*s_etat_processus).affichage_arguments == 'Y')
   59:     {
   60:         printf("\n  POLL ");
   61: 
   62:         if ((*s_etat_processus).langue == 'F')
   63:         {
   64:             printf("(attente d'un événement sur un fichier ou une socket)\n\n");
   65:         }
   66:         else
   67:         {
   68:             printf("(wait for event on file or socket)\n\n");
   69:         }
   70: 
   71:         if ((*s_etat_processus).langue == 'F')
   72:         {
   73:             printf("  Utilisation :\n\n");
   74:         }
   75:         else
   76:         {
   77:             printf("  Usage:\n\n");
   78:         }
   79: 
   80:         printf("    FILE { \"POLLIN\" \"POLLOUT\" } TIMEOUT POLL\n\n");
   81:         printf("    3: %s, %s\n", d_SCK, d_FCH);
   82:         printf("    2: %s\n", d_LST);
   83:         printf("    1: %s, %s\n", d_INT, d_REL);
   84:         printf("->  1: %s\n", d_INT);
   85: 
   86:         return;
   87:     }
   88:     else if ((*s_etat_processus).test_instruction == 'Y')
   89:     {
   90:         (*s_etat_processus).nombre_arguments = -1;
   91:         return;
   92:     }
   93: 
   94:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
   95:     {
   96:         if (empilement_pile_last(s_etat_processus, 3) == d_erreur)
   97:         {
   98:             return;
   99:         }
  100:     }
  101: 
  102:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  103:             &s_objet_argument_1) == d_erreur)
  104:     {
  105:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  106:         return;
  107:     }
  108: 
  109:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  110:             &s_objet_argument_2) == d_erreur)
  111:     {
  112:         liberation(s_etat_processus, s_objet_argument_1);
  113: 
  114:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  115:         return;
  116:     }
  117: 
  118:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  119:             &s_objet_argument_3) == d_erreur)
  120:     {
  121:         liberation(s_etat_processus, s_objet_argument_1);
  122:         liberation(s_etat_processus, s_objet_argument_2);
  123: 
  124:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  125:         return;
  126:     }
  127: 
  128:     if (((*s_objet_argument_3).type == SCK) ||
  129:             ((*s_objet_argument_3).type == FCH))
  130:     {
  131:         if ((*s_objet_argument_3).type == SCK)
  132:         {
  133:             s_poll.fd = (*((struct_socket *)
  134:                     (*s_objet_argument_1).objet)).socket;
  135:         }
  136:         else
  137:         {
  138:             s_poll.fd = (*((struct_fichier *) 
  139:                     (*s_objet_argument_1).objet)).descripteur;
  140:         }
  141: 
  142:         if ((*s_objet_argument_2).type != LST)
  143:         {
  144:             liberation(s_etat_processus, s_objet_argument_1);
  145:             liberation(s_etat_processus, s_objet_argument_2);
  146:             liberation(s_etat_processus, s_objet_argument_3);
  147: 
  148:             (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  149:             return;
  150:         }
  151: 
  152:         l_element_courant = (*s_objet_argument_2).objet;
  153:         s_poll.events = 0;
  154: 
  155:         while(l_element_courant != NULL)
  156:         {
  157:             if ((*(*l_element_courant).donnee).type != CHN)
  158:             {
  159:                 liberation(s_etat_processus, s_objet_argument_1);
  160:                 liberation(s_etat_processus, s_objet_argument_2);
  161:                 liberation(s_etat_processus, s_objet_argument_3);
  162: 
  163:                 (*s_etat_processus).erreur_execution =
  164:                         d_ex_erreur_type_argument;
  165:                 return;
  166:             }
  167: 
  168:             if ((registre = conversion_majuscule((unsigned char *)
  169:                     (*(*l_element_courant).donnee).objet)) == NULL)
  170:             {
  171:                 (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  172:                 return;
  173:             }
  174: 
  175:             if (strcmp(registre, "POLLIN") == 0)
  176:             {
  177:                 s_poll.events |= POLLIN;
  178:             }
  179:             else if (strcmp(registre, "POLLOUT") == 0)
  180:             {
  181:                 s_poll.events |= POLLOUT;
  182:             }
  183:             else
  184:             {
  185:                 free(registre);
  186: 
  187:                 liberation(s_etat_processus, s_objet_argument_1);
  188:                 liberation(s_etat_processus, s_objet_argument_2);
  189:                 liberation(s_etat_processus, s_objet_argument_3);
  190: 
  191:                 (*s_etat_processus).erreur_execution =
  192:                         d_ex_erreur_parametre_fichier;
  193:                 return;
  194:             }
  195: 
  196:             free(registre);
  197:             l_element_courant = (*l_element_courant).suivant;
  198:         }
  199: 
  200:         s_poll.revents = 0;
  201: 
  202:         if ((*s_objet_argument_1).type == INT)
  203:         {
  204:             timeout = (*((integer8 *) (*s_objet_argument_1).objet)) * 1000L;
  205:         }
  206:         else if ((*s_objet_argument_1).type == REL)
  207:         {
  208:             timeout = (int) ((*((real8 *) (*s_objet_argument_1).objet))
  209:                     * 1000L);
  210:         }
  211:         else
  212:         {
  213:             liberation(s_etat_processus, s_objet_argument_1);
  214:             liberation(s_etat_processus, s_objet_argument_2);
  215:             liberation(s_etat_processus, s_objet_argument_3);
  216: 
  217:             (*s_etat_processus).erreur_execution =
  218:                     d_ex_erreur_type_argument;
  219:             return;
  220:         }
  221: 
  222:         if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
  223:         {
  224:             (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
  225:             return;
  226:         }
  227: 
  228:         do
  229:         {
  230:             drapeau = d_vrai;
  231: 
  232: #           ifndef SEMAPHORES_NOMMES
  233:             if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
  234: #           else
  235:             if (sem_post((*s_etat_processus).semaphore_fork) != 0)
  236: #           endif
  237:             {
  238:                 (*s_etat_processus).erreur_systeme = d_es_processus;
  239:                 return;
  240:             }
  241: 
  242:             if ((ios = poll(&s_poll, 1, timeout)) < 0)
  243:             {
  244:                 erreur = errno;
  245: 
  246: #               ifndef SEMAPHORES_NOMMES
  247:                 while(sem_wait(&((*s_etat_processus)
  248:                         .semaphore_fork)) != 0)
  249: #               else
  250:                 while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
  251: #               endif
  252: 
  253:                 if (erreur != EINTR)
  254:                 {
  255:                     liberation(s_etat_processus, s_objet_argument_1);
  256:                     liberation(s_etat_processus, s_objet_argument_2);
  257:                     liberation(s_etat_processus, s_objet_argument_3);
  258:                     liberation(s_etat_processus, s_objet_resultat);
  259: 
  260:                     (*s_etat_processus).erreur_execution =
  261:                             d_ex_erreur_acces_fichier;
  262:                     return;
  263:                 }
  264: 
  265:                 scrutation_injection(s_etat_processus);
  266: 
  267:                 if ((*s_etat_processus).var_volatile_requete_arret != 0)
  268:                 {
  269:                     drapeau = d_vrai;
  270:                 }
  271:                 else
  272:                 {
  273:                     drapeau = d_faux;
  274:                 }
  275:             }
  276:             else
  277:             {
  278: #               ifndef SEMAPHORES_NOMMES
  279:                     while(sem_wait(&((*s_etat_processus)
  280:                             .semaphore_fork)) != 0)
  281: #               else
  282:                     while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
  283: #               endif
  284:                 {
  285:                     if (errno != EINTR)
  286:                     {
  287:                         (*s_etat_processus).erreur_systeme =
  288:                                 d_es_processus;
  289:                         return;
  290:                     }
  291:                 }
  292:             }
  293:         } while(drapeau == d_faux);
  294: 
  295:         if (ios > 0)
  296:         {
  297:             // Sortie sur un événement
  298:             (*((integer8 *) (*s_objet_resultat).objet)) = -1;
  299:         }
  300:         else
  301:         {
  302:             // Sortie sur timeout
  303:             (*((integer8 *) (*s_objet_resultat).objet)) = 0;
  304:         }
  305: 
  306:         liberation(s_etat_processus, s_objet_argument_1);
  307:         liberation(s_etat_processus, s_objet_argument_2);
  308:         liberation(s_etat_processus, s_objet_argument_3);
  309: 
  310:         if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  311:                 s_objet_resultat) == d_erreur)
  312:         {
  313:             return;
  314:         }
  315:     }
  316:     else
  317:     {
  318:         liberation(s_etat_processus, s_objet_argument_1);
  319:         liberation(s_etat_processus, s_objet_argument_2);
  320:         liberation(s_etat_processus, s_objet_argument_3);
  321: 
  322:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  323:         return;
  324:     }
  325: 
  326:     return;
  327: }
  328: 
  329: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>