socket, select, timeout - Linux

This is a discussion on socket, select, timeout - Linux ; Hello, I have some problem understanding the behaviour of select() in C code (compiled with gcc, against pthread -NPTL-, running under Linux 2.6.22.1-rt9). This is UDP sockets, with a sender and a receiver. Here is what the receiver does : ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: socket, select, timeout

  1. socket, select, timeout

    Hello,

    I have some problem understanding the behaviour of select() in C code
    (compiled with gcc, against pthread -NPTL-, running under Linux
    2.6.22.1-rt9).

    This is UDP sockets, with a sender and a receiver.

    Here is what the receiver does :
    //"sock" is an fd created with avec socket(PF_INET, SOCK_DGRAM, ..)
    //"set" is an fd_set containing only sock
    while(condition) {
    attente.tv_sec = 0;
    attente.tv_usec = 100000;
    int ret = select(sock+1, &set, NULL, NULL, &attente);
    if (ret < 0) perror(select);
    if (ret == 0) {
    printf("timeout\n");
    continue;
    }
    printf("data available\n");
    recv(sock, buffer, ..);
    //use of data
    }

    It works as expected except in the following scenario :
    1 - Start sender
    2 - Start receiver
    data available
    ....
    3 - Stop sender
    timeout
    ....
    4 - Start sender
    timeout
    ....

    Tcpdump confirms that the packets are arriving on the good port, but
    select keeps returning on timeouts.

    For info, sockets are not connected.

    After step 4, if I do a recv(..) on the socket, I get a packet.

    I am somehow misunderstanding how it is supposed to work, or misusing
    it. How do you explain this behaviour ?

    Thanks for any idea you can give me,
    Fabrice

  2. Re: socket, select, timeout

    Ok, Nevermind. Let's say I've never been here.

+ Reply to Thread