--- rpl/src/instructions_w1.c 2013/05/23 12:45:08 1.83 +++ rpl/src/instructions_w1.c 2016/09/27 15:29:39 1.105 @@ -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.26 + Copyright (C) 1989-2016 Dr. BERTRAND Joël This file is part of RPL/2. @@ -289,7 +289,8 @@ instruction_wait(struct_processus *s_eta scrutation_injection(s_etat_processus); - if (pthread_mutex_lock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -300,7 +301,8 @@ instruction_wait(struct_processus *s_eta affectation_interruptions_logicielles(s_etat_processus); } - if (pthread_mutex_unlock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -710,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) { @@ -760,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; @@ -937,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; @@ -983,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; @@ -1017,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; @@ -1081,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; @@ -1117,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; @@ -1252,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 = @@ -1492,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; @@ -2209,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; @@ -2291,7 +2297,8 @@ instruction_wflock(struct_processus *s_e } else { - if (pthread_mutex_lock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2302,7 +2309,8 @@ instruction_wflock(struct_processus *s_e affectation_interruptions_logicielles(s_etat_processus); } - if (pthread_mutex_unlock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_unlock(&(*s_etat_processus) + .mutex_interruptions) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2422,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) { @@ -2487,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; @@ -2512,7 +2522,7 @@ instruction_wfproc(struct_processus *s_e { if (envoi_signal_processus((*(*((struct_processus_fils *) (*(*l_element_courant).donnee).objet)).thread).pid, - rpl_signull) != 0) + rpl_signull, d_faux) != 0) { drapeau_fin = d_vrai; } @@ -2567,13 +2577,46 @@ instruction_wfproc(struct_processus *s_e * Le processus n'est pas terminé */ + 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); + } + + (*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)) != 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) { @@ -2624,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) { @@ -2646,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; @@ -2749,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) { @@ -2809,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; @@ -2852,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) { @@ -2893,7 +2941,8 @@ instruction_wfdata(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_interruptions) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2905,7 +2954,8 @@ instruction_wfdata(struct_processus *s_e affectation_interruptions_logicielles(s_etat_processus); } - if (pthread_mutex_unlock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_unlock(&(*s_etat_processus) + .mutex_interruptions) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -2930,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) { @@ -2957,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; @@ -2989,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) { @@ -3174,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; @@ -3194,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) @@ -3232,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) { @@ -3247,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); @@ -3277,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; @@ -3295,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) { @@ -3334,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) { @@ -3349,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); @@ -3399,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; @@ -3417,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) { @@ -3456,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) { @@ -3471,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); } @@ -3641,7 +3841,8 @@ instruction_wfswi(struct_processus *s_et return; } - if (pthread_mutex_lock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3652,7 +3853,8 @@ instruction_wfswi(struct_processus *s_et affectation_interruptions_logicielles(s_etat_processus); } - if (pthread_mutex_unlock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) + != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3790,7 +3992,7 @@ instruction_wfpoke(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_interruptions) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3801,7 +4003,7 @@ instruction_wfpoke(struct_processus *s_e affectation_interruptions_logicielles(s_etat_processus); } - if (pthread_mutex_unlock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3909,7 +4111,7 @@ instruction_wfack(struct_processus *s_et { scrutation_injection(s_etat_processus); - if (pthread_mutex_lock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_lock(&(*s_etat_processus).mutex_interruptions) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -3920,7 +4122,7 @@ instruction_wfack(struct_processus *s_et affectation_interruptions_logicielles(s_etat_processus); } - if (pthread_mutex_unlock(&(*s_etat_processus).mutex) != 0) + if (pthread_mutex_unlock(&(*s_etat_processus).mutex_interruptions) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return;