Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

socket.hh

Go to the documentation of this file.
00001 // Copyright (C) 2003, 2004, 2005 Laboratoire de Recherche en Informatique
00002 
00003 // This file is part of Qolyester.
00004 
00005 // Qolyester is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 // Qolyester is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018 
00019 #include "config.hh"
00020 
00021 #ifndef QOLYESTER_ENABLE_VIRTUAL
00022 
00023 # include "sys/realinterfaceinfo.hh"
00024 
00025 # ifndef QOLYESTER_DAEMON_SYS_SOCKET_HH
00026 #  define QOLYESTER_DAEMON_SYS_SOCKET_HH 1
00027 
00028 #  include <sys/types.h>
00029 #  include <string>
00030 
00031 #  include "config.hh"
00032 
00033 #  include "net/ipaddress.hh"
00034 #  include "utl/data.hh"
00035 #  include "sch/scheduler.hh"
00036 
00037 namespace olsr {
00038 
00039   namespace sys {
00040 
00041     // Higher-than-address level socket definition.
00042     class Socket {
00043       typedef Socket    This;
00044       enum _dummy_values { _dummy_val };
00045       Socket(_dummy_values);
00046     public:
00047       // Some utility definitions
00048       typedef address_t::sockaddr_t     sockaddr_t;
00049       typedef address_t                 addr_t;
00050       typedef u_int16_t                 port_t;
00051 
00052       // Constructors, for each kind of funky use.
00053 
00054       Socket();
00055       Socket(unsigned mtu);
00056       Socket(unsigned mtu, const addr_t& addr, port_t port);
00057       Socket(unsigned mtu, const std::string& host, port_t port);
00058       Socket(unsigned mtu, const char* host, port_t port);
00059 
00060       void      close();
00061 
00062       unsigned  mtu() const { return _mtu; }
00063 
00064       void      set_mtu(unsigned mtu) { _mtu = mtu; }
00065 
00066       void      bind_to_device(const std::string& name);
00067 
00068       void      set_multicast(const RealInterfaceInfo& info);
00069 
00070       void      bind(const sockaddr_t& sin);
00071 
00072       void      bind_multicast(const RealInterfaceInfo& info,
00073                                const address_t& a, port_t port);
00074 
00075 #  if QOLYESTER_FAMILY_INET == 6
00076       void      bind(const addr_t& addr, port_t port, unsigned index = 0);
00077 #  else // QOLYESTER_FAMILY_INET != 6
00078       void      bind(const addr_t& addr, port_t port);
00079 #  endif
00080 
00081       void      connect(const sockaddr_t& sin);
00082 
00083       void      connect(const addr_t& addr, port_t port);
00084 
00085       utl::Data receive(address_t& sender) const;
00086 
00087       void      send(const utl::ConstData& d) const;
00088 
00089       void      set_baddr(const address_t& a) { _baddr = a; }
00090 
00091       void      sendto(const utl::ConstData& d,
00092                        const address_t::sockaddr_t& s) const;
00093 
00094       void      sendto_bcast(const utl::ConstData& d) const;
00095 
00096       sch::IOEvent::p_t read_p() const;
00097       sch::IOEvent::p_t write_p() const;
00098 
00099       bool      operator<(const This& rhs) const;
00100 
00101       static const This&        dummy() { return _dummy; }
00102 
00103     private:
00104 
00105       // Internal utility function used by constructors.
00106       void      init();
00107 
00108       int       _fd;
00109       unsigned  _mtu;
00110       address_t _baddr;
00111       unsigned  _index;
00112 
00113       static This       _dummy;
00114     };
00115 
00116   } // namespace sys
00117 
00118 } // namespace olsr
00119 
00120 #  include "socket.hxx"
00121 
00122 # endif // ! QOLYESTER_DAEMON_SYS_SOCKET_HH
00123 
00124 #endif // ! QOLYESTER_ENABLE_VIRTUAL

Generated on Thu Jul 28 21:21:48 2005 for Qolyester daemon by  doxygen 1.4.1