LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-05-2010, 04:50 AM   #1
VGM
Member
 
Registered: Apr 2009
Posts: 33

Rep: Reputation: 15
Question timeout for standard input using tcsetattr not working


The code is attached..My intention is that getchar which usually blocks,should come out after 5 seconds(VTIME).But this is not happening..can anyone tell me the mistake that I make..?

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>

int main()
{
int g,fd;
struct termios oldtio;
struct termios newtio;


g= tcgetattr( STDIN_FILENO, &oldtio );
tcgetattr( fd, &oldtio );
memcpy( &newtio, &oldtio, sizeof(oldtio) );
newtio.c_cc[VTIME] = 50;
newtio.c_cc[VMIN] = 0;

tcflush( STDIN_FILENO, TCIFLUSH );
tcsetattr( fd, TCSANOW, &newtio );

g=getchar();

tcsetattr( fd, TCSANOW, &oldtio );
return 0;
}
 
Old 01-05-2010, 07:56 AM   #2
kunstkopf
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Rep: Reputation: 0
fd assignment?

You try to modify a device with a file descriptor which is not
opened. Where does it say: fd = open( .... ???
 
1 members found this post helpful.
Old 01-05-2010, 10:10 AM   #3
VGM
Member
 
Registered: Apr 2009
Posts: 33

Original Poster
Rep: Reputation: 15
sorry..I copied from a wrong place..it is this one that I was suppose to copy...its not working...

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>

int main()
{
int g,fd;
struct termios oldtio;
struct termios newtio;


tcgetattr( STDIN_FILENO, &oldtio );

memcpy( &newtio, &oldtio, sizeof(oldtio) );
newtio.c_cc[VTIME] = 50;
newtio.c_cc[VMIN] = 0;

tcflush( STDIN_FILENO, TCIFLUSH );
tcsetattr( STDIN_FILENO, TCSANOW, &newtio );

g=getchar();

tcsetattr( STDIN_FILENO, TCSANOW, &oldtio );
return 0;
}
 
Old 01-05-2010, 12:21 PM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
VMIN and VTIME work only if you're doing non-canonical I/O. For information on how to set that, see the tcsetattr() man page.

Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
timeout waiting for input during Draining Input HammerHed Linux - Newbie 1 11-01-2008 05:35 AM
DDD and standard input Bassy Programming 0 09-02-2008 06:28 AM
Standard Input in Perl Program eachow Linux - General 2 11-17-2005 12:16 AM
GTK input and timeout joakim12 Programming 1 07-15-2005 03:44 PM
Sendmail: timeout waiting for input from local during Draining Input andrewstr Linux - Software 0 07-14-2004 01:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration