cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: libcurl not sending QUIT to terminate control connection

From: Joe Halpin <j.p.h_at_comcast.net>
Date: Sun, 18 Jan 2004 18:02:41 -0600

Daniel Stenberg wrote:
> On Sun, 18 Jan 2004, Joe Halpin wrote:
>
>
>>I added the following function
>>
>>void Curl_ftp_quit(struct connectdata *conn)
>>{
>> int nread;
>> int ftpcode;
>>
>> (void) Curl_ftpsendf(conn, "%s", "QUIT");
>> (void) Curl_GetFTPResponse(&nread, conn, &ftpcode);
>>}
>
>
> Just note that having the (void)s there is not very nice code. Actually caring
> about errors is better.

Normally I do. However, the only error I can see that would occur is for
the server to have closed its end of the connection (for example,
crashing in the middle of a send). I had thought that Curl_read() would
detect that, but looking at it again I see that it doesn't return a
value of 0, so there isn't any way of telling that the server has
dropped the connection. I'll have to think about that a bit more.

>>And called it like this from Curl_disconnect()
>>
>> if(-1 != conn->sock[FIRSTSOCKET]) {
>> /*
>> * If this is an ftp connection, then FIRSTSOCKET is the control
>> * connection. Send a QUIT message and get any response back
>> * before actually closing the connection.
>> */
>> if(PROT_FTP == conn->protocol)
>> Curl_ftp_quit(conn);
>>
>> sclose(conn->sock[FIRSTSOCKET]);
>> }
>>
>>It crashes in Curl_GETFTPResponse at line 296
>>
>> memcpy(ptr, ftp->cache, (int)ftp->cache_size);
>>
>>According to GDB, ftp->cache is an invalid pointer here.
>
>
> FTP-specific disconnect code should be written in the Curl_ftp_disconnect()
> function (which is called from the Curl_disconnect()) function.
>
> My guess is that you called Curl_ftp_quit() after Curl_ftp_disconnect() is
> called, and then the ftp struct is cleaned up already!

How would I tell in Curl_ftp_disconnect() whether it was the control or
data connection that was being closed? That's been the hardest thing for
me to figure out, and is why I put it where I did. Currently nothing is
actually disconnected in Curl_ftp_disconnect() so it's hard to make the
distinction there, while it seems easy in Curl_disconnect().

I'm not very familiar with the library though. I suspect you're correct
about calling Curl_ftp_quit() at the wrong point. Would it be ok for me
to add a parameter to Curl_ftp_disconnect() which indicates whether or
not an ftp control connection is being closed? Then I could know when to
call Curl_ftp_quit().

Incidentally, I tried running this with the memory debug option on but
got no output file. Is there any way to build this to use Electric Fence?

Thanks

Joe

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
Received on 2004-01-19