xe5 compatible
This commit is contained in:
parent
e1f132d1bd
commit
2b7abcceff
1 changed files with 32 additions and 9 deletions
|
@ -6,8 +6,9 @@ unit IdIOHandlerWebsocket;
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes,
|
Classes, SysUtils,
|
||||||
IdIOHandlerStack, IdGlobal, IdException, IdBuffer, SyncObjs,
|
IdIOHandlerStack, IdGlobal, IdException, IdBuffer,
|
||||||
|
SyncObjs,
|
||||||
Generics.Collections;
|
Generics.Collections;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -19,6 +20,10 @@ type
|
||||||
TIdIOHandlerWebsocket = class;
|
TIdIOHandlerWebsocket = class;
|
||||||
EIdWebSocketHandleError = class(EIdSocketHandleError);
|
EIdWebSocketHandleError = class(EIdSocketHandleError);
|
||||||
|
|
||||||
|
{$if CompilerVersion >= 26} //XE5
|
||||||
|
TIdTextEncoding = IIdTextEncoding;
|
||||||
|
{$ifend}
|
||||||
|
|
||||||
TIdIOHandlerWebsocket = class(TIdIOHandlerStack)
|
TIdIOHandlerWebsocket = class(TIdIOHandlerStack)
|
||||||
private
|
private
|
||||||
FIsServerSide: Boolean;
|
FIsServerSide: Boolean;
|
||||||
|
@ -44,6 +49,12 @@ type
|
||||||
|
|
||||||
function ReadFrame(out aFIN, aRSV1, aRSV2, aRSV3: boolean; out aDataCode: TWSDataCode; out aData: TIdBytes): Integer;
|
function ReadFrame(out aFIN, aRSV1, aRSV2, aRSV3: boolean; out aDataCode: TWSDataCode; out aData: TIdBytes): Integer;
|
||||||
function ReadMessage(var aBuffer: TIdBytes; out aDataCode: TWSDataCode): Integer;
|
function ReadMessage(var aBuffer: TIdBytes; out aDataCode: TWSDataCode): Integer;
|
||||||
|
|
||||||
|
{$if CompilerVersion >= 26} //XE5
|
||||||
|
function UTF8Encoding: IIdTextEncoding;
|
||||||
|
{$else}
|
||||||
|
function UTF8Encoding: TEncoding;
|
||||||
|
{$ifend}
|
||||||
public
|
public
|
||||||
function WriteData(aData: TIdBytes; aType: TWSDataCode;
|
function WriteData(aData: TIdBytes; aType: TWSDataCode;
|
||||||
aFIN: boolean = true; aRSV1: boolean = false; aRSV2: boolean = false; aRSV3: boolean = false): integer;
|
aFIN: boolean = true; aRSV1: boolean = false; aRSV2: boolean = false; aRSV3: boolean = false): integer;
|
||||||
|
@ -171,7 +182,7 @@ const
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, Math, Windows,
|
Math, Windows,
|
||||||
IdStream, IdStack, IdWinsock2, IdExceptionCore,
|
IdStream, IdStack, IdWinsock2, IdExceptionCore,
|
||||||
IdResourceStrings, IdResourceStringsCore;
|
IdResourceStrings, IdResourceStringsCore;
|
||||||
|
|
||||||
|
@ -381,7 +392,7 @@ begin
|
||||||
Lock;
|
Lock;
|
||||||
try
|
try
|
||||||
FWriteTextToTarget := True;
|
FWriteTextToTarget := True;
|
||||||
inherited WriteLn(AOut, TIdTextEncoding.UTF8); //must be UTF8!
|
inherited WriteLn(AOut, UTF8Encoding); //must be UTF8!
|
||||||
finally
|
finally
|
||||||
FWriteTextToTarget := False;
|
FWriteTextToTarget := False;
|
||||||
Unlock;
|
Unlock;
|
||||||
|
@ -408,7 +419,7 @@ begin
|
||||||
Lock;
|
Lock;
|
||||||
try
|
try
|
||||||
FWriteTextToTarget := True;
|
FWriteTextToTarget := True;
|
||||||
inherited WriteLnRFC(AOut, TIdTextEncoding.UTF8); //must be UTF8!
|
inherited WriteLnRFC(AOut, UTF8Encoding); //must be UTF8!
|
||||||
finally
|
finally
|
||||||
FWriteTextToTarget := False;
|
FWriteTextToTarget := False;
|
||||||
Unlock;
|
Unlock;
|
||||||
|
@ -435,7 +446,7 @@ begin
|
||||||
Lock;
|
Lock;
|
||||||
try
|
try
|
||||||
FWriteTextToTarget := True;
|
FWriteTextToTarget := True;
|
||||||
inherited Write(AOut, TIdTextEncoding.UTF8); //must be UTF8!
|
inherited Write(AOut, UTF8Encoding); //must be UTF8!
|
||||||
finally
|
finally
|
||||||
FWriteTextToTarget := False;
|
FWriteTextToTarget := False;
|
||||||
Unlock;
|
Unlock;
|
||||||
|
@ -462,7 +473,7 @@ begin
|
||||||
Lock;
|
Lock;
|
||||||
try
|
try
|
||||||
FWriteTextToTarget := True;
|
FWriteTextToTarget := True;
|
||||||
inherited Write(AValue, AWriteLinesCount, TIdTextEncoding.UTF8); //must be UTF8!
|
inherited Write(AValue, AWriteLinesCount, UTF8Encoding); //must be UTF8!
|
||||||
finally
|
finally
|
||||||
FWriteTextToTarget := False;
|
FWriteTextToTarget := False;
|
||||||
Unlock;
|
Unlock;
|
||||||
|
@ -654,7 +665,7 @@ begin
|
||||||
FCloseCode := (iaReadBuffer[0] shl 8) +
|
FCloseCode := (iaReadBuffer[0] shl 8) +
|
||||||
iaReadBuffer[1];
|
iaReadBuffer[1];
|
||||||
if Length(iaReadBuffer) > 2 then
|
if Length(iaReadBuffer) > 2 then
|
||||||
FCloseReason := BytesToString(iaReadBuffer, 2, Length(iaReadBuffer), TEncoding.UTF8);
|
FCloseReason := BytesToString(iaReadBuffer, 2, Length(iaReadBuffer), UTF8Encoding);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FClosing := True;
|
FClosing := True;
|
||||||
|
@ -723,6 +734,18 @@ begin
|
||||||
FLock.Leave;
|
FLock.Leave;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$if CompilerVersion >= 26} //XE5
|
||||||
|
function TIdIOHandlerWebsocket.UTF8Encoding: IIdTextEncoding;
|
||||||
|
begin
|
||||||
|
Result := IndyTextEncoding_UTF8;
|
||||||
|
end;
|
||||||
|
{$else}
|
||||||
|
function TIdIOHandlerWebsocket.UTF8Encoding: TEncoding;
|
||||||
|
begin
|
||||||
|
Result := TIdTextEncoding.UTF8;
|
||||||
|
end;
|
||||||
|
{$ifend}
|
||||||
|
|
||||||
function TIdIOHandlerWebsocket.ReadFrame(out aFIN, aRSV1, aRSV2, aRSV3: boolean;
|
function TIdIOHandlerWebsocket.ReadFrame(out aFIN, aRSV1, aRSV2, aRSV3: boolean;
|
||||||
out aDataCode: TWSDataCode; out aData: TIdBytes): Integer;
|
out aDataCode: TWSDataCode; out aData: TIdBytes): Integer;
|
||||||
var
|
var
|
||||||
|
@ -899,7 +922,7 @@ var
|
||||||
False: (MaskAsInt : Int32);
|
False: (MaskAsInt : Int32);
|
||||||
end;
|
end;
|
||||||
strmData: TMemoryStream;
|
strmData: TMemoryStream;
|
||||||
bData: TBytes;
|
bData: TIdBytes;
|
||||||
begin
|
begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
Assert(Binding <> nil);
|
Assert(Binding <> nil);
|
||||||
|
|
Loading…
Reference in a new issue