From 2b7abcceff071ede12b28d2d3ee8e0f8f2140031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Mussche?= Date: Mon, 20 Jan 2014 08:59:12 +0100 Subject: [PATCH] xe5 compatible --- IdIOHandlerWebsocket.pas | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/IdIOHandlerWebsocket.pas b/IdIOHandlerWebsocket.pas index 1f3fc74..739174f 100644 --- a/IdIOHandlerWebsocket.pas +++ b/IdIOHandlerWebsocket.pas @@ -6,8 +6,9 @@ unit IdIOHandlerWebsocket; interface uses - Classes, - IdIOHandlerStack, IdGlobal, IdException, IdBuffer, SyncObjs, + Classes, SysUtils, + IdIOHandlerStack, IdGlobal, IdException, IdBuffer, + SyncObjs, Generics.Collections; type @@ -19,6 +20,10 @@ type TIdIOHandlerWebsocket = class; EIdWebSocketHandleError = class(EIdSocketHandleError); + {$if CompilerVersion >= 26} //XE5 + TIdTextEncoding = IIdTextEncoding; + {$ifend} + TIdIOHandlerWebsocket = class(TIdIOHandlerStack) private FIsServerSide: Boolean; @@ -44,6 +49,12 @@ type function ReadFrame(out aFIN, aRSV1, aRSV2, aRSV3: boolean; out aDataCode: TWSDataCode; out aData: TIdBytes): Integer; function ReadMessage(var aBuffer: TIdBytes; out aDataCode: TWSDataCode): Integer; + + {$if CompilerVersion >= 26} //XE5 + function UTF8Encoding: IIdTextEncoding; + {$else} + function UTF8Encoding: TEncoding; + {$ifend} public function WriteData(aData: TIdBytes; aType: TWSDataCode; aFIN: boolean = true; aRSV1: boolean = false; aRSV2: boolean = false; aRSV3: boolean = false): integer; @@ -171,7 +182,7 @@ const implementation uses - SysUtils, Math, Windows, + Math, Windows, IdStream, IdStack, IdWinsock2, IdExceptionCore, IdResourceStrings, IdResourceStringsCore; @@ -381,7 +392,7 @@ begin Lock; try FWriteTextToTarget := True; - inherited WriteLn(AOut, TIdTextEncoding.UTF8); //must be UTF8! + inherited WriteLn(AOut, UTF8Encoding); //must be UTF8! finally FWriteTextToTarget := False; Unlock; @@ -408,7 +419,7 @@ begin Lock; try FWriteTextToTarget := True; - inherited WriteLnRFC(AOut, TIdTextEncoding.UTF8); //must be UTF8! + inherited WriteLnRFC(AOut, UTF8Encoding); //must be UTF8! finally FWriteTextToTarget := False; Unlock; @@ -435,7 +446,7 @@ begin Lock; try FWriteTextToTarget := True; - inherited Write(AOut, TIdTextEncoding.UTF8); //must be UTF8! + inherited Write(AOut, UTF8Encoding); //must be UTF8! finally FWriteTextToTarget := False; Unlock; @@ -462,7 +473,7 @@ begin Lock; try FWriteTextToTarget := True; - inherited Write(AValue, AWriteLinesCount, TIdTextEncoding.UTF8); //must be UTF8! + inherited Write(AValue, AWriteLinesCount, UTF8Encoding); //must be UTF8! finally FWriteTextToTarget := False; Unlock; @@ -654,7 +665,7 @@ begin FCloseCode := (iaReadBuffer[0] shl 8) + iaReadBuffer[1]; if Length(iaReadBuffer) > 2 then - FCloseReason := BytesToString(iaReadBuffer, 2, Length(iaReadBuffer), TEncoding.UTF8); + FCloseReason := BytesToString(iaReadBuffer, 2, Length(iaReadBuffer), UTF8Encoding); end; FClosing := True; @@ -723,6 +734,18 @@ begin FLock.Leave; 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; out aDataCode: TWSDataCode; out aData: TIdBytes): Integer; var @@ -899,7 +922,7 @@ var False: (MaskAsInt : Int32); end; strmData: TMemoryStream; - bData: TBytes; + bData: TIdBytes; begin Result := 0; Assert(Binding <> nil);