ucommon
buffer.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
2 //
3 // This file is part of GNU uCommon C++.
4 //
5 // GNU uCommon C++ is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // GNU uCommon C++ is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
17 
23 #ifndef _UCOMMON_BUFFER_H_
24 #define _UCOMMON_BUFFER_H_
25 
26 #ifndef _UCOMMON_CONFIG_H_
27 #include <ucommon/platform.h>
28 #endif
29 
30 #ifndef _UCOMMON_PROTOCOLS_H_
31 #include <ucommon/protocols.h>
32 #endif
33 
34 #ifndef _UCOMMON_SOCKET_H_
35 #include <ucommon/socket.h>
36 #endif
37 
38 #ifndef _UCOMMON_STRING_H_
39 #include <ucommon/string.h>
40 #endif
41 
42 #ifndef _UCOMMON_FSYS_H_
43 #include <ucommon/fsys.h>
44 #endif
45 
46 #ifndef _UCOMMON_SHELL_H_
47 #include <ucommon/shell.h>
48 #endif
49 
50 NAMESPACE_UCOMMON
51 
58 class __EXPORT TCPBuffer : public BufferProtocol, protected Socket
59 {
60 protected:
61  void _buffer(size_t size);
62 
63  virtual size_t _push(const char *address, size_t size);
64  virtual size_t _pull(char *address, size_t size);
65  int _err(void) const;
66  void _clear(void);
67  bool _blocking(void);
68 
73  inline socket_t getsocket(void) const
74  {return so;};
75 
76 public:
80  TCPBuffer();
81 
87  TCPBuffer(const TCPServer *server, size_t size = 536);
88 
95  TCPBuffer(const char *host, const char *service, size_t size = 536);
96 
100  virtual ~TCPBuffer();
101 
108  void open(const TCPServer *server, size_t size = 536);
109 
117  void open(const char *host, const char *service, size_t size = 536);
118 
122  void close(void);
123 
124 protected:
129  virtual bool _pending(void);
130 };
131 
135 typedef TCPBuffer tcp_t;
136 
137 END_NAMESPACE
138 
139 #endif