blob: 5c3d8a5cadbbb915f0abd68cdf94450c110f329f [file] [log] [blame]
Jens Geyerd5436f52014-10-03 19:50:38 +02001(*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *)
19
20unit Thrift.Utils;
21
22interface
23
24uses
25 Classes, Windows, SysUtils, SyncObjs;
26
27type
28 IOverlappedHelper = interface
29 ['{A1832EFA-2E02-4884-8F09-F0A0277157FA}']
30 function Overlapped : TOverlapped;
31 function OverlappedPtr : POverlapped;
32 function WaitHandle : THandle;
33 function WaitFor(dwTimeout: DWORD) : DWORD;
34 end;
35
36 TOverlappedHelperImpl = class( TInterfacedObject, IOverlappedHelper)
37 strict protected
38 FOverlapped : TOverlapped;
39 FEvent : TEvent;
40
41 // IOverlappedHelper
42 function Overlapped : TOverlapped;
43 function OverlappedPtr : POverlapped;
44 function WaitHandle : THandle;
45 function WaitFor(dwTimeout: DWORD) : DWORD;
46 public
47 constructor Create;
48 destructor Destroy; override;
49 end;
50
51
Jens Geyerd5436f52014-10-03 19:50:38 +020052implementation
53
Jens Geyerd5436f52014-10-03 19:50:38 +020054{ TOverlappedHelperImpl }
55
56constructor TOverlappedHelperImpl.Create;
57begin
58 inherited Create;
59 FillChar( FOverlapped, SizeOf(FOverlapped), 0);
60 FEvent := TEvent.Create( nil, TRUE, FALSE, ''); // always ManualReset, see MSDN
61 FOverlapped.hEvent := FEvent.Handle;
62end;
63
64
65
66destructor TOverlappedHelperImpl.Destroy;
67begin
68 try
69 FOverlapped.hEvent := 0;
70 FreeAndNil( FEvent);
71
72 finally
73 inherited Destroy;
74 end;
75
76end;
77
78
79function TOverlappedHelperImpl.Overlapped : TOverlapped;
80begin
81 result := FOverlapped;
82end;
83
84
85function TOverlappedHelperImpl.OverlappedPtr : POverlapped;
86begin
87 result := @FOverlapped;
88end;
89
90
91function TOverlappedHelperImpl.WaitHandle : THandle;
92begin
93 result := FOverlapped.hEvent;
94end;
95
96
97function TOverlappedHelperImpl.WaitFor( dwTimeout : DWORD) : DWORD;
98begin
99 result := WaitForSingleObject( FOverlapped.hEvent, dwTimeout);
100end;
101
102
103
104
105end.