Unix Programming - Synchronous I/O

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2007 > Synchronous I/O





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Synchronous I/O
seema

2007-04-23, 7:19 am

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 <sys/time.h>

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

Casper H.S. Dik

2007-04-23, 7:19 am

seema <seema_coma@yahoo.co.in> 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 <sys/time.h>


>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.
Bin Chen

2007-04-24, 1:23 pm

On 4=D4=C223=C8=D5, =CF=C2=CE=E76=CA=B138=B7=D6, seema <seema_c...@yahoo.co=
..in> 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 <sys/time.h>
>
> int main(int argc, char *argv[])
> {
>
> fd_set fd_s;
> int lsock,ret;
> struct timeval timeout;
>
> timeout.tv_sec =3D 1;
> timeout.tv_usec =3D 0;
>
> lsock=3D3;


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.


chsalvia@gmail.com

2007-04-24, 7:18 pm

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

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com