🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #1195

Re: WSAGetLastError return always 6

#1195
From: Remy Lebeau (TeamB)
Date: Tue, 27 Feb 2007 18:04
60 lines
3090 bytes
"Eduardo Jauch" <eduardo.jauch@gmail.com> wrote in message
news:45e4284e$1@newsgroups.borland.com...

> It comes a first part, that contains the header and an hexa that say
> the number of bytes to read. Then on the next loop, I receive a new
> chunk with a new hexa that says the length of the new chunk, a
> third time this occour and on the fourth, the signal that the send
of
> chunked data ends is present "0\r\n\r\n". So I quit the loop because
> there not more data to read...

That is how chunked transfers work, but that is not how your earlier
code was actually reading chunked data.  You were not reading the
chunked sizes at all.  You were reading the incoming data in arbitrary
byte sizes into a buffer without any care whatsoever to the actual
content of the transfer, and then trying to verify the last chunk
only.  A proper transfer should be performing the following sequence
instead:

    send the request
    read a single line
    verify the response code in the line
    loop
        read a line
        if line is empty then break
        store the line into a header list
    end
    if list contains 'Transfer-Encoding: chunked' header then
    begin
        loop
            read a line
            extract chunk size from the line
            if chunk size is 0 then break
            read number of bytes specified
            store bytes into buffer
            read an empty line
        end
        read an empty line
    end
    else if list contains 'Content-Length' header then
    begin
        read number of bytes specified
        store bytes into buffer
    end
    else
    begin
        loop
            read as many bytes as are currently available
            if disconnected then break
            store bytes into buffer
        end
    end

> And what I must to do?

See above.


Gambit
Technical Details
Message-ID: <45e47101$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!newsfeed.datemas.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!feeder08.uucp.at!feeder10.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail
References: <45e24baa@newsgroups.borland.com> <45e31e54$1@newsgroups.borland.com> <45e34585$1@newsgroups.borland.com> <45e358b3$1@newsgroups.borland.com> <45e380bc@newsgroups.borland.com> <45e38fa2$1@newsgroups.borland.com> <45e3a6cf@newsgroups.borland.com> <45e3d748@newsgroups.borland.com> <45e4284e$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,ead06e5a7c488245
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <45e24baa@newsgroups.borland.com> <45e31e54$1@newsgroups.borland.com> <45e34585$1@newsgroups.borland.com> <45e358b3$1@newsgroups.borland.com> <45e380bc@newsgroups.borland.com> <45e38fa2$1@newsgroups.borland.com> <45e3a6cf@newsgroups.borland.com> <45e3d748@newsgroups.borland.com> <45e4284e$1@newsgroups.borland.com>
Subject: Re: WSAGetLastError return always 6
Date: Tue, 27 Feb 2007 10:04:39 -0800
Lines: 62
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.34.171
Message-ID: <45e47101$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1172599041 75.83.34.171 (27 Feb 2007 09:57:21 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!newsfeed.datemas.de!news.albasani.net!feeder06.uucp-net.de!reader.uucp.at!feeder08.uucp.at!feeder10.uucp.at!news.uucp.at!newsgroups.borland.com!not-for-mail