You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.0 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: socketbuffer.h
  4. // Created: 5/2003
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2003-2010 Tad E. Smith
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_
  23. #define LOG4CPLUS_HELPERS_SOCKET_BUFFER_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/tstring.h>
  29. namespace log4cplus {
  30. namespace helpers {
  31. /**
  32. *
  33. */
  34. class LOG4CPLUS_EXPORT SocketBuffer
  35. {
  36. public:
  37. explicit SocketBuffer(std::size_t max);
  38. virtual ~SocketBuffer();
  39. char *getBuffer() const { return buffer; }
  40. std::size_t getMaxSize() const { return maxsize; }
  41. std::size_t getSize() const { return size; }
  42. void setSize(std::size_t s) { size = s; }
  43. std::size_t getPos() const { return pos; }
  44. unsigned char readByte();
  45. unsigned short readShort();
  46. unsigned int readInt();
  47. tstring readString(unsigned char sizeOfChar);
  48. void appendByte(unsigned char val);
  49. void appendShort(unsigned short val);
  50. void appendInt(unsigned int val);
  51. void appendString(const tstring& str);
  52. void appendBuffer(const SocketBuffer& buffer);
  53. private:
  54. // Data
  55. std::size_t maxsize;
  56. std::size_t size;
  57. std::size_t pos;
  58. char *buffer;
  59. SocketBuffer(SocketBuffer const & rhs);
  60. SocketBuffer& operator= (SocketBuffer const& rhs);
  61. };
  62. } // end namespace helpers
  63. } // end namespace log4cplus
  64. #endif // LOG4CPLUS_HELPERS_SOCKET_HEADER_