source: tags/1.0.0/Packages/synapse/synadbg.pas

Last change on this file was 1, checked in by chronos, 8 years ago
  • Added: Synapse package for HTTP download support.
  • Added: Import from MediaWiki page source copied from clipboard.
  • Added: Show application tray icon in task bar notification area.
  • Added: Load and save acronyms in file and allow filtering them.
File size: 5.9 KB
Line 
1{==============================================================================|
2| Project : Ararat Synapse | 001.001.000 |
3|==============================================================================|
4| Content: Socket debug tools |
5|==============================================================================|
6| Copyright (c)2008, Lukas Gebauer |
7| All rights reserved. |
8| |
9| Redistribution and use in source and binary forms, with or without |
10| modification, are permitted provided that the following conditions are met: |
11| |
12| Redistributions of source code must retain the above copyright notice, this |
13| list of conditions and the following disclaimer. |
14| |
15| Redistributions in binary form must reproduce the above copyright notice, |
16| this list of conditions and the following disclaimer in the documentation |
17| and/or other materials provided with the distribution. |
18| |
19| Neither the name of Lukas Gebauer nor the names of its contributors may |
20| be used to endorse or promote products derived from this software without |
21| specific prior written permission. |
22| |
23| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
24| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
25| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
26| ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR |
27| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
28| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
29| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
30| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
31| LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
32| OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
33| DAMAGE. |
34|==============================================================================|
35| The Initial Developer of the Original Code is Lukas Gebauer (Czech Republic).|
36| Portions created by Lukas Gebauer are Copyright (c)2008. |
37| All Rights Reserved. |
38|==============================================================================|
39| Contributor(s): |
40|==============================================================================|
41| History: see HISTORY.HTM from distribution package |
42| (Found at URL: http://www.ararat.cz/synapse/) |
43|==============================================================================}
44
45{:@abstract(Socket debug tools)
46
47Routines for help with debugging of events on the Sockets.
48}
49
50
51unit synadbg;
52
53interface
54
55uses
56 blcksock, synsock, synautil, classes, sysutils;
57
58type
59 TSynaDebug = class(TObject)
60 class procedure HookStatus(Sender: TObject; Reason: THookSocketReason; const Value: string);
61 class procedure HookMonitor(Sender: TObject; Writing: Boolean; const Buffer: TMemory; Len: Integer);
62 end;
63
64procedure AppendToLog(const value: Ansistring);
65
66var
67 LogFile: string;
68
69implementation
70
71procedure AppendToLog(const value: Ansistring);
72var
73 st: TFileStream;
74 s: string;
75 h, m, ss, ms: word;
76 dt: Tdatetime;
77begin
78 if fileexists(LogFile) then
79 st := TFileStream.Create(LogFile, fmOpenReadWrite or fmShareDenyWrite)
80 else
81 st := TFileStream.Create(LogFile, fmCreate or fmShareDenyWrite);
82 try
83 st.Position := st.Size;
84 dt := now;
85 decodetime(dt, h, m, ss, ms);
86 s := formatdatetime('yyyymmdd-hhnnss', dt) + format('.%.3d', [ms]) + ' ' + value;
87 WriteStrToStream(st, s);
88 finally
89 st.free;
90 end;
91end;
92
93class procedure TSynaDebug.HookStatus(Sender: TObject; Reason: THookSocketReason; const Value: string);
94var
95 s: string;
96begin
97 case Reason of
98 HR_ResolvingBegin:
99 s := 'HR_ResolvingBegin';
100 HR_ResolvingEnd:
101 s := 'HR_ResolvingEnd';
102 HR_SocketCreate:
103 s := 'HR_SocketCreate';
104 HR_SocketClose:
105 s := 'HR_SocketClose';
106 HR_Bind:
107 s := 'HR_Bind';
108 HR_Connect:
109 s := 'HR_Connect';
110 HR_CanRead:
111 s := 'HR_CanRead';
112 HR_CanWrite:
113 s := 'HR_CanWrite';
114 HR_Listen:
115 s := 'HR_Listen';
116 HR_Accept:
117 s := 'HR_Accept';
118 HR_ReadCount:
119 s := 'HR_ReadCount';
120 HR_WriteCount:
121 s := 'HR_WriteCount';
122 HR_Wait:
123 s := 'HR_Wait';
124 HR_Error:
125 s := 'HR_Error';
126 else
127 s := '-unknown-';
128 end;
129 s := inttohex(integer(Pointer(Sender)), 8) + s + ': ' + value + CRLF;
130 AppendToLog(s);
131end;
132
133class procedure TSynaDebug.HookMonitor(Sender: TObject; Writing: Boolean; const Buffer: TMemory; Len: Integer);
134var
135 s, d: Ansistring;
136begin
137 setlength(s, len);
138 move(Buffer^, pointer(s)^, len);
139 if writing then
140 d := '-> '
141 else
142 d := '<- ';
143 s :=inttohex(integer(Pointer(Sender)), 8) + d + s + CRLF;
144 AppendToLog(s);
145end;
146
147initialization
148begin
149 Logfile := changefileext(paramstr(0), '.slog');
150end;
151
152end.
Note: See TracBrowser for help on using the repository browser.