Ignore:
Timestamp:
Aug 14, 2012, 10:31:30 AM (12 years ago)
Author:
chronos
Message:
  • Modified: PinConnection package now use for data parameters TListByte instead of TStream class contained in TemplateGenerics package. TStream have Position property which has no meaning for forwarding plain byte memory block. There is TBinarySerializer class used for serializing data instead of TStreamHelper class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/UPacketBurst.pas

    r231 r407  
    66
    77uses
    8   Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils,
    9   DateUtils;
     8  Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils, SpecializedList,
     9  DateUtils, UBinarySerializer;
    1010
    1111type
     
    2525    SendThread: TPacketBurstSendThread;
    2626    SendStreamLock: TCriticalSection;
    27     SendStream: TStreamHelper;
    28     ReceiveStream: TStreamHelper;
    29     procedure PacketSingleReceive(Sender: TCommPin; Stream: TStream);
    30     procedure PacketBurstReceive(Sender: TCommPin; Stream: TStream);
     27    SendStream: TBinarySerializer;
     28    ReceiveStream: TBinarySerializer;
     29    procedure PacketSingleReceive(Sender: TCommPin; Stream: TListByte);
     30    procedure PacketBurstReceive(Sender: TCommPin; Stream: TListByte);
    3131    procedure SetActive(const AValue: Boolean);
    3232  public
     
    6363end;
    6464
    65 procedure TPacketBurst.PacketBurstReceive(Sender: TCommPin; Stream: TStream);
     65procedure TPacketBurst.PacketBurstReceive(Sender: TCommPin; Stream: TListByte);
    6666var
    67   PacketStream: TStreamHelper;
     67  PacketStream: TListByte;
    6868  Size: Word;
    6969begin
    7070  try
    71     PacketStream := TStreamHelper.Create;
    72     ReceiveStream.Seek(0, soFromEnd);
    73     ReceiveStream.WriteStream(Stream, Stream.Size);
     71    PacketStream := TListByte.Create;
     72    ReceiveStream.Position := ReceiveStream.List.Count;
     73    ReceiveStream.WriteList(Stream, 0, Stream.Count);
    7474    ReceiveStream.Position := 0;
    7575    Size := ReceiveStream.ReadWord;
    76     while Size < ReceiveStream.Size do begin
    77       PacketStream.Stream.Size := 0;
    78       PacketStream.ReadStream(TStream(ReceiveStream), Size);
     76    while Size < ReceiveStream.List.Count do begin
     77      PacketStream.Count := Size;
     78      ReceiveStream.ReadList(PacketStream, 0, Size);
    7979      PacketSinglePin.Send(PacketStream);
    8080      Size := ReceiveStream.ReadWord;
     
    100100end;
    101101
    102 procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: TStream);
     102procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: TListByte);
    103103var
    104104  SignalEvent: Boolean;
     
    106106  try
    107107    SendStreamLock.Acquire;
    108     SendStream.WriteWord(Stream.Size);
    109     Stream.Position := 0;
    110     SendStream.WriteStream(Stream, Stream.Size);
    111     SignalEvent := SendStream.Size > SendBurstSize;
     108    SendStream.WriteWord(Stream.Count);
     109    SendStream.WriteList(Stream, 0, Stream.Count);
     110    SignalEvent := SendStream.List.Count > SendBurstSize;
    112111  finally
    113112    SendStreamLock.Release;
     
    120119procedure TPacketBurstSendThread.Execute;
    121120var
    122   Stream: TStreamHelper;
     121  Stream: TListByte;
    123122begin
    124123  try
    125     Stream := TStreamHelper.Create;
     124    Stream := TListByte.Create;
    126125    with PacketBurst do
    127126    repeat
     
    130129        SendStreamLock.Acquire;
    131130        SendStream.Position := 0;
    132         if SendStream.Size < SendBurstSize then begin
    133           PacketBurstPin.Send(SendStream);
    134           SendStream.Stream.Size := 0;
     131        if SendStream.List.Count < SendBurstSize then begin
     132          PacketBurstPin.Send(SendStream.List);
     133          SendStream.List.Count := 0;
    135134        end else
    136         while (SendStream.Size - SendStream.Position) > SendBurstSize do begin
    137           Stream.Stream.Size := 0;
     135        while (SendStream.List.Count - SendStream.Position) > SendBurstSize do begin
     136          Stream.Count := 0;
    138137          SendStream.ReadStream(TStream(Stream), SendBurstSize);
    139138          PacketBurstPin.Send(Stream);
Note: See TracChangeset for help on using the changeset viewer.