Board index » cppbuilder » about TFileStream
haozhe_han
![]() CBuilder Developer |
haozhe_han
![]() CBuilder Developer |
about TFileStream2008-01-07 01:37:26 PM cppbuilder71 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
![]() CBuilder Developer |
2008-01-07 05:10:49 PM
Re:about TFileStream
Hi haozhe_han
haozhe_han says: QuoteHow shall I do that overriding the virtual Maybe show a piece of code to illustrate Your problem. Kind regards Asger |
haozhe_han
![]() CBuilder Developer |
2008-01-07 07:30:30 PM
Re:about TFileStream
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. "Asger Joergensen" < XXXX@XXXXX.COM >写入消息新闻: XXXX@XXXXX.COM ... Quote
{smallsort} |
Asger Joergensen
![]() CBuilder Developer |
2008-01-07 08:44:19 PM
Re:about TFileStream
Hi haozhe_han
haozhe_han says: QuoteI use TIdFTPServer to get files from remote,and i want get the rage of speed 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)
![]() CBuilder Developer |
2008-01-08 02:10:24 AM
Re:about TFileStream
"haozhe_han" < XXXX@XXXXX.COM >wrote in message
QuoteHow shall I do that overriding the virtual 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 |