Skip to content

Commit

Permalink
implements minimal error handling in THttpApiWebSocketConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Bouchez committed Nov 20, 2017
1 parent 9544d5f commit cb3756c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
25 changes: 9 additions & 16 deletions SynCrtSock.pas
Expand Up @@ -8767,10 +8767,12 @@ procedure THttpApiWebSocketConnection.ReadData(const aBuf: WEB_SOCKET_BUFFER_DAT
var Err: HRESULT;
fBytesRead: cardinal;
begin
if fWSHandle = nil then
exit;
Err := Http.ReceiveRequestEntityBody(fProtocol.fServer.FReqQueue, fOpaqueHTTPRequestId, 0,
aBuf.pbBuffer, aBuf.ulBufferLength, fBytesRead, @self.fOverlapped);
case Err of
ERROR_HANDLE_EOF: ; // todo: close connection
ERROR_HANDLE_EOF: Disconnect;
ERROR_IO_PENDING: ; //
NO_ERROR: ;//
else
Expand All @@ -8783,6 +8785,8 @@ procedure THttpApiWebSocketConnection.WriteData(const aBuf: WEB_SOCKET_BUFFER_DA
httpSendEntity: HTTP_DATA_CHUNK_INMEMORY;
bytesWrite: Cardinal;
begin
if fWSHandle = nil then
exit;
bytesWrite := 0;
httpSendEntity.DataChunkType := hctFromMemory;
httpSendEntity.pBuffer := aBuf.pbBuffer;
Expand All @@ -8791,7 +8795,7 @@ procedure THttpApiWebSocketConnection.WriteData(const aBuf: WEB_SOCKET_BUFFER_DA
HTTP_SEND_RESPONSE_FLAG_BUFFER_DATA or HTTP_SEND_RESPONSE_FLAG_MORE_DATA,
1, @httpSendEntity, bytesWrite, nil, nil, @fProtocol.fServer.fSendOverlaped);
case Err of
ERROR_HANDLE_EOF: ; // todo: close connection
ERROR_HANDLE_EOF: Disconnect;
ERROR_IO_PENDING: ; //
NO_ERROR: ;//
else
Expand All @@ -8817,29 +8821,18 @@ procedure THttpApiWebSocketConnection.CheckIsActive;
end;

procedure THttpApiWebSocketConnection.Disconnect;
var Err: HRESULT;
var //Err: HRESULT; //todo: handle error
httpSendEntity: HTTP_DATA_CHUNK_INMEMORY;
bytesWrite: Cardinal;
begin
WebSocketAPI.AbortHandle(fWSHandle);
WebSocketAPI.DeleteHandle(fWSHandle);
fWSHandle := nil;

httpSendEntity.DataChunkType := hctFromMemory;
httpSendEntity.pBuffer := nil;
httpSendEntity.BufferLength := 0;

Err := Http.SendResponseEntityBody(fProtocol.fServer.fReqQueue, fOpaqueHTTPRequestId,
HTTP_SEND_RESPONSE_FLAG_DISCONNECT,
1, @httpSendEntity, bytesWrite, nil, nil, nil);
// todo: check Err
case Err of
ERROR_HANDLE_EOF: ; // todo: close connection
ERROR_IO_PENDING: ; //
NO_ERROR: ;//
else
// todo: close connection
end;
{Err :=} Http.SendResponseEntityBody(fProtocol.fServer.fReqQueue, fOpaqueHTTPRequestId,
HTTP_SEND_RESPONSE_FLAG_DISCONNECT, 1, @httpSendEntity, bytesWrite, nil, nil, nil);
end;

procedure THttpApiWebSocketConnection.BeforeRead;
Expand Down
2 changes: 1 addition & 1 deletion SynopseCommit.inc
@@ -1 +1 @@
'1.18.3983'
'1.18.3984'
4 changes: 2 additions & 2 deletions compilFPC.bat
@@ -1,8 +1,8 @@
@echo off

set lib=d:\dev\lib
set bin=z:\tempbuild\fpc
set fpc=c:\fpcupdeluxe\fpc\bin\i386-win32\fpc.exe
set bin=d:\dev\lib\tempbuild\fpc
set fpc=c:\np\fpc\bin\i386-win32\fpc.exe

if exist %fpc% (

Expand Down

0 comments on commit cb3756c

Please sign in to comment.