🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages Started by Dennis Cote Thu, 20 Mar 2008 16:25
replacing ReadBuffer in Indy10
#289
Author: Dennis Cote
Date: Thu, 20 Mar 2008 16:25
30 lines
1518 bytes
I am porting an application from Indy 9 to Indy 10.

In Indy 9 I had code to read data into a dynamically allocated char 
buffer using ReadBuffer.

     char* Buffer;
     int Length;

     ...
     ReadBuffer(Buffer, Length);
     ...

I have found that I need to do the following instead in Indy 10.

     char* Buffer;
     int Length;

     ...
     TIdBytes byteBuf;
     byteBuf.Length = Length;
     IOHandler->ReadBytes(byteBuf, Length);
     BytesToRaw(byteBuf, Buffer, Length);
     ...

My question is, is there a way to get Indy 10 to read directly into the 
existing char buffer? I would like to avoid the extra allocations and 
the buffer copy if possible.

TIA
Dennis Cote
Re: replacing ReadBuffer in Indy10
#290
Author: Remy Lebeau (TeamB)
Date: Thu, 20 Mar 2008 16:43
44 lines
2190 bytes
"Dennis Cote" <denniscote@gmail.com> wrote in message 
news:47e28ff7$1@newsgroups.borland.com...

> is there a way to get Indy 10 to read directly into the existing char 
> buffer?

Indy does not support direct memory buffers anymore, by design.  One thing 
you can do, though, is derive a new class from TCustomMemoryStream that uses 
the char* buffer as its underlying memory block.  You could then use 
ReadStream() to receive the data directly into the buffer.  For example:

    class TBufferStream : public TCustomMemoryStream
    {
    public:
        __fastcall TBufferStream(void *Buffer, int Length)
            : TCustomMemoryStream()
        {
            SetPointer(Buffer, Length);
        }

        int __fastcall Write(void *Buffer, int Count)
        {
            Count = min(Count, Size-Position);
            if( Count > 0 )
            {
                memcpy(((LPBYTE)Memory) + Position, Buffer, Count);
                Seek(Count, soFromCurrent);
                return Count;
            }
            return 0;
        }
    };


    char* Buffer;
    int Length;
    ...
    TBufferStream *strm = new TBufferStream(Buffer, Length);
    IOHandler->ReadStream(strm, Length);
    delete strm;


Gambit 
Re: replacing ReadBuffer in Indy10
#356
Author: Colin B Maharaj
Date: Sun, 23 Mar 2008 00:19
50 lines
2272 bytes
What you can also probably do, as I did using indy 9
(sorry I do not use indy 10 yet) is get the socket handle
similar to this...
int isocket = AThread->Connection->Socket->Binding->Handle;
and do this....
unsigned char * s = new unsigned char [8200];
int r = recv(isocket, s, 8192, 0);
if r == 0 then do this.....
AThread->Connection->Disconnect();
and terminate else if
r == -1
this is an error so go look up WSAGetLastError();
and if r > 0 then you got data in s and r is the
length!





Dennis Cote wrote:
> I am porting an application from Indy 9 to Indy 10.
> 
> In Indy 9 I had code to read data into a dynamically allocated char 
> buffer using ReadBuffer.
> 
>     char* Buffer;
>     int Length;
> 
>     ...
>     ReadBuffer(Buffer, Length);
>     ...
> 
> I have found that I need to do the following instead in Indy 10.
> 
>     char* Buffer;
>     int Length;
> 
>     ...
>     TIdBytes byteBuf;
>     byteBuf.Length = Length;
>     IOHandler->ReadBytes(byteBuf, Length);
>     BytesToRaw(byteBuf, Buffer, Length);
>     ...
> 
> My question is, is there a way to get Indy 10 to read directly into the 
> existing char buffer? I would like to avoid the extra allocations and 
> the buffer copy if possible.
> 
> TIA
> Dennis Cote
Re: replacing ReadBuffer in Indy10
#359
Author: Remy Lebeau (TeamB)
Date: Mon, 24 Mar 2008 16:33
13 lines
1345 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message 
news:47e5a1fb$1@newsgroups.borland.com...

> What you can also probably do, as I did using indy 9
> (sorry I do not use indy 10 yet) is get the socket handle
> similar to this...

You shouldn't be doing that.  That completely bypasses Indy's ability to 
manage and track the socket state.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads