cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Piping Telnet

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 23 Jun 2008 10:53:30 -0700

On Mon, Jun 23, 2008 at 10:54:29AM -0400, Will Dean wrote:
> I am trying to use libcurl to handle the telnet session when polling ARP tables
> off a device. Since libcurl doesn't have any sort of callback functions for
> telnet I had to spawn it in a child and redirect both stdin and stdout.
>
> I have no trouble writing to the libcurl/the session but when attempting to
> read() I get blocking of some sort if I try to write post read().
>
> write()
> write()
> ....
> read()
>
> will work.
>
> write()
> write()
> ....
> read()
> write()
>
> will block.
>
> write()
> write()
> ....
> read()
> read()
>
> will block (I think this is normal as there is zero).
>
> I have tried my code without libcurl in the child and it doesn't seem to
> happen. Any thoughts? Could libcurl be buffering the data?
>
> I've posted the code here - http://willscorner.net/tmp_email_attachments/
> pipetest.c

I spotted a number of problems in the code, but it's not clear that they
should be causing this problem. The comments in the code don't quite match
the code, and it's not clear quite how the trace above relates.

For one, fflush() doesn't work on file descriptors but on FILE pointers.
There's no need to do any flushing when you're dealing with file
descriptors directly. Also, when the code prints the contents of the
read buffer, it assumes that the data was read correctly, and that the
data is NUL-terminated, both of which could be false. Finally, you could
avoid a lot of unnecessary dup'ing of file descriptors by performing
the dup2 calls in the child instead of the parent.

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2008-06-23