Nonblocking stdin on telnet

Ian Caddy ianc at goanna.iinet.net.au
Wed Jul 7 01:23:46 UTC 2010


On 7/07/2010 7:13 AM, Andrei Chichak wrote:
> I am using 4.9.4 on a Coldfire 5282.
>
> I need to do a non-blocking read on stdin in my telnet process. I have
> done the following, but the getchar blocks.


We are using an older version of RTEMS with a custom telnet, pty driver 
and shell, but when the telnet accepts the socket connection, you also 
need to setup a timeout on the connected socket.  We use this piece of 
code to setup a timeout for the character read.


> /**
>    Set the length of time socket reads take.
> **/
> int SetSocketTimeout(int connectSock, int milliseconds)
> {
>    struct timeval tv;
>
>    tv.tv_sec = milliseconds / 1000 ;
>    tv.tv_usec = ( milliseconds % 1000) * 1000  ;
>
>    return setsockopt(connectSock, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
> }

We currently set this to 500ms.

regards,

Ian Caddy

-- 
Ian Caddy
Goanna Technologies Pty Ltd
+61 8 9444 2634





More information about the users mailing list