shorter server loop (in case of "hanging" data?)
direct context as connection
This commit is contained in:
parent
c075c6bb50
commit
24a9c83501
1 changed files with 13 additions and 5 deletions
|
@ -30,7 +30,8 @@ type
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
StrUtils, SysUtils, IdCustomTCPServer, IdCoderMIME;
|
StrUtils, SysUtils, DateUtils,
|
||||||
|
IdCustomTCPServer, IdCoderMIME;
|
||||||
|
|
||||||
{ TIdServerWebsocketHandling }
|
{ TIdServerWebsocketHandling }
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ var
|
||||||
wscode: TWSDataCode;
|
wscode: TWSDataCode;
|
||||||
wstype: TWSDataType;
|
wstype: TWSDataType;
|
||||||
context: TIdServerWSContext;
|
context: TIdServerWSContext;
|
||||||
|
tstart: TDateTime;
|
||||||
begin
|
begin
|
||||||
context := nil;
|
context := nil;
|
||||||
try
|
try
|
||||||
|
@ -58,11 +60,15 @@ begin
|
||||||
end;
|
end;
|
||||||
//AThread.Connection.Socket.UseNagle := False;
|
//AThread.Connection.Socket.UseNagle := False;
|
||||||
|
|
||||||
|
tstart := Now;
|
||||||
|
|
||||||
while AThread.Connection.Connected do
|
while AThread.Connection.Connected do
|
||||||
begin
|
begin
|
||||||
if (AThread.Connection.IOHandler.InputBuffer.Size > 0) or
|
if (AThread.Connection.IOHandler.InputBuffer.Size > 0) or
|
||||||
AThread.Connection.IOHandler.Readable(5 * 1000) then //wait 5s, else ping the client(!)
|
AThread.Connection.IOHandler.Readable(1 * 1000) then //wait 5s, else ping the client(!)
|
||||||
begin
|
begin
|
||||||
|
tstart := Now;
|
||||||
|
|
||||||
strmResponse := TMemoryStream.Create;
|
strmResponse := TMemoryStream.Create;
|
||||||
strmRequest := TMemoryStream.Create;
|
strmRequest := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
|
@ -104,8 +110,10 @@ begin
|
||||||
strmResponse.Free;
|
strmResponse.Free;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else
|
//ping after 5s idle
|
||||||
|
else if SecondsBetween(Now, tstart) > 5 then
|
||||||
begin
|
begin
|
||||||
|
tstart := Now;
|
||||||
//ping
|
//ping
|
||||||
if context.IsSocketIO then
|
if context.IsSocketIO then
|
||||||
begin
|
begin
|
||||||
|
@ -193,8 +201,8 @@ begin
|
||||||
AResponseInfo.ContentText := squid +
|
AResponseInfo.ContentText := squid +
|
||||||
':15:10:websocket,xhr-polling';
|
':15:10:websocket,xhr-polling';
|
||||||
AResponseInfo.CloseConnection := False;
|
AResponseInfo.CloseConnection := False;
|
||||||
//(AThread.SocketIO as TIdServerSocketIOHandling_Ext).NewConnection(AThread);
|
(AThread.SocketIO as TIdServerSocketIOHandling_Ext).NewConnection(AThread);
|
||||||
(AThread.SocketIO as TIdServerSocketIOHandling_Ext).NewConnection(squid, AThread.Binding.PeerIP);
|
//(AThread.SocketIO as TIdServerSocketIOHandling_Ext).NewConnection(squid, AThread.Binding.PeerIP);
|
||||||
|
|
||||||
Result := True; //handled
|
Result := True; //handled
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue