Synchronous I/O - Unix

This is a discussion on Synchronous I/O - Unix ; Hi all, I have a problem when I started debugging , select () call always returns -1. I have made a small sample that reproduces the problem, can some body indicate what is the problem here, #include int main(int argc, ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Synchronous I/O

  1. Synchronous I/O

    Hi all,

    I have a problem when I started debugging , select () call always
    returns -1. I have made a small sample
    that reproduces the problem, can some body indicate what is the
    problem here,

    #include

    int main(int argc, char *argv[])
    {

    fd_set fd_s;
    int lsock,ret;
    struct timeval timeout;

    timeout.tv_sec = 1;
    timeout.tv_usec = 0;

    lsock=3;

    FD_ZERO(&fd_s);

    FD_SET(lsock, &fd_s);

    ret=select(lsock+1,(void *)&fd_s, (void *)0, (void *)0,
    &timeout);

    printf ("%d",ret);
    }

    select() call always returns -1?

    Thanks in advance,
    Seema Rao


  2. Re: Synchronous I/O

    seema writes:

    >Hi all,


    >I have a problem when I started debugging , select () call always
    >returns -1. I have made a small sample
    >that reproduces the problem, can some body indicate what is the
    >problem here,


    >#include


    >int main(int argc, char *argv[])
    >{


    > fd_set fd_s;
    > int lsock,ret;
    > struct timeval timeout;


    > timeout.tv_sec = 1;
    > timeout.tv_usec = 0;


    > lsock=3;


    > FD_ZERO(&fd_s);


    > FD_SET(lsock, &fd_s);


    > ret=select(lsock+1,(void *)&fd_s, (void *)0, (void *)0,
    >&timeout);


    > printf ("%d",ret);
    >}


    >select() call always returns -1?



    errno is probably always EBADF.

    File descriptor 3 point to what file?

    Casper
    --
    Expressed in this posting are my opinions. They are in no way related
    to opinions held by my employer, Sun Microsystems.
    Statements on Sun products included here are not gospel and may
    be fiction rather than truth.

  3. Re: Synchronous I/O

    On 4月23日, 下午6时38分, seema wrote:
    > Hi all,
    >
    > I have a problem when I started debugging , select () call always
    > returns -1. I have made a small sample
    > that reproduces the problem, can some body indicate what is the
    > problem here,
    >
    > #include
    >
    > int main(int argc, char *argv[])
    > {
    >
    > fd_set fd_s;
    > int lsock,ret;
    > struct timeval timeout;
    >
    > timeout.tv_sec = 1;
    > timeout.tv_usec = 0;
    >
    > lsock=3;


    You didn't assign lsock to a return from open() or socket() etc, only
    0, 1, 2 is opened by system default, so fd number 3 is incorrect.



  4. Re: Synchronous I/O

    You need to actually create a socket before you use select().


+ Reply to Thread