[comp.unix.programmer] IPC/Sockets and blocking revisited...THANKS

hoff@en.ecn.purdue.edu (Michael Hoefflinger) (02/17/91)

Just wanted to take a moment to thank all the kind folks that took
a minute to write me about the non-blocking socket question I had.
The solution, courtesy of both Les Hill and Mike "Lakermaniac
(not such a good game agains Boston, eh?)" Sullivan:

   flags = fcntl (socket, F_GETFL, 0);
   fcntl (socket, F_SETFL, flags | FNDELAY);

This was indeed the Right Thing (tm) to do, and the Right Time (tm) to do it.

Since I got such a quick and working response on my last question,
I think I will abuse this living user's manual some more:


-->  Question is, how can I execute a getchar() that will return with
     EOF immediately if the user has not typed anything, or with
     the char as soon as it is typed?  The problem is that getchar
     is buffered I/O, and apparently _fillbuf() doesn't exit back to
     getchar until a carriage return is executed.


Appreciate your time.  And thanks again...


Michael Hoefflinger
EE, Purdue University (hoff@ecn.purdue.edu, uxg@fugue.cc.purdue.edu)
"I'm not really a EE grad student, but I played one on TV."

jik@athena.mit.edu (Jonathan I. Kamens) (02/18/91)

In article <1991Feb16.225731.20445@en.ecn.purdue.edu>, hoff@en.ecn.purdue.edu (Michael Hoefflinger) writes:
|> Since I got such a quick and working response on my last question,
|> I think I will abuse this living user's manual some more:

  "Abuse" is the right word.  (1/2 :-)

|> -->  Question is, how can I execute a getchar() that will return with
|>      EOF immediately if the user has not typed anything, or with
|>      the char as soon as it is typed?  The problem is that getchar
|>      is buffered I/O, and apparently _fillbuf() doesn't exit back to
|>      getchar until a carriage return is executed.

  This is question 5 on the "Frequently Asked Questions about Unix - with
Answers" posting to comp.unix.questions.  If you can't get a hold of it at
your site, E-mail me and I'll send it to you.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710