🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
11 messages
11 total messages Started by Hanne B Wed, 08 Nov 2006 10:08
Indy9 - BCB5 - FTP server - access violation errors
#1757
Author: Hanne B
Date: Wed, 08 Nov 2006 10:08
17 lines
1287 bytes
I have problems using Indy9 TIdFTPServer component.

If a client is connected to the FTP server and retriving a huge file, then I 
get EAaccessViolation errors if I want to disconnect the client by the 
following code

if (AThread->Connection->ClosedGracefully == false)
    AThread->Connection->Disconnect()

AThread->StopMode = smTerminate;
AThread->Stop();


How do I avoid such errors ?


Regards Hanne
Re: Indy9 - BCB5 - FTP server - access violation errors
#1755
Author: Hans Galema
Date: Wed, 08 Nov 2006 10:09
8 lines
1138 bytes
Hanne B wrote:

> How do I avoid such errors ?

You forgot to tell which statement causes the AV.
(which line of code?).

Hans.
Re: Indy9 - BCB5 - FTP server - access violation errors
#1759
Author: Hanne B
Date: Wed, 08 Nov 2006 11:05
79 lines
3107 bytes
"Hans Galema" <notused@notused.nl> wrote in message 
news:4551ad3e$1@newsgroups.borland.com...
> Hanne B wrote:
>
>> How do I avoid such errors ?
>
> You forgot to tell which statement causes the AV.
> (which line of code?).
>
> Hans.
>


It doesn't happen in any of my lines but a short time after the code has 
been executed.

I get an exception message box:

Application Error:
Exception EAccesViolation in module FTPServer1.exe at 0000000
Access violation at address 00455B9B in module FTPServer1.exe. Read of 
address 0000000C.

Hanne




Example:

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  IdFTPServer1->Active = true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::IdFTPServer1UserLogin(TIdFTPServerThread *ASender,
      const AnsiString AUsername, const AnsiString APassword,
      bool &AAuthenticated)
{
  AAuthenticated = true;
}
//---------------------------------------------------------------------------
TIdFTPServerThread *AThread = NULL;

void __fastcall TForm1::IdFTPServer1RetrieveFile(
      TIdFTPServerThread *ASender, const AnsiString AFileName,
      TStream *&VStream)
{
  AThread = ASender;

  VStream = new TMemoryStream();
  for (int i = 0; i < 100000; i++)
    VStream->Write("Test", 4);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ButtonDisconnectClick(TObject *Sender)
{
  if (AThread)
  {
    if (AThread->Connection &&
        AThread->Connection->ClosedGracefully == false)
        AThread->Connection->Disconnect();

    AThread->StopMode = smTerminate;
    AThread->Stop();
  }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::IdFTPServer1Disconnect(TIdPeerThread *AThread)
{
  AThread = NULL;
}
//---------------------------------------------------------------------------
Re: Indy9 - BCB5 - FTP server - access violation errors
#1760
Author: Hans Galema
Date: Wed, 08 Nov 2006 11:23
42 lines
1993 bytes
Hanne B wrote:

> It doesn't happen in any of my lines but a short time after the code has 
> been executed.

Are you sure?

> void __fastcall TForm1::ButtonDisconnectClick(TObject *Sender)
> {
>   if (AThread)
>   {
>     if (AThread->Connection &&
>         AThread->Connection->ClosedGracefully == false)
>         AThread->Connection->Disconnect();
> 
>     AThread->StopMode = smTerminate;
>     AThread->Stop();
>   }
> }

I did not try your code yet. You could first try the following:

void __fastcall TForm1::ButtonDisconnectClick(TObject *Sender)
{
   if (AThread)
   {
     if (AThread->Connection &&
         AThread->Connection->ClosedGracefully == false
        )
         AThread->Connection->Disconnect();

     if ( AThread )
	{
     	AThread->StopMode = smTerminate;
     	AThread->Stop();
	}
     else
	ShowMessage ( "AThread gone");
   }
}

Hans.
Re: Indy9 - BCB5 - FTP server - access violation errors
#1761
Author: Hanne B
Date: Wed, 08 Nov 2006 14:51
62 lines
2670 bytes
"Hans Galema" <notused@notused.nl> wrote in message 
news:4551be9b$1@newsgroups.borland.com...
> Hanne B wrote:
>
>> It doesn't happen in any of my lines but a short time after the code has 
>> been executed.
>
> Are you sure?
>
>> void __fastcall TForm1::ButtonDisconnectClick(TObject *Sender)
>> {
>>   if (AThread)
>>   {
>>     if (AThread->Connection &&
>>         AThread->Connection->ClosedGracefully == false)
>>         AThread->Connection->Disconnect();
>>
>>     AThread->StopMode = smTerminate;
>>     AThread->Stop();
>>   }
>> }
>
> I did not try your code yet. You could first try the following:
>
> void __fastcall TForm1::ButtonDisconnectClick(TObject *Sender)
> {
>   if (AThread)
>   {
>     if (AThread->Connection &&
>         AThread->Connection->ClosedGracefully == false
>        )
>         AThread->Connection->Disconnect();
>
>     if ( AThread )
> {
>     AThread->StopMode = smTerminate;
>     AThread->Stop();
> }
>     else
> ShowMessage ( "AThread gone");
>   }
> }
>
> Hans.
>



I have tried your code with ShowMessage("AThread gone")  - it didn't show 
the message (so AThread has not become NULL at that time).

I have put a message box in the bottom of the method - and seen that the 
exception occures before this message is shown.
And it also happens if I remove the part to termintate/stop the Thread.

So it must be the call AThread->Connection->Disconnect()  that cause the 
error - because the stream is still open / used.

How do I disconnect the client if the above cannot be used ?


Hanne
Re: Indy9 - BCB5 - FTP server - access violation errors
#1763
Author: Hans Galema
Date: Wed, 08 Nov 2006 15:12
19 lines
1528 bytes
Hanne B wrote:

> How do I disconnect the client if the above cannot be used ?

Don't know. But you could catch the AV and neglect it.

   try
     {
      AThread->Connection->Disconnect();
     }
   catch ( Exception &Exception )
     {
     // do nothing
     }

(You know to run this outside the IDE? Otrherwise you will still
see the exception).

Hans.
Re: Indy9 - BCB5 - FTP server - access violation errors
#1764
Author: Remy Lebeau (TeamB)
Date: Wed, 08 Nov 2006 19:55
18 lines
1507 bytes
"Hanne B" <hb@aeromark.dk> wrote in message
news:4551ac92@newsgroups.borland.com...

> If a client is connected to the FTP server and retriving a huge file, then
> I get EAaccessViolation errors if I want to disconnect the client by
> the following code

Why are you disconnecting the client manually?  You should not be doing
that.  TIdFTPServer is currently not designed to handle server-side
disconnections of transfers that are in progress.

At the very least, you should be disconnecting the transfer's DataChannel
first, so that it can send an error message back to the FTP client
indicating that the transfer has failed.


Gambit
Re: Indy9 - BCB5 - FTP server - access violation errors
#1767
Author: Hanne B
Date: Thu, 09 Nov 2006 07:50
35 lines
2095 bytes
"Hans Galema" <notused@notused.nl> wrote in message 
news:4551f425$1@newsgroups.borland.com...
> Hanne B wrote:
>
>> How do I disconnect the client if the above cannot be used ?
>
> Don't know. But you could catch the AV and neglect it.
>
>   try
>     {
>      AThread->Connection->Disconnect();
>     }
>   catch ( Exception &Exception )
>     {
>     // do nothing
>     }
>
> (You know to run this outside the IDE? Otrherwise you will still
> see the exception).
>
> Hans.
>


I have tried (try ... catch) but it doesn't help because it is not the 
statement that has the error - it is something that happens in the Indy code 
after the statement is executed.

I don't know exactly what you mean by the sentence "You know to run this 
outside the IDE? Otherwise you will still see the exception" ?
Is it that I should run thg generated program (exe file) instead of use run 
in BCB5 ?

Hanne 
Re: Indy9 - BCB5 - FTP server - access violation errors
#1768
Author: Hanne B
Date: Thu, 09 Nov 2006 08:15
36 lines
2198 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:4552371e$3@newsgroups.borland.com...
>
> "Hanne B" <hb@aeromark.dk> wrote in message
> news:4551ac92@newsgroups.borland.com...
>
>> If a client is connected to the FTP server and retriving a huge file, 
>> then
>> I get EAaccessViolation errors if I want to disconnect the client by
>> the following code
>
> Why are you disconnecting the client manually?  You should not be doing
> that.  TIdFTPServer is currently not designed to handle server-side
> disconnections of transfers that are in progress.
>
> At the very least, you should be disconnecting the transfer's DataChannel
> first, so that it can send an error message back to the FTP client
> indicating that the transfer has failed.
>
>
> Gambit
>
>
>



I have a FTP server where a lot of clients connect and pick up files.
If they are interrupted while they are retrieving files (and I don't get the 
disconnected event for the client), then they will stay "connected" and take 
up memory - if I cannot disconnect them.

What exactly do you want me to do to disconnect the DataChannel first ? and 
how do I send an error message to the FTP client ?

Hanne 
Re: Indy9 - BCB5 - FTP server - access violation errors
#1769
Author: Hans Galema
Date: Thu, 09 Nov 2006 08:47
18 lines
1833 bytes
Hanne B wrote:

>>(You know to run this outside the IDE? Otrherwise you will still
>>see the exception).

> I don't know exactly what you mean by the sentence "You know to run this 
> outside the IDE? Otherwise you will still see the exception" ?

Please do not retype what I said. You already quoted my post. Use that to
reply. Be carefull with the amount you send back. A few lines will do mostly.

> Is it that I should run thg generated program (exe file) instead of use run 
> in BCB5 ?

Yes. You should start your .exe yourself. Not bcb. This is called Inside/Outside
the IDE.

Hans.
Re: Indy9 - BCB5 - FTP server - access violation errors
#1770
Author: Remy Lebeau (TeamB)
Date: Thu, 09 Nov 2006 10:51
34 lines
2482 bytes
"Hanne B" <hb@aeromark.dk> wrote in message
news:4552e3ba$1@newsgroups.borland.com...

> If they are interrupted while they are retrieving files (and I don't get
the
> disconnected event for the client), then they will stay "connected"
> and take up memory

Blocking sockets cannot detect abnormal disconnects in a timely manner.
TIdFTPServer in Indy 9 does not have enough hooks for you to customize the
connection's behavior, such as being able to automate the handling of
reading timouts.  The closest you can get is to set the
CommandHandlersEnabled property to False, then use the OnConnect event to
set the ReadTimeout property on a per-client basis, and then use the
OnExecute event to manually call ReadLn() and check the ReadLnTimedOut
property before then passing the received line to the CommandHandlers for
processing.  If a timeout occurs, you can disconnect the client.

> What exactly do you want me to do to disconnect the DataChannel first ?

TIdFTPServerThread has a DataChannelThread property.  Unfortunately, you do
not have access to the socket that it creates to transfer the data.  You
would have to change Indy's source and then recompile Indy in order to do
that.  Then you can disconnect the socket when needed, which will
effectively abort the transfer.

> how do I send an error message to the FTP client ?

TIdFTPServer automatically does that when the transfer thread fails to
transmit/receive data.


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