IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Linux Discussion :

timerfd_settime error: 22: Invalid argument


Sujet :

Linux

  1. #1
    Membre régulier
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Points : 113
    Points
    113
    Par défaut timerfd_settime error: 22: Invalid argument
    Bonjour, ligne 57, j'ai timerfd_settime() qui retourne -1.
    L'erreur est: settime error: 22: Invalid argument

    Voila le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    #include "EpollTimer.h"
    #include "Epoll.h"
     
    #include <iostream>
    #include <sys/timerfd.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
     
    char buff_temp[sizeof(uint64_t)];
     
    EpollTimer::EpollTimer()
    {
        tfd=-1;
        singleShot=false;
    }
     
    BaseClassSwitch::Type EpollTimer::getType() const
    {
        return BaseClassSwitch::Type::Timer;
    }
     
    bool EpollTimer::start(const unsigned int &msec)
    {
        if(tfd!=-1)
            return false;
        if((tfd=::timerfd_create(CLOCK_REALTIME,0)) < 0)
        {
            std::cerr << "Timer creation error" << std::endl;
            return false;
        }
     
        timespec now;
        if (clock_gettime(CLOCK_REALTIME, &now) == -1)
        {
            std::cerr << "clock_gettime error" << std::endl;
            return false;
        }
        itimerspec new_value;
        if(singleShot)
        {
            new_value.it_value.tv_sec = now.tv_sec + msec/1000;
            new_value.it_value.tv_nsec = now.tv_nsec + (msec%1000)*1000000;
            new_value.it_interval.tv_sec = 0;
            new_value.it_interval.tv_nsec = 0;
        }
        else
        {
            new_value.it_value.tv_sec = now.tv_sec + msec/1000;
            new_value.it_value.tv_nsec = now.tv_nsec + (msec%1000)*1000000;
            new_value.it_interval.tv_sec = msec/1000;
            new_value.it_interval.tv_nsec = (msec%1000)*1000000;
        }
     
        if(::timerfd_settime(tfd, TFD_TIMER_ABSTIME, &new_value, NULL)<0)
        {
            //settime error: 22: Invalid argument
            std::cerr << "settime error: " << errno << ": " << strerror(errno) << std::endl;
            return false;
        }
        epoll_event event;
        event.data.ptr = this;
        event.events = EPOLLIN;
        if(Epoll::epoll.ctl(EPOLL_CTL_ADD,tfd,&event) < 0)
        {
            std::cerr << "epoll_ctl error" << std::endl;
            return false;
        }
        return true;
    }
     
    bool EpollTimer::start()
    {
        return start(msec);
    }
     
    void EpollTimer::setInterval(const unsigned int &msec)
    {
        this->msec=msec;
    }
     
    void EpollTimer::setSingleShot(const bool &singleShot)
    {
        this->singleShot=singleShot;
    }
     
    void EpollTimer::exec()
    {
        ::read(tfd, buff_temp, sizeof(uint64_t));
    }
    Merci d'avance pour votre aide.
    Développeur d'Ultracopier

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Bonjour,

    L'erreur tombe sur EINVAL -> http://www-numi.fnal.gov/offline_sof...em_errors.html (du moins, y a de grandes chances).

    Les possibilités sont :
    EINVAL fd is not a valid timerfd file descriptor.
    EINVAL new_value is not properly initialized (one of the tv_nsec falls
    outside the range zero to 999,999,999).

    EINVAL flags is invalid.
    La dernière, j'ai vérifié, ce n'est pas le cas.
    Donc, à votre place, j'afficherai la valeur de new_value et de fd, pour bien vérifier que cela match quelque chose de correct.
    Je passerai un petit coup de strace aussi, au cas où

    Peut être comme votre premier problème de la dernière fois, il aime pas le CLOCK_REALTIME ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  3. #3
    Membre régulier
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Points : 113
    Points
    113
    Par défaut
    Le fd est correcte, donc il ne reste que l'erreur 2.
    Et ca correspondrai bien avec le fait que ce soit alleatoire.
    Développeur d'Ultracopier

  4. #4
    Membre régulier
    Avatar de alpha_one_x86
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Décembre 2006
    Messages
    411
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Somme (Picardie)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2006
    Messages : 411
    Points : 113
    Points
    113
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    if(new_value.it_value.tv_nsec>999999999 || new_value.it_value.tv_nsec<0)
            {
                std::cerr << "nsec out of range" << std::endl;
                abort();
                return false;
            }
    Fait bien bugger, donc:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    if(new_value.it_value.tv_nsec>999999999)
            {
                new_value.it_value.tv_nsec-=1000000000;
                new_value.it_value.tv_sec++;
            }
    Merci du coup de main.
    Développeur d'Ultracopier

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Invalid argument supplied for foreach()
    Par Rajhonson dans le forum Langage
    Réponses: 4
    Dernier message: 16/11/2006, 14h31
  2. Réponses: 11
    Dernier message: 19/05/2006, 11h41
  3. Réponses: 26
    Dernier message: 24/03/2006, 13h44
  4. [Tableaux] Problème invalid argument foreach()
    Par kcizth dans le forum Langage
    Réponses: 9
    Dernier message: 05/01/2006, 11h56
  5. Invalid argument?
    Par Anduriel dans le forum Langage
    Réponses: 24
    Dernier message: 12/10/2005, 19h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo