c - How to terminate read() when EOF is not encountered? -


i building client/server model using sockets, using named pipes, mkfifo().

a client writes output name pipe, , read input in server using:

while ((n = read(fd_in, &newchar, 1)) == 1) { /* ... */ } 

i reading 1 character @ time, until encounter 2 characters: <'cr'><'lf'>. make code in such way if client not terminate <'cr'><'lf'> after time maybe, can discard , proceed client, otherwise next client have wait, maybe infinitely.

is there way please terminate execution of read()? if has not returned in 2 seconds, interrupt read , discard read characters, , start reading again please?

thank help,

jary

try passing o_nonblock flag when open read-end of fifo. should change behavior read returns right away if number of requested characters not in pipe.


Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -