Discussion:
about TFileStream
(too old to reply)
haozhe_han
2008-01-07 05:37:26 UTC
Permalink
How shall I do that overriding the virtual
Read() and Write() methods from TFileStream to get the rage of speed when
TIdFTPServer storefiles.
thanks!
Asger Joergensen
2008-01-07 09:10:49 UTC
Permalink
Hi haozhe_han
Post by haozhe_han
How shall I do that overriding the virtual
Read() and Write() methods from TFileStream to get the rage of speed when
TIdFTPServer storefiles.
Maybe it is just me, but I don't understand what it is that You
are asking, could You explaine a little bit more ?

Maybe show a piece of code to illustrate Your problem.

Kind regards
Asger
haozhe_han
2008-01-07 11:30:30 UTC
Permalink
I use TIdFTPServer to get files from remote,and i want get the rage of speed
when TIdFTPServer storefiles.
but TIdFTPServer does not provide access to any notifications for that. So I
want overriding the virtual
Read() and Write() methods to get I needed.
class TMyFileStream : public TFileStream
{
typedef TFileStream inherited;
protected:
public:
__fastcall TMyFileStream(const AnsiString AFileName, Word Mode);/* overload
*/;
int __fastcall Write(const void *Buffer, int Count);
};
int __fastcall TMyFileStream::Write(const void *Buffer, int Count)
{
//i can get send data count in this position,but i don't know which time
send data end.
THandleStream::Write(Buffer,Count);
return 0;
}
sorry,my english is very poor.
Post by Asger Joergensen
Hi haozhe_han
Post by haozhe_han
How shall I do that overriding the virtual
Read() and Write() methods from TFileStream to get the rage of speed when
TIdFTPServer storefiles.
Maybe it is just me, but I don't understand what it is that You
are asking, could You explaine a little bit more ?
Maybe show a piece of code to illustrate Your problem.
Kind regards
Asger
Asger Joergensen
2008-01-07 12:44:19 UTC
Permalink
Hi haozhe_han
Post by haozhe_han
I use TIdFTPServer to get files from remote,and i want get the rage of speed
when TIdFTPServer storefiles.
but TIdFTPServer does not provide access to any notifications for that. So I
want overriding the virtual
Read() and Write() methods to get I needed.
class TMyFileStream : public TFileStream
{
typedef TFileStream inherited;
__fastcall TMyFileStream(const AnsiString AFileName, Word Mode);/* overload
*/;
int __fastcall Write(const void *Buffer, int Count);
};
int __fastcall TMyFileStream::Write(const void *Buffer, int Count)
{
//i can get send data count in this position,but i don't know which time
send data end.
THandleStream::Write(Buffer,Count);
return 0;
}
sorry,my english is very poor.
Ohh, Your english is fine, it is just better to some use extra words,
that way it is easier to make a good gues if there something
that I don't understand.

I have have not used Indy much, but here is an idea:

DWORD DownloadStartTime = timeGetTime();
int DownloadedBytes = 0;

int __fastcall TMyFileStream::Write(const void *Buffer, int Count)
{
DWORD CurrentTime = timeGetTime();
DWORD TimeSpent = CurrentTime - DownloadStartTime;
DownloadedBytes += Count;
// do some calculation to get the rate
return THandleStream::Write(Buffer,Count);
}

timeGetTime(); returns number of milliseconds since the computer
was last rebooted, but You can see all about that in the Win32 help.

Kind regards
Asger
Remy Lebeau (TeamB)
2008-01-07 18:10:24 UTC
Permalink
Post by haozhe_han
How shall I do that overriding the virtual
Read() and Write() methods from TFileStream to
get the rage of speed when TIdFTPServer storefiles.
Read() is not called when receiving a file from the client.

As for Write(), you will know how much data is being written each time
Write() is called. It is passed as an input parameter. Simply add that
value to a running counter in order to know how many bytes have been written
in total. As for calculating the speed, you need to keep track of the time
that elapses between each call to Write(). That is the time it took
TIdFTPServer to read a block of data from the socket connection before then
passing that block to Write(). Since you will know how long the block took
to read, and how large the block is, the current speed of the connection is
a simple division of those two values.


Gambit

Loading...