PipeStream.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // PipeStream.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/PipeStream.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Processes
  8. // Module: PipeStream
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/PipeStream.h"
  16. namespace Poco {
  17. //
  18. // PipeStreamBuf
  19. //
  20. PipeStreamBuf::PipeStreamBuf(const Pipe& pipe, openmode mode):
  21. BufferedStreamBuf(STREAM_BUFFER_SIZE, mode),
  22. _pipe(pipe)
  23. {
  24. }
  25. PipeStreamBuf::~PipeStreamBuf()
  26. {
  27. }
  28. int PipeStreamBuf::readFromDevice(char* buffer, std::streamsize length)
  29. {
  30. return _pipe.readBytes(buffer, (int) length);
  31. }
  32. int PipeStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
  33. {
  34. return _pipe.writeBytes(buffer, (int) length);
  35. }
  36. void PipeStreamBuf::close()
  37. {
  38. _pipe.close(Pipe::CLOSE_BOTH);
  39. }
  40. //
  41. // PipeIOS
  42. //
  43. PipeIOS::PipeIOS(const Pipe& pipe, openmode mode):
  44. _buf(pipe, mode)
  45. {
  46. poco_ios_init(&_buf);
  47. }
  48. PipeIOS::~PipeIOS()
  49. {
  50. try
  51. {
  52. _buf.sync();
  53. }
  54. catch (...)
  55. {
  56. }
  57. }
  58. PipeStreamBuf* PipeIOS::rdbuf()
  59. {
  60. return &_buf;
  61. }
  62. void PipeIOS::close()
  63. {
  64. _buf.sync();
  65. _buf.close();
  66. }
  67. //
  68. // PipeOutputStream
  69. //
  70. PipeOutputStream::PipeOutputStream(const Pipe& pipe):
  71. PipeIOS(pipe, std::ios::out),
  72. std::ostream(&_buf)
  73. {
  74. }
  75. PipeOutputStream::~PipeOutputStream()
  76. {
  77. }
  78. //
  79. // PipeInputStream
  80. //
  81. PipeInputStream::PipeInputStream(const Pipe& pipe):
  82. PipeIOS(pipe, std::ios::in),
  83. std::istream(&_buf)
  84. {
  85. }
  86. PipeInputStream::~PipeInputStream()
  87. {
  88. }
  89. } // namespace Poco