Recent

Author Topic: Synapse abort timeout  (Read 3212 times)

rvk

  • Hero Member
  • *****
  • Posts: 4171
Re: Synapse abort timeout
« Reply #60 on: June 04, 2020, 01:36:01 pm »
And how can I create hook?
Just by adding this line.
Code: Pascal  [Select][+][-]
  1. FileConnection := TTCPBlockSocket.Create;
  2. FileConnection.OnMonitor := MyMonitorHook;

and
Code: Pascal  [Select][+][-]
  1. type
  2.   TCustomThread = class(TThread)
  3.     //...
  4.   public
  5.     //...
  6.     procedure MyMonitorHook(Sender: TObject; Writing: Boolean; const Buffer: TMemory; Len: Integer);
  7.     //...
  8.   end;
  9.  
  10. procedure MyMonitorHook(Sender: TObject; Writing: Boolean; const Buffer: TMemory; Len: Integer);
  11. begin
  12.   Synchronize(@ShowProgress);
  13. end;

BTW, This could slow down the sending process because for every buffer read and write the syncrhonize is executed.
If that is really the case (slowdown) you could build in a counter to only execute the Synchronize in the MonitorHook about 1 time out of a 100 or so (or other value). But first try it like this.
« Last Edit: June 04, 2020, 01:37:49 pm by rvk »

TRon

  • Sr. Member
  • ****
  • Posts: 288
Re: Synapse abort timeout
« Reply #61 on: June 04, 2020, 01:40:20 pm »
@rvk
Glad i could be of help  :).

On that subject...  :D
Quote
    {:This event is good for calling your code during long socket operations.
      (Example, for refresing UI if class in not called within the thread.)
      Rate of heartbeats can be modified by @link(HeartbeatRate) property.}
    property OnHeartbeat: THookHeartbeat read FOnHeartbeat write FOnHeartbeat;
and
Quote

 {:This procedural type is used for hook OnHeartbeat. By this hook you can
   call your code repeately during long socket operations.
   You must enable heartbeats by @Link(HeartbeatRate) property!}
  THookHeartbeat = procedure(Sender: TObject) of object;
If you do not require the parameters that the monitor hook is providing... ?

rvk

  • Hero Member
  • *****
  • Posts: 4171
Re: Synapse abort timeout
« Reply #62 on: June 04, 2020, 01:47:08 pm »
On that subject...  :D
Quote
    {:This event is good for calling your code during long socket operations.
      (Example, for refresing UI if class in not called within the thread.)
      Rate of heartbeats can be modified by @link(HeartbeatRate) property.}
    property OnHeartbeat: THookHeartbeat read FOnHeartbeat write FOnHeartbeat;
If you do not require the parameters that the monitor hook is providing... ?
Ah, yes. That is also a possibility.
You would need to provide a specific HeartbeatRate because OnHeartbeat could be executed a lot of times if you don't provide it.

OnStatus, OnMonitor and OnHeartbeat are all executed differently and also a different number of times.
So it would take some investigating which one would be best for what purpose.

Jake012345

  • Full Member
  • ***
  • Posts: 248
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Synapse abort timeout
« Reply #63 on: June 04, 2020, 01:48:37 pm »
unit1.pas(69,78) Error: Identifier not found "TMemory"
Check my ProjectShare site and share your content: FPCShare

rvk

  • Hero Member
  • *****
  • Posts: 4171
Re: Synapse abort timeout
« Reply #64 on: June 04, 2020, 01:49:22 pm »
unit1.pas(69,78) Error: Identifier not found "TMemory"
Code?

Jake012345

  • Full Member
  • ***
  • Posts: 248
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Synapse abort timeout
« Reply #65 on: June 04, 2020, 01:50:59 pm »
Code.
Check my ProjectShare site and share your content: FPCShare

rvk

  • Hero Member
  • *****
  • Posts: 4171
Re: Synapse abort timeout
« Reply #66 on: June 04, 2020, 01:53:40 pm »
Code.
You can change TMemory to pointer. And add the TCustomThread before the hookprocedure.

Code: Pascal  [Select][+][-]
  1. FileConnection := TTCPBlockSocket.Create;
  2. FileConnection.OnMonitor := @MyMonitorHook; // don't forget the @

Code: Pascal  [Select][+][-]
  1. type
  2.   TCustomThread = class(TThread)
  3.     //...
  4.   public
  5.     //...
  6.     procedure MyMonitorHook(Sender: TObject; Writing: Boolean; const Buffer: pointer; Len: Integer);
  7.     //...
  8.   end;
  9.  
  10. procedure TCustomThread.MyMonitorHook(Sender: TObject; Writing: Boolean; const Buffer: pointer; Len: Integer);
  11. begin
  12.   Synchronize(@ShowProgress);
  13. end;

TRon

  • Sr. Member
  • ****
  • Posts: 288
Re: Synapse abort timeout
« Reply #67 on: June 04, 2020, 01:56:36 pm »
unit1.pas(69,78) Error: Identifier not found "TMemory"
Besides solution given by rvk, you can add unit synsock to your uses clause, it is defined there.

TRon

  • Sr. Member
  • ****
  • Posts: 288
Re: Synapse abort timeout
« Reply #68 on: June 04, 2020, 01:59:51 pm »
Ah, yes. That is also a possibility.
You would need to provide a specific HeartbeatRate because OnHeartbeat could be executed a lot of times if you don't provide it.

OnStatus, OnMonitor and OnHeartbeat are all executed differently and also a different number of times.
So it would take some investigating which one would be best for what purpose.
I suspected as such, that is why i was more or less guessing (hoping for a more definite answer from your experience) as i have no idea what would be best for this situation.

I am still busy on other things before i am able to return more seriously to synapse. When i do, i'll try to make some use cases to see how some of these events turn out.

Thank you for your input.

Jake012345

  • Full Member
  • ***
  • Posts: 248
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Synapse abort timeout
« Reply #69 on: June 04, 2020, 02:20:25 pm »
Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2.  
What means the parameters?

EDIT:

That's worked and really got slow.
« Last Edit: June 04, 2020, 02:22:27 pm by Jake012345 »
Check my ProjectShare site and share your content: FPCShare

rvk

  • Hero Member
  • *****
  • Posts: 4171
Re: Synapse abort timeout
« Reply #70 on: June 04, 2020, 02:21:43 pm »
Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2.  
What means the parameters?
Writing is if you are sending or receiving.
Buffer is the pointer to the buffer about to be transfered.
Len is the length of that buffer.

All parameters are really not needed if you just want to know the end (Stream.position) of your stream to show a progressbar.

Jake012345

  • Full Member
  • ***
  • Posts: 248
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Synapse abort timeout
« Reply #71 on: June 04, 2020, 09:03:57 pm »
Okay. That's worked.
But
Quote
If that is really the case (slowdown) you could build in a counter to only execute the Synchronize in the MonitorHook about 1 time out of a 100 or so (or other value). But first try it like this.

I can't do that. My technic doesn't work.
Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2.  var i:integer=0;
  3. begin
  4.   i:=i+1;
  5.   if i=ProgressRefreshRate then begin
  6.   Synchronize(@ShowProgress);
  7.   i:=0;
  8.   end;
  9. end;
  10.  
Check my ProjectShare site and share your content: FPCShare

rvk

  • Hero Member
  • *****
  • Posts: 4171
Re: Synapse abort timeout
« Reply #72 on: June 04, 2020, 09:08:19 pm »
I can't do that. My technic doesn't work.
Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2.  var i:integer=0;
  3. begin
  4.   i:=i+1;
  5.   if i=ProgressRefreshRate then begin
  6.   Synchronize(@ShowProgress);
  7.   i:=0;
  8.   end;
  9. end;
  10.  
You have i as local variable and it gets initialized to 0 each time the procedure is run.

Make it a class variable, setting it to 0 at the top of execute, and it should work.

lucamar

  • Hero Member
  • *****
  • Posts: 2926
Re: Synapse abort timeout
« Reply #73 on: June 04, 2020, 09:38:55 pm »
I can't do that. My technic doesn't work.
Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2.  var i:integer=0;
  3. begin
  4.   i:=i+1;
  5.   if i=ProgressRefreshRate then begin
  6.   Synchronize(@ShowProgress);
  7.   i:=0;
  8.   end;
  9. end;

Note that, as it is, your code is completely equivalent to this:

Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2. begin
  3.   if 1 = ProgressRefreshRate then
  4.     Synchronize(@ShowProgress);
  5. end;

Your code would work if you did it like:

Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2. const
  3.   i:integer = 0;
  4. begin
  5.   i := i+1;
  6.   if i = ProgressRefreshRate then begin
  7.     Synchronize(@ShowProgress);
  8.     i:=0;
  9.   end;
  10. end;

But that would only ever trigger the if just once, unless you change ProgressRefreshRate elsewhere before this is called. If it's indeed a "rate" (that is, if you mean the if condition to be true, say, each 10 interations) you should do it, for example, like:

Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2. const
  3.   i:integer = 0;
  4. begin
  5.   i := i+1;
  6.   if (i mod ProgressRefreshRate) = 0 then begin
  7.     Synchronize(@ShowProgress);
  8.     if i >= 100 then i:=0;
  9.   end;
  10. end;
« Last Edit: June 04, 2020, 09:40:34 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Jake012345

  • Full Member
  • ***
  • Posts: 248
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Synapse abort timeout
« Reply #74 on: June 05, 2020, 04:27:49 am »
I wrote this:
Code: Pascal  [Select][+][-]
  1. procedure TCustomThread.MonitorHook(Sender: TObject; Writing: boolean; const Buffer: Pointer; Len: Integer);
  2. begin
  3.   inc(ProgressRefreshCooldown,1);
  4.   if ProgressRefreshCooldown>=ProgressRefreshRate then begin
  5.   Synchronize(@ShowProgress);
  6.   ProgressRefreshCooldown:=0;
  7.   end;
  8. end;    
  9.  
And I think thats good.
But I have a qusetion:
how fast it repeats? millisecons or faster?
Check my ProjectShare site and share your content: FPCShare

 

TinyPortal © 2005-2018