🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TWinSocketStream Read in BYTE buffer

#2880
From: Remy Lebeau (TeamB)
Date: Mon, 02 Jan 2006 23:07
36 lines
2831 bytes
"newsgroups.borland.com" <mauriceanderson@hotmail.com> wrote in message 
news:43b5a868$1@newsgroups.borland.com...

> Oh, I interpreted it the way an int variable is incremented by '+=',
> as in int a; a += 1;  Again, my mis-understanding.

A pointer is an integer as far as the CPU is concerned, just one whose value 
is a memory address.  Any mathematical operation can be performed on a 
pointer since it is just a number like any other.

> Also, I discovered an error in the code that caused files sent over
> to the server to be pre-padded with 'blank' bytes equal to the
> original file/data size over.  So a file that is 192 Bytes on the client
> become 384 Bytes on the server.  The error is where you pre-initialized
> the size of FS to the size of the data sent over.

I did not realize it at the time, but setting the Size of a TFileStream 
changes the Position to the new Size as well.  That is a bug in the VCL, in 
my opinion.  Setting the Size should no change the Position.  You will have 
to set the Position back to 0 after setting the Size before then writing the 
data to the file.

    FS->Size = size;
    FS->Position = 0; // <-- add this

> Once I commented out the line, it worked perfectly!!

It is good to set the Size beforehand when you know the amount of data being 
written (which you do).  It allows the OS to optimize the writing to the 
harddrive since it will not have to hunt around for available space on each 
call to TFileStream::Write() - all of the needed space is pre-allocated 
ahead of time.


Gambit 
Technical Details
Message-ID: <43b9b1b0$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <43ac3d34$1@newsgroups.borland.com> <43ac6028$1@newsgroups.borland.com> <43acc4c5$1@newsgroups.borland.com> <43ae5b51$1@newsgroups.borland.com> <43aeebe1$1@newsgroups.borland.com> <43aef70e$1@newsgroups.borland.com> <43af06d7$1@newsgroups.borland.com> <43b252fa$1@newsgroups.borland.com> <43b43a5a$1@newsgroups.borland.com> <43b45550$1@newsgroups.borland.com> <43b5a868$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,74cdc31c66b3abd9
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: <43ac3d34$1@newsgroups.borland.com> <43ac6028$1@newsgroups.borland.com> <43acc4c5$1@newsgroups.borland.com> <43ae5b51$1@newsgroups.borland.com> <43aeebe1$1@newsgroups.borland.com> <43aef70e$1@newsgroups.borland.com> <43af06d7$1@newsgroups.borland.com> <43b252fa$1@newsgroups.borland.com> <43b43a5a$1@newsgroups.borland.com> <43b45550$1@newsgroups.borland.com> <43b5a868$1@newsgroups.borland.com>
Subject: Re: TWinSocketStream Read in BYTE buffer
Date: Mon, 2 Jan 2006 15:07:23 -0800
Lines: 38
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 68.69.17.41
Message-ID: <43b9b1b0$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1136243120 68.69.17.41 (2 Jan 2006 15:05:20 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail