Easy Simple Network Library  0.3.7
All Classes Functions Modules
IoBuffer.h
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of "esnetwork" library.
4 It is licensed under the terms of the BSD license.
5 For the latest info, see http://esnetwork.sourceforge.net
6 
7 Copyright (c) 2012-2013 Lin Jia Jun (Joe Lam)
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 
13 1. Redistributions of source code must retain the above copyright notice, this
14  list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 -----------------------------------------------------------------------------
30 */
31 
32 #ifndef _ESN_IOBUFFER_H_
33 #define _ESN_IOBUFFER_H_
34 
35 #include <deque>
36 
37 #include "Buffer.h"
38 #include "Session.h"
39 
40 #ifndef ESN_MAX_IOBUF_SIZE
41 #define ESN_MAX_IOBUF_SIZE 1024 * 1024 * 256
42 #endif
43 
44 #ifndef ESN_DEFAULT_IOBUF_SIZE
45 #define ESN_DEFAULT_IOBUF_SIZE 2048
46 #endif
47 
48 namespace esnlib
49 {
50 
52 class IoBuffer : public Buffer
53 {
54 public:
55 
57  IoBuffer();
58 
63  IoBuffer(const char* buf, int bufsize);
64 
68  explicit IoBuffer(int size);
69 
73  explicit IoBuffer(const IoBuffer& src);
74 
76  virtual ~IoBuffer();
77 
81  const char* data() const;
82 
86  char* data();
87 
91  int size() const;
92 
97  int size(int value);
98 
102  int flag() const;
103 
107  void flag(int value);
108 
112  int code() const;
113 
117  void code(int value);
118 
122  int type() const;
123 
127  void type(int value);
128 
132  int state() const;
133 
137  void state(int value);
138 
142  bool anysize() const;
143 
147  SessionPtr session();
148 
152  void session(SessionPtr value);
153 
157  int GetReadPos();
158 
162  void SetReadPos(int pos);
163 
167  int GetWritePos();
168 
172  void SetWritePos(int pos);
173 
177  char GetByte();
178 
182  short GetShort();
183 
187  int GetInt();
188 
192  double GetDouble();
193 
199  int GetBuf(char* buf, int len);
200 
205  std::string GetStr(int len);
206 
210  void PutByte(char value);
211 
215  void PutShort(int value);
216 
220  void PutInt(int value);
221 
225  void PutDouble(double value);
226 
231  void PutBuf(char* buf, int len);
232 
236  void PutStr(const std::string& value);
237 
238 protected:
239 
240 private:
241  char* m_data;
242 
243  int m_size;
244  int m_max;
245 
246  int m_code;
247  int m_flag;
248  int m_type;
249  int m_state;
250 
251  int m_default;
252 
253  int m_readpos;
254  int m_writepos;
255 
256  SessionRef m_session;
257 
258 };
259 
260 typedef boost::shared_ptr<IoBuffer> IoBufferPtr;
261 
262 typedef std::deque<IoBufferPtr> IoBufferQueue;
263 
264 }
265 
266 #endif // _ESN_IOBUFFER_H_
267 
int type() const
void PutInt(int value)
IoBuffer()
Constructor function.
std::string GetStr(int len)
int size() const
const char * data() const
virtual ~IoBuffer()
Destructor function.
void SetReadPos(int pos)
void PutByte(char value)
SessionPtr session()
int GetBuf(char *buf, int len)
void SetWritePos(int pos)
int flag() const
int code() const
void PutDouble(double value)
void PutShort(int value)
Buffer class.
Definition: Buffer.h:40
bool anysize() const
void PutStr(const std::string &value)
double GetDouble()
Definition: Buffer.h:37
int state() const
IO Buffer class.
Definition: IoBuffer.h:52
void PutBuf(char *buf, int len)