function ReceiveText: string; virtual; function TCustomWinSocket.ReceiveText: string; begin if ReceiveLength > 0 then begin SetLength(Result, ReceiveLength); ReceiveBuf(Result[1], Length(Result)); end else Result := ''; end;
function TServerClientWinSocket.ReceiveLength: Integer; begin Result := FStream.Position; end; function TServerClientWinSocket.ReceiveBuf(var Buf; Count: Integer): Integer; var P, Len: Integer; begin Lock; try if FStream.Position >= Count then begin P := FStream.Position - Count; FStream.Position := P; Len := Count; end else begin P := 0; Len := FStream.Position; FStream.Position := P; end;
Result := FStream.Read(Buf, Len); if FStream.Position = FStream.Size then begin //´óÓÚ4K¾Í·ÅµôÖØÐ·ÖÅäÄÚ´æ,·ñÔò,Ö»Êǽ«Ö¸ÕëÒÆ¶¯µ½Í·²¿ if FStream.Size > 4096 then FStream.Clear else FStream.Position := 0; end else begin FStream.Position := P + (Len - Result); end; finally UnLock; end; end;
ÐÂÐ޸ģº TCustomWinSocketÀàÌí¼ÓÁË function ReceiveText: string; virtual; function TCustomWinSocket.ReceiveText: string; begin if ReceiveLength > 0 then begin SetLength(Result, ReceiveLength); ReceiveBuf(Result[1], Length(Result)); end else Result := ''; end;
function TServerClientWinSocket.ReceiveLength: Integer; begin Result := FStream.Position; end; function TServerClientWinSocket.ReceiveBuf(var Buf; Count: Integer): Integer; var P1: Integer; PS, PD: Pointer; begin Lock; try P1 := FStream.Position; FStream.Seek(0, soBeginning); FStream.ReadBuffer(Buf, Count); if FStream.Position = P1 then begin {´óÓÚ4K¾Í·ÅµôÖØÐ·ÖÅäÄÚ´æ,·ñÔò,Ö»Êǽ«Ö¸ÕëÒÆ¶¯µ½Í·²¿} if FStream.Size > 4096 then FStream.Clear else FStream.Seek(0, soBeginning); end else if FStream.Position < P1 then begin PS := Pointer(Longint(FStream.Memory) + FStream.Position); Move(PS^, FStream.Memory^, P1 - FStream.Position); FStream.Position := P1 - FStream.Position; end; finally UnLock; end; end;
This block was previously allocated by thread 0xF84, and the stack trace (return addresses) at the time was: 402D48 456CA4 4583CA 44D09F 45475C 4586A4 7C82F23B [Unknown function at ProcessIdToSessionId]
The allocation number was: 527
The block was previously freed by thread 0xF84, and the stack trace (return addresses) at the time was: 402D73
The current thread ID is 0xF84, and the stack trace (return addresses) leading to this error is: 40B826 40B86E 4041FF 4044BE 7C82F23B [Unknown function at ProcessIdToSessionId]
function TServerClientWinSocket.WorkBlock(var Block: PBlock; Transfered: DWORD): DWORD; var ErrCode: Integer; Flag, BytesSend: Cardinal; begin Result := RESPONSE_SUCCESS; with Block^.Data do try case Block^.Data.Event of seRead: begin {ÀûÓÃÄÚ´æÁ÷À´±£´æÊÕµ½µÄÊý¾Ý,ÓпÉÄÜÔì³ÉƵ·±µÄÄÚ´æÖØÐ·ÖÅä,¿ÉÒԸĽø} Lock; FStream.Clear; //<<---½ÓÊÕµ½Á÷ǰÏÈÇå¿ÕÔÄÚÈÝ£¬ FStream.Write(Buffer, Transfered); UnLock; Self.Event(Self, seRead); if not PrepareRecv(Block) then Result := RESPONSE_FAIL; end; seWrite: begin // Self.Event(Self, seWrite); Dec(wsaBuffer.len, Transfered); if wsaBuffer.len <= 0 then begin { ·¢ËÍÍê³É£¬½«BlockÖÿգ¬·µ»Øµ½FBlockµÄ¿ÉʹÓõĻºÇøÖÐ } Block.Data.IsUse := False; Block := nil; end else begin { Êý¾Ý»¹Ã»·¢ËÍÍê³É£¬¼ÌÐø·¢ËÍ } Flag := 0; Inc(wsaBuffer.buf, Transfered); FillChar(Overlapped, SizeOf(Overlapped), 0); if SOCKET_ERROR = WSASend(FSocket, @wsaBuffer, 1, BytesSend, Flag, @Overlapped, nil) then begin ErrCode := WSAGetLastError; if ErrCode <> ERROR_IO_PENDING then Error(Self, eeSend, ErrCode); end; end; end; end; except Result := RESPONSE_FAIL; end; end;