|
Hi!, i have a "server-like" application: i use select to accept and recieve data from Sockets. I want to Add a menu to this app something like "pick an option" thing, but it has to show data according to data recieved from Sockets..
I found a way to do it with Fork, i mean, First i fork;in the Child i do all the menu stuff and in the "else" part (the parent part) i have the rest (the while(1) with a select inside). But i dont like this because, i don't like forking just for a menu! and i have to create a socket to communicate with the parent.
i was thinking.. isn't it possible to tell the select to read and show the stdin, after all, it's a FD. I tried this but i couldn't get it to work correctly, i ran into trouble like "recv cant read from a Non-socket fd" "i read the stdin with "read" but i reads char by char -i guess- and it remains "ready" so select, keeps selecting stdin forever.
so, i don't know which is THE way to do it correcly if there is such a thing.
Thanks.
|
|
0
|
|
|
Reply
|
ifmusic
|
5/16/2006 5:47:12 PM
|
Header
|
Report
as Spam
|
|
ifmusic@gmail.com wrote: > Hi!, i have a "server-like" application: > i use select to accept and recieve data from Sockets. > I want to Add a menu to this app something like "pick an option" thing, > but it has to show data according to data recieved from Sockets.. > > I found a way to do it with Fork, i mean, First i fork;in the Child i > do all the menu stuff and in the "else" part (the parent part) i have > the rest (the while(1) with a select inside). But i dont like this > because, i don't like forking just for a menu! and i have to create a > socket to communicate with the parent. > > i was thinking.. isn't it possible to tell the select to read and show > the stdin, after all, it's a FD. > I tried this but i couldn't get it to work correctly, i ran into > trouble like "recv cant read from a Non-socket fd" "i read the stdin > with "read" but i reads char by char -i guess- and it remains "ready" > so select, keeps selecting stdin forever. > > so, i don't know which is THE way to do it correcly if there is such a > thing. > > Thanks.
This shouldn't be too much of a problem. Heres a bit of code from something I wrote which could handle that if fdin was set to stdin.
struct timeval tv = {0,0}; FD_ZERO(&fdset); FD_SET(fdin,&fdset); if(select(fdin+1,&fdset,0,0,&tv)>0) { if(FD_ISSET(fdin,&fdset)) { i = read(fdin,stdinbuf,STDINBUFSIZE); if(i>0) //successful read len += i; else //end of stream or error } } }
If you can't get it working post a bit of code.
|
|
0
|
|
|
Reply
|
noogie
|
5/16/2006 10:47:39 PM
|
Header
|
Report
as Spam
|
|
2 Replies
470 Views
Similiar Articles: readline() with select() on STDIN - comp.unix.programmer ...Hello, I have a program that needs to monitor different sockets for data available for reading. I use select for this. I would like to be able to ty... create tar from stdin - comp.unix.admin... file and need to get it to a tar.gz. Looks like tar cannot read from stdin ... select: Bad file number - comp.unix.solaris create tar from stdin - comp.unix.admin select ... Default buffers on pipes - comp.unix.programmerSo I have one program writing to stdout and another reading on stdin (using fwrite() and ... ... You might want to use SIGALRM or select()/poll() to implement I/O with timeouts. select() and file descriptor usage troubles - comp.unix.programmer ...experiencing difficulties with the select() function. ... descriptor (obtained with fileno(stdin)) to an fd_set. ... Reading Directory hirenshah.05 1 68 select: Bad file number - comp.unix.solariscreate tar from stdin - comp.unix.admin select: Bad file number - comp.unix.solaris ... suddenly goes bad - comp.unix.programmer ..... one of read(), write() or select ... Remote Ufsdump - comp.unix.adminselect: Bad file number debug1: Transferred: stdin 0, stdout 0, stderr 25 bytes in 0.2 seconds ... > debug1: Reading configuration data /etc/ssh/ssh_config > debug1 ... eclipse debugging and standard input - comp.lang.java.programmer ...... cat file.txt |").In order to provide data to standard input, just select the ... java - Eclipse reading stdin (System.in) from a file - Stack Overflow On the "common" tab ... [BEA][Oracle JDBC Driver]No more data available to read. - comp ...readline() with select() on STDIN - comp.unix.programmer ... [BEA][Oracle JDBC Driver]No more data available to read. - comp ... readline() with select() on STDIN - comp ... popen() and blocking - comp.unix.programmer> he's just reading from stdin. Hi Simon, that one more reason to let the child-side untouched ... (2) a poll() or select() loop for non-blocking I/O, or (3) a special protocol ... Putting data in STDIN - comp.lang.rexx... but expects the body of the email to be on STDIN. ... how to UPDATE based on a SELECT - comp.databases ... the same with the command to simply read the data back to stdin ... using select to read STDIN? - C / C++using select to read STDIN?. C / C++ Forums on Bytes. ... Hi!, i have a "server-like" application: i use select to accept and recieve data from Sockets. c - using select to read from socket and stdin - Stack OverflowI'm writing a ncurses based chat program. At first, I wrote just networking stuff (without ncurses) and everything worked fine, but after adding graphics I can't get ... How to work with: select(), stdin ... ? - Dev ShedHow to work with: select(), stdin ... ?- C Programming. Visit Dev Shed to discuss How ... Well if you don't actually read stdin as well, then the condition "there's data ... How to write a program to read stdin or command line?Comment on How to write a program to read stdin or command line? Re: How to write a program to read stdin or command line? by ikegami (Pope) on Oct 02, 2007 at 15:02 UTC reading from stdin - C Boardhello I can't figure out how to make a program which won't get paused reading from the stdin. ... fd_set fdset; FD_ZERO(fdset); FD_SET(fno, fdset); return select ... 5/18/2012 10:01:57 AM
|