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 <boost/cstdint.hpp>
26 #include <boost/shared_ptr.hpp>
27 #include "IOChannel.h"
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netdb.h>
31 
32 namespace gnash {
33  class URL;
34 }
35 
36 namespace gnash {
37 
39 //
45 class DSOEXPORT Socket : public IOChannel
46 {
47 public:
48 
50  Socket();
51 
52  virtual ~Socket() {}
53 
55  //
59  //
63  bool connect(const std::string& hostname, boost::uint16_t port);
64 
66  //
69  void close();
70 
72  //
76  bool connected() const;
77 
79  //
83  virtual bool bad() const {
84  return _error;
85  }
86 
88  //
89  virtual std::streamsize read(void* dst, std::streamsize num);
90 
92  virtual std::streamsize readNonBlocking(void* dst, std::streamsize num);
93 
95  //
98  //
100  virtual std::streamsize write(const void* src, std::streamsize num);
101 
103  //
105  virtual std::streampos tell() const;
106 
108  //
110  virtual bool seek(std::streampos p);
111 
113  //
115  virtual void go_to_end();
116 
118  //
122  virtual bool eof() const;
123 
124 private:
125 
126  // Return the string representation of the IPV4 or IPV6 number
127  boost::shared_ptr<char> getIPString(struct addrinfo *ai);
128 
130  void fillCache();
131 
132  mutable bool _connected;
133 
135  char _cache[16384];
136 
138  int _socket;
139 
141  int _size;
142 
144  size_t _pos;
145 
146  mutable bool _error;
147 };
148 
149 } // namespace gnash
150 
151 #endif // GNASH_IOCHANNEL_H
152 
153 // Local Variables:
154 // mode: C++
155 // indent-tabs-mode: nil
156 // End: