[Synalist] TBlockSocket.SendBuffer deadlock if client disconnect before complete
Pascal TCP/IP Library
Brought to you by:
geby
From: Suparit T. <tsu...@ya...> - 2007-08-24 01:14:34
|
how to prevent the dead lock i make a small http web server , i found that the dead lock come out from the "TBlockSocket.SendBuffer" when i try to call this line and if client close the connection before finish sent complete. i try to modify the code below , it looks work. ..but Do you have any guide for me ? My idea is correct or not Thank you very much Suparit function TBlockSocket.SendBuffer(Buffer: TMemory; Length: Integer): Integer; {$IFNDEF CIL} var x, y: integer; l, r: integer; p: Pointer; maxloopcnt:integer; //++++spl {$ENDIF} begin Result := 0; if TestStopFlag then Exit; DoMonitor(True, Buffer, Length); {$IFDEF CIL} Result := synsock.Send(FSocket, Buffer, Length, 0); {$ELSE} l := Length; maxloopcnt:=0; //++ writeln(l); x := 0; while (x < l) do begin Inc(maxloopcnt,1); //writeln('[TX]');//++++ //sleep(1); //+++reduce cpu load.. y := l - x; //prevent dead lock if y > FSendMaxChunk then y := FSendMaxChunk; if y > 0 then begin LimitBandwidth(y, FMaxSendBandwidth, FNextsend); p := IncPoint(Buffer, x); r := synsock.Send(FSocket, p, y, MSG_NOSIGNAL); SockCheck(r); //writeln(FLastError);//++++ if FLastError = WSAEWOULDBLOCK then begin if CanWrite(FNonblockSendTimeout) then begin r := synsock.Send(FSocket, p, y, MSG_NOSIGNAL); SockCheck(r); end else FLastError := WSAETIMEDOUT; end; if FLastError <> 0 then Break; //writeln(r);//+++ //if client disconnect it will found -1 if (r<0) or (maxloopcnt>Length) then begin Break; //remove dead lock add...client disconnect before sent complete writeln('client disconnect before sent buffer complete anti-dead lock'); end; Inc(x, r); Inc(Result, r); Inc(FSendCounter, r); DoStatus(HR_WriteCount, IntToStr(r)); end else break; end; {$ENDIF} ExceptCheck; //writeln(maxloopcnt);//++++ end; --------------------------------- Pinpoint customers who are looking for what you sell. |