--- rpl/src/instructions_w1.c 2015/06/08 14:11:43 1.97 +++ rpl/src/instructions_w1.c 2015/09/15 19:18:46 1.98 @@ -3041,6 +3041,115 @@ 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); + } + } + + 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); + } + } + + // 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); + } + } + + 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); + } + } + + // 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); + } + } + + 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); + } + } + + 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) { @@ -3226,12 +3335,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; @@ -3246,11 +3355,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) @@ -3284,13 +3393,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) { @@ -3299,6 +3408,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); @@ -3329,12 +3449,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; @@ -3347,13 +3467,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) { @@ -3386,13 +3506,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) { @@ -3401,6 +3521,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); @@ -3451,12 +3582,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; @@ -3469,13 +3600,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) { @@ -3508,13 +3639,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) { @@ -3523,6 +3654,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); }