Skip to content

Commit

Permalink
introducing cross-platform INVALID_HANDLE_VALUE constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Aug 30, 2023
1 parent f41ee35 commit fca9a7c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/core/mormot.core.os.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2631,6 +2631,9 @@ function FileTimeToUnixMSTime(const FT: TFileTime): TUnixMSTime;
{$else}

const
/// a cross-platform incorrect THandle value, as defined in Windows unit
INVALID_HANDLE_VALUE = THandle(-1);

/// allow to assign proper signed symbol table name for a libc.so.6 method
{$ifdef OSLINUXX64}
LIBC_SUFFIX = '@GLIBC_2.2.5';
Expand Down Expand Up @@ -4338,6 +4341,7 @@ TAutoLock = class(TInterfacedObject)
end;

/// our lightweight cross-platform TEvent-like component
// - on Windows, calls directly the CreateEvent/ResetEvent/SetEvent API
// - on Linux, will use eventfd() in blocking and non-semaphore mode
// - on other POSIX, will use PRTLEvent which is lighter than TEvent BasicEvent
// - only limitation is that we don't know if WaitFor is signaled or timeout,
Expand Down
6 changes: 3 additions & 3 deletions src/core/mormot.core.os.windows.inc
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ begin
result := CreateFileW(W32(aFileName, tmp), ACCESS[aMode and 3], SHARE[s],
nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
else
result := THandle(-1);
result := INVALID_HANDLE_VALUE;
end;

function FileSetDateFrom(const Dest: TFileName; SourceHandle: THandle): boolean;
Expand Down Expand Up @@ -3267,11 +3267,11 @@ begin
exit;
add := address;
virt := nil;
if NtMapViewOfSection(mem, THandle(-1), @virt, 0, size, add, @size,
if NtMapViewOfSection(mem, INVALID_HANDLE_VALUE, @virt, 0, size, add, @size,
1, 0, PAGE_READONLY) = 0 then
begin
FastSetRawByteString(result, virt, size);
NtUnmapViewOfSection(THandle(-1), virt);
NtUnmapViewOfSection(INVALID_HANDLE_VALUE, virt);
end;
CloseHandle(mem);
end;
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'2.1.5806'
'2.1.5807'
4 changes: 2 additions & 2 deletions src/net/mormot.net.sock.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4696,7 +4696,7 @@ procedure TCrtSocket.CreateSockIn(LineBreak: TTextLineBreakStyle;
BufSize := InputBufferSize;
BufPtr := pointer(PAnsiChar(SockIn) + SizeOf(TTextRec));
OpenFunc := @OpenSock;
Handle := {$ifdef FPC}THandle{$endif}(0); // some invalid handle
Handle := INVALID_HANDLE_VALUE;
end;
SetLineBreakStyle(SockIn^, LineBreak); // http does break lines with #13#10
Reset(SockIn^);
Expand All @@ -4718,7 +4718,7 @@ procedure TCrtSocket.CreateSockOut(OutputBufferSize: integer);
BufSize := OutputBufferSize;
BufPtr := pointer(PAnsiChar(SockIn) + SizeOf(TTextRec)); // ignore Buffer[] (Delphi 2009+)
OpenFunc := @OpenSock;
Handle := {$ifdef FPC}THandle{$endif}(0);
Handle := INVALID_HANDLE_VALUE;
end;
SetLineBreakStyle(SockOut^, tlbsCRLF); // force e.g. for Linux platforms
Rewrite(SockOut^);
Expand Down

0 comments on commit fca9a7c

Please sign in to comment.