Gnash  0.8.11dev
Socket.h
Go to the documentation of this file.
1 // Socket.h - a virtual IO channel, for Gnash
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 
21 #ifndef GNASH_SOCKET_H
22 #define GNASH_SOCKET_H
23 
24 #include "dsodefs.h"
25 #include <cstdint>
26 #include "IOChannel.h"
27 
28 namespace gnash {
29  class URL;
30 }
31 
32 namespace gnash {
33 
35 //
41 class DSOEXPORT Socket : public IOChannel
42 {
43 public:
44 
46  Socket();
47 
48  virtual ~Socket() {}
49 
51  //
55  //
59  bool connect(const std::string& hostname, std::uint16_t port);
60 
62  //
65  void close();
66 
68  //
72  bool connected() const;
73 
75  //
79  virtual bool bad() const {
80  return _error;
81  }
82 
84  //
85  virtual std::streamsize read(void* dst, std::streamsize num);
86 
88  virtual std::streamsize readNonBlocking(void* dst, std::streamsize num);
89 
91  //
94  //
96  virtual std::streamsize write(const void* src, std::streamsize num);
97 
99  //
101  virtual std::streampos tell() const;
102 
104  //
106  virtual bool seek(std::streampos p);
107 
109  //
111  virtual void go_to_end();
112 
114  //
118  virtual bool eof() const;
119 
120 private:
121 
123  void fillCache();
124 
125  mutable bool _connected;
126 
128  char _cache[16384];
129 
131  int _socket;
132 
134  int _size;
135 
137  size_t _pos;
138 
139  mutable bool _error;
140 };
141 
142 } // namespace gnash
143 
144 #endif // GNASH_IOCHANNEL_H
145 
146 // Local Variables:
147 // mode: C++
148 // indent-tabs-mode: nil
149 // End:
A virtual IO channel.
Definition: IOChannel.h:42
void write(SimpleBuffer &buf, const std::string &str)
Write a string to an AMF buffer.
Definition: AMF.cpp:161
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
A simple IOChannel subclass for reading and writing sockets.
Definition: Socket.h:41
virtual ~Socket()
Definition: Socket.h:48
#define DSOEXPORT
Definition: dsodefs.h:55
Definition: GnashKey.h:162
virtual bool bad() const
True if the Socket is in an error condition.
Definition: Socket.h:79