IdTCPStream.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.13 27.08.2004 21:58:22 Andreas Hausladen
  18. Speed optimization ("const" for string parameters)
  19. Rev 1.12 29/05/2004 21:17:48 CCostelloe
  20. ReadLnSplit added, needed for binary attachments
  21. Rev 1.11 28/05/2004 20:30:12 CCostelloe
  22. Bug fix
  23. Rev 1.10 2004.05.21 8:22:16 PM czhower
  24. Added ReadLn
  25. Rev 1.9 2004.05.20 1:40:00 PM czhower
  26. Last of the IdStream updates
  27. Rev 1.8 2004.03.07 11:48:46 AM czhower
  28. Flushbuffer fix + other minor ones found
  29. Rev 1.7 2004.02.03 4:16:58 PM czhower
  30. For unit name changes.
  31. Rev 1.6 5/12/2003 9:17:58 AM GGrieve
  32. remove dead code
  33. Rev 1.5 5/12/2003 12:32:14 AM GGrieve
  34. Refactor to work under DotNet
  35. Rev 1.4 10/10/2003 11:04:24 PM BGooijen
  36. DotNet
  37. Rev 1.3 9/10/2003 1:50:50 PM SGrobety
  38. DotNet
  39. Rev 1.2 2003.10.01 11:16:38 AM czhower
  40. .Net
  41. Rev 1.1 2003.10.01 1:37:36 AM czhower
  42. .Net
  43. Rev 1.0 11/13/2002 09:01:04 AM JPMugaas
  44. }
  45. unit IdTCPStream;
  46. interface
  47. {$I IdCompilerDefines.inc}
  48. //TODO: This should be renamed to IdStreamTCP for consistency, and class too
  49. uses
  50. Classes,
  51. IdGlobal, IdTCPConnection;
  52. type
  53. TIdTCPStream = class(TIdBaseStream)
  54. protected
  55. FConnection: TIdTCPConnection;
  56. FWriteThreshold: Integer;
  57. FWriteBuffering: Boolean;
  58. function IdRead(var VBuffer: TIdBytes; AOffset, ACount: Longint): Longint; override;
  59. function IdWrite(const ABuffer: TIdBytes; AOffset, ACount: Longint): Longint; override;
  60. function IdSeek(const AOffset: Int64; AOrigin: TSeekOrigin): Int64; override;
  61. procedure IdSetSize(ASize: Int64); override;
  62. public
  63. constructor Create(AConnection: TIdTCPConnection; const AWriteThreshold: Integer = 0); reintroduce;
  64. destructor Destroy; override;
  65. property Connection: TIdTCPConnection read FConnection;
  66. end;
  67. implementation
  68. uses
  69. SysUtils;
  70. constructor TIdTCPStream.Create(AConnection: TIdTCPConnection; const AWriteThreshold: Integer = 0);
  71. begin
  72. inherited Create;
  73. FConnection := AConnection;
  74. FWriteThreshold := AWriteThreshold;
  75. end;
  76. destructor TIdTCPStream.Destroy;
  77. begin
  78. if FWriteBuffering then begin
  79. Connection.IOHandler.WriteBufferClose;
  80. end;
  81. inherited Destroy;
  82. end;
  83. function TIdTCPStream.IdRead(var VBuffer: TIdBytes; AOffset, ACount: Longint): Longint;
  84. begin
  85. if AOffset <> 0 then begin
  86. ToDo('IdRead() method of TIdTCPStream class does not support seeking'); {do not localized}
  87. end;
  88. Connection.IOHandler.ReadBytes(VBuffer, ACount, False);
  89. Result := ACount;
  90. end;
  91. function TIdTCPStream.IdSeek(const AOffset: Int64; AOrigin: TSeekOrigin): Int64;
  92. begin
  93. Result := 0;
  94. end;
  95. procedure TIdTCPStream.IdSetSize(ASize: Int64);
  96. begin
  97. //
  98. end;
  99. function TIdTCPStream.IdWrite(const ABuffer: TIdBytes; AOffset, ACount: Longint): Longint;
  100. begin
  101. if (not FWriteBuffering) and (FWriteThreshold > 0) and (not Connection.IOHandler.WriteBufferingActive) then begin
  102. Connection.IOHandler.WriteBufferOpen(FWriteThreshold);
  103. FWriteBuffering := True;
  104. end;
  105. Connection.IOHandler.Write(ABuffer, ACount, AOffset);
  106. Result := ACount;
  107. end;
  108. end.