Hello,
I'm using FPC 2.6.0 on Linux with newest SVN's Synapse codebase. I'm writing
few console based applications which utilise non-blocking TCP connection and
I've found Synapse as the best one library on the market, thank you very
much for well done job! :)
I need to connect HookMonitor and/or HookStatus to my apps, however I'm
lacking a bit od knowledge to do so. Could you please point me to some
examples for hooking Status and Monitor in console (non-Lazarus)
application?
Thank you in advance,
Jason
The only "diffculty" is that THookSocketStatus and THookMonitor are defined
as procedure() of object. This means that you need to pass a class method to
the OnStatus and OnMonitor properties. Here is a sample program that creates
a class containing the 2 hooks:
program Project1;
{$mode objfpc}{$H+}
uses
blcksock,synsock;
type
{ TMonStat }
TMonStat=class(TObject)
procedure SocketStatus(Sender: TObject; Reason: THookSocketReason;
const Value: String);
procedure Monitor(Sender: TObject; Writing: Boolean;
const Buffer: TMemory; Len: Integer);
end;
{ TMonStat }
procedure TMonStat.SocketStatus(Sender: TObject; Reason: THookSocketReason;
const Value: String);
begin
//
end;
procedure TMonStat.Monitor(Sender: TObject; Writing: Boolean;
const Buffer: TMemory; Len: Integer);
begin
//
end;
var
sock:TTCPBlockSocket;
MonStatus:TMonStat;
begin
MonStatus:=TMonStat.Create;
sock:=TTCPBlockSocket.Create;
sock.OnStatus:[email protected];
sock.OnMonitor:[email protected];
// do whatever with sock, as usual needed here
sock.Free;
MonStatus.Free;
end.
You can use one TMonStat instance for all the sockets created in your
program but you need to make the OnStatus:[email protected] and
OnMonitor:[email protected] assignment for each and every one.
In case you run multiple threads, the usual precautions have to be taken
when sharing objects accross thread boundaries.
Ludo
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
synalist-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/synalist-public