Gnash  0.8.10
Socket.h
Go to the documentation of this file.
00001 // Socket.h - a virtual IO channel, for Gnash
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00004 //   Free Software Foundation, Inc
00005 // 
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 
00021 #ifndef GNASH_SOCKET_H
00022 #define GNASH_SOCKET_H
00023 
00024 #include "dsodefs.h"
00025 #include <boost/cstdint.hpp>
00026 #include "IOChannel.h"
00027 
00028 namespace gnash {
00029     class URL;
00030 }
00031 
00032 namespace gnash {
00033 
00035 //
00041 class DSOEXPORT Socket : public IOChannel
00042 {
00043 public:
00044 
00046     Socket();
00047 
00048     virtual ~Socket() {}
00049 
00051     //
00055     //
00059     bool connect(const std::string& hostname, boost::uint16_t port);
00060 
00062     //
00065     void close();
00066 
00068     //
00072     bool connected() const;
00073     
00075     //
00079     virtual bool bad() const {
00080         return _error;
00081     }
00082 
00084     //
00085     virtual std::streamsize read(void* dst, std::streamsize num);
00086 
00088     virtual std::streamsize readNonBlocking(void* dst, std::streamsize num);
00089 
00091     //
00094     //
00096     virtual std::streamsize write(const void* src, std::streamsize num);
00097     
00099     //
00101     virtual std::streampos tell() const;
00102 
00104     //
00106     virtual bool seek(std::streampos p);
00107 
00109     //
00111     virtual void go_to_end();
00112 
00114     //
00118     virtual bool eof() const;
00119 
00120 private:
00121 
00123     void fillCache();
00124 
00125     mutable bool _connected;
00126 
00128     char _cache[16384];
00129 
00131     int _socket;
00132 
00134     int _size;
00135 
00137     size_t _pos;
00138 
00139     mutable bool _error;
00140 };
00141 
00142 } // namespace gnash
00143 
00144 #endif // GNASH_IOCHANNEL_H
00145 
00146 
00147 // Local Variables:
00148 // mode: C++
00149 // indent-tabs-mode: t
00150 // End: