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:
gnash::LogFile::getDefaultInstance
static LogFile & getDefaultInstance()
Definition: log.cpp:77
gnash::Socket::readNonBlocking
virtual std::streamsize readNonBlocking(void *dst, std::streamsize num)
Read up to the given number of bytes from the Socket.
Definition: Socket.cpp:317
gnash::Socket::tell
virtual std::streampos tell() const
Return current stream position.
Definition: Socket.cpp:395
gnash::arraySize
size_t arraySize(T(&)[N])
Get the size of an array without passing a pointer by mistake.
Definition: GnashAlgorithm.h:58
dsodefs.h
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
_
#define _(String)
Definition: log.h:44
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
utility.h
gnash::Socket::eof
virtual bool eof() const
Return true if the end of the stream has been reached.
Definition: Socket.cpp:415
start
@ start
Definition: klash_part.cpp:330
gnash::Socket::~Socket
virtual ~Socket()
Definition: Socket.h:48
gnash::Socket::connected
bool connected() const
Whether a connection attempt is complete.
Definition: Socket.cpp:50
gnash::Socket::go_to_end
virtual void go_to_end()
Seek to the end of the stream.
Definition: Socket.cpp:409
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::Socket::seek
virtual bool seek(std::streampos p)
Seek to the specified position.
Definition: Socket.cpp:402
gnash::IOChannel
A virtual IO channel.
Definition: IOChannel.h:43
gnash::amf::write
void write(SimpleBuffer &buf, const std::string &str)
Write a string to an AMF buffer.
Definition: AMF.cpp:161
Socket.h
GnashSystemNetHeaders.h
GnashAlgorithm.h
gnash::key::code
code
Definition: GnashKey.h:44
gnash::Socket
A simple IOChannel subclass for reading and writing sockets.
Definition: Socket.h:42
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::Socket::read
virtual std::streamsize read(void *dst, std::streamsize num)
Read exactly the given number of bytes from the Socket or none at all.
Definition: Socket.cpp:302
gnash::Socket::write
virtual std::streamsize write(const void *src, std::streamsize num)
Write the given number of bytes to the stream.
Definition: Socket.cpp:355
log.h
gnash::Socket::close
void close()
Close the Socket.
Definition: Socket.cpp:114
gnashconfig.h
DSOEXPORT
#define DSOEXPORT
Definition: dsodefs.h:55
gnash::Socket::connect
bool connect(const std::string &hostname, std::uint16_t port)
Initiate a connection.
Definition: Socket.cpp:147
GnashSystemFDHeaders.h
gnash::Socket::Socket
Socket()
Create a non-connected socket.
Definition: Socket.cpp:40
IOChannel.h
gnash::Socket::bad
virtual bool bad() const
True if the Socket is in an error condition.
Definition: Socket.h:79