UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2002-09-11 02:30 PM

emihaly
Member
Registered: 2002-08-01
Posts: 191

Re: eeeeeeeeeh

fd_set rset;
tv.tv_sec=0;
tv.tc_usec=0; or 1
FD_ZERO(&rset);
FD_SET(0,&rset);
while(1)
{
q=select(0+1,&rset,NULL,NULL,&tv);

if (q)
{
printf(|keypress!....
}
}

still no reaction! I use robs off line buff + this code and nothing!
I use redhat 7.2 console no kde and no gnome.

Where is problem?

Offline

#2 2002-09-11 06:31 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: eeeeeeeeeh

I don't know...  All I can tell you is the following code works just
fine for me in RH6.2, RH7.3, and QNX4.2:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <sys/select.h>

int main (int argc, char *argv[])
{
    int     i;
    char    c;
    fd_set  rfds;
    struct termios  oldtty, newtty;

    tcgetattr (0, &oldtty);
    memcpy (&newtty, &oldtty, sizeof (newtty));
    newtty.c_lflag &= ~ICANON;
    tcsetattr (0, TCSANOW, &newtty);

    for (;;) {
        FD_ZERO (&rfds);
        FD_SET (0, &rfds);
        i = select (1, &rfds, NULL, NULL, NULL);
        fprintf (stderr, "select() = %d\n", i);
        if (i > 0) {
            i = read (0, &c, 1);
            fprintf (stderr, "read() = %d; c = %c\n", i, c);
            if (c == 'Q')
                break;
        }
    }

    tcsetattr (0, TCSANOW, &oldtty);

    exit (0);
}

Does the above code work as-is for you on your system? If not, well
then I don't know what the problem is...  But, if so, then something must
be wrong with your code, somewhere...  Start tweaking the working code
until it breaks, and see what you're doing wrong... *shrug*

Offline

#3 2002-09-11 07:53 PM

mlampkin
Administrator
From: Sol 3
Registered: 2002-06-12
Posts: 911
Website

Re: eeeeeeeeeh

Out of the threading section and into general...

Seems more appropriate here.... :-/


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)

Offline

Board footer

Powered by FluxBB