socket io problem

Ian Caddy ianc at goanna.iinet.net.au
Wed Jan 30 01:05:08 UTC 2008


Hi Chris,


CWolfe at motioncontrol.org wrote:
> Hi all,
> I'm having a problem using sockets, and I hope someone might know what i'm doing wrong.
> In a previous email, I mentioned i'm trying to create a telnet server which directly manipulates 
> the rs-232 buffers (as opposed to using ptys which wouldn't be compatible with our 
> application.) I can read and write to and from the socket, but only in a blocking way, which 
> doesn't fit our needs. I've tried to register handlers for the sopcket, but they never get called. I 
> have modeled my socket initialization on the telnetd.c and also GoAhead's initialization code.
> Could someone possibly explain how i can set up a telnet socket which is non-blocking at 
> minimum, but even better, one that actually calls the handlers on reception/transmission?
> I assume it's something small that I'm missing, but nothing i've tried has worked in triggering 
> execution of the  socketHandler function. Thank you for your time.

We use telnet in our applications, but we setup a timeout on the receive 
of 500ms.  I don't know how to make the socket truly non-blocking, but 
one option would be to setup the receive timeout to only 1 or 2 ms. 
Here is the code snippet if interested:

static int SetSocketTimeout(int connectSocket, int milliseconds)
{
    struct timeval tv;

       tv.tv_sec = milliseconds / 1000 ;
       tv.tv_usec = ( milliseconds % 1000) * 1000  ;

    return setsockopt (connectSocket, SOL_SOCKET, SO_RCVTIMEO, (char 
*)&tv, sizeof tv);
}

I had a quick look at the wakeup functionality as I was curious and it 
seems to look OK from a quick code walk through.  If no-one has any 
better suggestions than mine, maybe you could post your code example of 
how you set it up and we could look at it?

Hope this helps.

regards,

Ian Caddy


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




More information about the users mailing list