to dcsdcds:
呵呵!数据传输的代码不是我写的,是Borland原码啊!
{*******************************************************}
{ }
{ Borland Delphi Visual Component Library }
{ Streamed Connection classes }
{ }
{ Copyright (c) 1997,99 Inprise Corporation }
{ }
{*******************************************************}
unit SConnect;
{$R-}
interface
uses
Windows, Messages, Classes, SysUtils, MConnect, ScktComp, WinSock, objbrkr, WinINet;
type
//>------------------11.11----------------------------------------------------
TDataReserved= procedure (Sender: TObject; BytesReceive, BytesCount: Integer) of object;
//<---------------------------------------------------------------------------
TSocketTransport = class(TInterfacedObject, ITransport)
private
FEvent: THandle;
FInterceptor: IDataIntercept;
FCreateAttempted: Boolean;
//>------------------说 明---------------------------------------
FOnDataReserved: TDataReserved;
//<-------------------------------------------------------------------------
property OnDataReserved: TDataReserved read FOnDataReserved write FOnDataReserved;
function TSocketTransport.Receive(WaitForInput: Boolean; Context: Integer;TimeOut:Integer=15): IDataBlock;
var
RetLen, Sig, StreamLen: Integer;
P: Pointer;
FDSet: TFDSet;
TimeVal: PTimeVal;
RetVal, ByteReceive, ByteCount: Integer;
begin
、
、
、
ByteCount:= StreamLen;
ByteReceive:=0;
while StreamLen > 0 do
begin
RetLen := FSocket.ReceiveBuf(P^, StreamLen);
if RetLen = 0 then
raise ESocketConnectionError.CreateRes(@SSocketReadError);
if RetLen > 0 then
begin
Inc(ByteReceive,RetLen);
[green] if Assigned(FOnDataReserved) then
FOnDataReserved(self, ByteReceive, ByteCount);[/green]
Dec(StreamLen, RetLen);
Inc(Integer(P), RetLen);
end;
end;
[green]但这下面的就没法加代码处理了![/green]
function TSocketTransport.Send(const Data: IDataBlock): Integer;
var
P: Pointer;
begin
Result := 0;
InterceptOutgoing(Data);
P := Data.Memory;
FSocket.SendBuf(P^, Data.Size + Data.BytesReserved);
end;