conn.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "conn.h"
  2. #include <util/network/socket.h>
  3. #include <util/stream/buffered.h>
  4. class THttpServerConn::TImpl {
  5. public:
  6. inline TImpl(const TSocket& s, size_t outputBufferSize)
  7. : S_(s)
  8. , SI_(S_)
  9. , SO_(S_)
  10. , BO_(&SO_, outputBufferSize)
  11. , HI_(&SI_)
  12. , HO_(&BO_, &HI_)
  13. {
  14. }
  15. inline ~TImpl() {
  16. }
  17. inline THttpInput* Input() noexcept {
  18. return &HI_;
  19. }
  20. inline THttpOutput* Output() noexcept {
  21. return &HO_;
  22. }
  23. inline void Reset() {
  24. if (S_ != INVALID_SOCKET) {
  25. // send RST packet to client
  26. S_.SetLinger(true, 0);
  27. S_.Close();
  28. }
  29. }
  30. private:
  31. TSocket S_;
  32. TSocketInput SI_;
  33. TSocketOutput SO_;
  34. TBufferedOutput BO_;
  35. THttpInput HI_;
  36. THttpOutput HO_;
  37. };
  38. THttpServerConn::THttpServerConn(const TSocket& s)
  39. : THttpServerConn(s, s.MaximumTransferUnit())
  40. {
  41. }
  42. THttpServerConn::THttpServerConn(const TSocket& s, size_t outputBufferSize)
  43. : Impl_(new TImpl(s, outputBufferSize))
  44. {
  45. }
  46. THttpServerConn::~THttpServerConn() {
  47. }
  48. THttpInput* THttpServerConn::Input() noexcept {
  49. return Impl_->Input();
  50. }
  51. THttpOutput* THttpServerConn::Output() noexcept {
  52. return Impl_->Output();
  53. }
  54. void THttpServerConn::Reset() {
  55. return Impl_->Reset();
  56. }