--- rpl/src/instructions_w1.c 2013/04/01 15:29:38 1.82 +++ rpl/src/instructions_w1.c 2016/03/01 22:12:35 1.102 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.14 - Copyright (C) 1989-2013 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.25 + Copyright (C) 1989-2016 Dr. BERTRAND Joël This file is part of RPL/2. @@ -289,11 +289,25 @@ instruction_wait(struct_processus *s_eta scrutation_injection(s_etat_processus); + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) + != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_non_affectees != 0) { affectation_interruptions_logicielles(s_etat_processus); } + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) + != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_en_queue != 0) { traitement_interruptions_logicielles(s_etat_processus); @@ -698,7 +712,8 @@ instruction_write(struct_processus *s_et free(chaine); - if (alsprintf(&commande, "insert or replace into data " + if (alsprintf(s_etat_processus, &commande, + "insert or replace into data " "(id, data) values (%lld, '%s')", (*((integer8 *) (*s_objet_argument_2).objet)), chaine_utf8) < 0) { @@ -748,8 +763,8 @@ instruction_write(struct_processus *s_et // Récupération de la position de la clef - if (alsprintf(&commande, "select key from control " - "where id = 1") < 0) + if (alsprintf(s_etat_processus, &commande, + "select key from control where id = 1") < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -925,8 +940,8 @@ instruction_write(struct_processus *s_et // Récupération de l'identifiant de la clef - if (alsprintf(&commande, "select id from key where key = " - "'%s'", clef_utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "select id from key where key = '%s'", clef_utf8) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -971,8 +986,9 @@ instruction_write(struct_processus *s_et free(commande); - if (alsprintf(&commande, "insert into key " - "(key) values ('%s')", clef_utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "insert into key (key) values ('%s')", + clef_utf8) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1005,8 +1021,9 @@ instruction_write(struct_processus *s_et free(commande); - if (alsprintf(&commande, "select id from key " - "where key = '%s'", clef_utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "select id from key where key = '%s'", + clef_utf8) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1069,8 +1086,9 @@ instruction_write(struct_processus *s_et if (mise_a_jour == d_vrai) { - if (alsprintf(&commande, "update key set key = '%s' where " - "id = %lld", clef_utf8, id) < 0) + if (alsprintf(s_etat_processus, &commande, + "update key set key = '%s' where id = %lld", + clef_utf8, id) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1105,8 +1123,8 @@ instruction_write(struct_processus *s_et // Effacement de l'enregistrement existant - if (alsprintf(&commande, "delete from data where " - "key_id = %lld", id) < 0) + if (alsprintf(s_etat_processus, &commande, + "delete from data where key_id = %lld", id) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1240,8 +1258,8 @@ instruction_write(struct_processus *s_et free(chaine); - if (alsprintf(&commande, "insert into data " - "(data, key_id, sequence) values " + if (alsprintf(s_etat_processus, &commande, + "insert into data (data, key_id, sequence) values " "('%s', %lld, %lld)", chaine_utf8, id, ordre) < 0) { (*s_etat_processus).erreur_systeme = @@ -1480,9 +1498,9 @@ instruction_write(struct_processus *s_et return; } - if ((format_chaine = conversion_majuscule((unsigned char *) - (*(*l_element_courant_format).donnee).objet)) - == NULL) + if ((format_chaine = conversion_majuscule(s_etat_processus, + (unsigned char *) (*(*l_element_courant_format) + .donnee).objet)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -2197,8 +2215,8 @@ instruction_wflock(struct_processus *s_e do { - if ((chaine = conversion_majuscule((unsigned char *) - (*s_objet_argument_1).objet)) == NULL) + if ((chaine = conversion_majuscule(s_etat_processus, + (unsigned char *) (*s_objet_argument_1).objet)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; return; @@ -2279,13 +2297,26 @@ instruction_wflock(struct_processus *s_e } else { + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) + != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_non_affectees != 0) { affectation_interruptions_logicielles(s_etat_processus); } - if ((*s_etat_processus).nombre_interruptions_en_queue - != 0) + if (pthread_mutex_unlock(&(*s_etat_processus) + .mutex_interruptions) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + + if ((*s_etat_processus).nombre_interruptions_en_queue != 0) { registre_instruction_valide = (*s_etat_processus).instruction_valide; @@ -2399,7 +2430,8 @@ instruction_wfproc(struct_processus *s_e } } - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2464,7 +2496,8 @@ instruction_wfproc(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2544,8 +2577,12 @@ instruction_wfproc(struct_processus *s_e * Le processus n'est pas terminé */ - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus) + .mutex_interruptions)) != 0) { + pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)); + if ((*s_etat_processus).profilage == d_vrai) { profilage(s_etat_processus, NULL); @@ -2562,8 +2599,36 @@ instruction_wfproc(struct_processus *s_e affectation_interruptions_logicielles(s_etat_processus); } - if ((*s_etat_processus).nombre_interruptions_en_queue - != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_interruptions)) != 0) + { + pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)); + + if ((*s_etat_processus).profilage == d_vrai) + { + profilage(s_etat_processus, NULL); + } + + (*s_etat_processus).erreur_systeme = + d_es_processus; + return; + } + + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) + { + if ((*s_etat_processus).profilage == d_vrai) + { + profilage(s_etat_processus, NULL); + } + + (*s_etat_processus).erreur_systeme = + d_es_processus; + return; + } + + if ((*s_etat_processus).nombre_interruptions_en_queue != 0) { registre_instruction_valide = (*s_etat_processus).instruction_valide; @@ -2602,7 +2667,8 @@ instruction_wfproc(struct_processus *s_e scrutation_injection(s_etat_processus); - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2624,7 +2690,8 @@ instruction_wfproc(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2727,7 +2794,8 @@ instruction_wfdata(struct_processus *s_e } } - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2787,7 +2855,8 @@ instruction_wfdata(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2830,7 +2899,8 @@ instruction_wfdata(struct_processus *s_e return; } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2871,12 +2941,26 @@ instruction_wfdata(struct_processus *s_e scrutation_injection(s_etat_processus); + if (pthread_mutex_lock(&(*s_etat_processus) + .mutex_interruptions) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_non_affectees != 0) { affectation_interruptions_logicielles(s_etat_processus); } + if (pthread_mutex_unlock(&(*s_etat_processus) + .mutex_interruptions) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_en_queue != 0) { registre_instruction_valide = @@ -2896,7 +2980,8 @@ instruction_wfdata(struct_processus *s_e return; } - if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_lock(&((*s_etat_processus) + .mutex_pile_processus)) != 0) { if ((*s_etat_processus).profilage == d_vrai) { @@ -2923,7 +3008,8 @@ instruction_wfdata(struct_processus *s_e profilage(s_etat_processus, NULL); } - if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0) + if (pthread_mutex_unlock(&((*s_etat_processus).mutex_pile_processus)) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2955,6 +3041,121 @@ instruction_wfdata(struct_processus *s_e ================================================================================ */ +static inline logical1 +options_sockets(struct_processus *s_etat_processus, struct_socket *s_socket) +{ + int drapeau; + + if (((*s_socket).options & (1 << d_BROADCAST)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_BROADCAST, &drapeau, + sizeof(drapeau)) != 0) + { + return(d_erreur); + } + } + + if (((*s_socket).options & (1 << d_DONT_ROUTE)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_DONTROUTE, &drapeau, + sizeof(drapeau)) != 0) + { + return(d_erreur); + } + } + + if (((*s_socket).options & (1 << d_KEEP_ALIVE)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_KEEPALIVE, &drapeau, + sizeof(drapeau)) != 0) + { + return(d_erreur); + } + } + +# ifdef SO_PRIORITY + if (((*s_socket).options & (1 << d_PRIORITY)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_PRIORITY, + &((*s_socket).priorite), sizeof((*s_socket).priorite)) != 0) + { + return(d_erreur); + } + } +# endif + + // Les deux options suivantes ne peuvent être positionnées simultanément. + + if (((*s_socket).options & (1 << d_RECEIVE_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUF, + &((*s_socket).buffer_reception), + sizeof((*s_socket).buffer_reception)) != 0) + { + return(d_erreur); + } + } + +# ifdef SO_RCVBUFFORCE + if (((*s_socket).options & (1 << d_FORCE_RECEIVE_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVBUFFORCE, + &((*s_socket).buffer_reception), + sizeof((*s_socket).buffer_reception)) != 0) + { + return(d_erreur); + } + } +# endif + + // Même remarque + + if (((*s_socket).options & (1 << d_SEND_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUF, + &((*s_socket).buffer_emission), + sizeof((*s_socket).buffer_emission)) != 0) + { + return(d_erreur); + } + } + +# ifdef SO_SNDBUFFORCE + if (((*s_socket).options & (1 << d_FORCE_SEND_BUFFER)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDBUFFORCE, + &((*s_socket).buffer_emission), + sizeof((*s_socket).buffer_emission)) != 0) + { + return(d_erreur); + } + } +# endif + + if (((*s_socket).options & (1 << d_RECEIVING_TIMEOUT)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_RCVTIMEO, + &((*s_socket).timeout_emission), + sizeof((*s_socket).timeout_emission)) != 0) + { + return(d_erreur); + } + } + + if (((*s_socket).options & (1 << d_SENDING_TIMEOUT)) != 0) + { + if (setsockopt((*s_socket).socket, SOL_SOCKET, SO_SNDTIMEO, + &((*s_socket).timeout_emission), + sizeof((*s_socket).timeout_emission)) != 0) + { + return(d_erreur); + } + } + + return(d_absence_erreur);; +} + + void instruction_wfsock(struct_processus *s_etat_processus) { @@ -3140,12 +3341,12 @@ instruction_wfsock(struct_processus *s_e { drapeau = d_vrai; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) -# else +# else if (sem_post((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3160,11 +3361,11 @@ instruction_wfsock(struct_processus *s_e erreur = errno; # ifndef SEMAPHORES_NOMMES - while(sem_wait(&((*s_etat_processus) - .semaphore_fork)) != 0) + while(sem_wait(&((*s_etat_processus) + .semaphore_fork)) != 0) # else - while(sem_wait((*s_etat_processus).semaphore_fork) - != 0) + while(sem_wait((*s_etat_processus).semaphore_fork) + != 0) # endif { if (errno != EINTR) @@ -3198,13 +3399,13 @@ instruction_wfsock(struct_processus *s_e } else { -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3213,6 +3414,17 @@ instruction_wfsock(struct_processus *s_e return; } } + + if (options_sockets(s_etat_processus, + (*s_objet_resultat).objet) != d_absence_erreur) + { + liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_resultat); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return; + } } } while(drapeau == d_faux); @@ -3243,12 +3455,12 @@ instruction_wfsock(struct_processus *s_e { drapeau = d_vrai; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) -# else +# else if (sem_post((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3261,13 +3473,13 @@ instruction_wfsock(struct_processus *s_e { erreur = errno; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3300,13 +3512,13 @@ instruction_wfsock(struct_processus *s_e } else { -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3315,6 +3527,17 @@ instruction_wfsock(struct_processus *s_e return; } } + + if (options_sockets(s_etat_processus, + (*s_objet_resultat).objet) != d_absence_erreur) + { + liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_resultat); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return; + } } } while(drapeau == d_faux); @@ -3365,12 +3588,12 @@ instruction_wfsock(struct_processus *s_e { drapeau = d_vrai; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) -# else +# else if (sem_post((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3383,13 +3606,13 @@ instruction_wfsock(struct_processus *s_e { erreur = errno; -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3422,13 +3645,13 @@ instruction_wfsock(struct_processus *s_e } else { -# ifndef SEMAPHORES_NOMMES +# ifndef SEMAPHORES_NOMMES while(sem_wait(&((*s_etat_processus) .semaphore_fork)) != 0) -# else +# else while(sem_wait((*s_etat_processus).semaphore_fork) != 0) -# endif +# endif { if (errno != EINTR) { @@ -3437,6 +3660,17 @@ instruction_wfsock(struct_processus *s_e return; } } + + if (options_sockets(s_etat_processus, + (*s_objet_resultat).objet) != d_absence_erreur) + { + liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_resultat); + + (*s_etat_processus).erreur_execution = + d_ex_erreur_parametre_fichier; + return; + } } } while(drapeau == d_faux); } @@ -3607,11 +3841,25 @@ instruction_wfswi(struct_processus *s_et return; } + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) + != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_non_affectees != 0) { affectation_interruptions_logicielles(s_etat_processus); } + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) + != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).queue_interruptions[interruption - 1] > 0) { drapeau_fin = d_vrai; @@ -3744,11 +3992,23 @@ instruction_wfpoke(struct_processus *s_e scrutation_injection(s_etat_processus); + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_non_affectees != 0) { affectation_interruptions_logicielles(s_etat_processus); } + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_en_queue != 0) { registre_instruction_valide = @@ -3851,11 +4111,23 @@ instruction_wfack(struct_processus *s_et { scrutation_injection(s_etat_processus); + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_non_affectees != 0) { affectation_interruptions_logicielles(s_etat_processus); } + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0) + { + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } + if ((*s_etat_processus).nombre_interruptions_en_queue != 0) { registre_instruction_valide =