socket.hh

Go to the documentation of this file.
00001 // Copyright (C) 2003-2006 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,
00018 // Boston, MA  02110-1301, USA.
00019 
00020 #include "config.hh"
00021 
00022 #ifndef QOLYESTER_ENABLE_VIRTUAL
00023 
00024 # include "sys/realinterfaceinfo.hh"
00025 
00026 # ifndef QOLYESTER_DAEMON_SYS_SOCKET_HH
00027 #  define QOLYESTER_DAEMON_SYS_SOCKET_HH 1
00028 
00029 #  include <sys/types.h>
00030 #  include <string>
00031 
00032 #  include "config.hh"
00033 
00034 #  include "net/ipaddress.hh"
00035 #  include "utl/data.hh"
00036 #  include "sch/scheduler.hh"
00037 
00038 namespace olsr {
00039 
00040   namespace sys {
00041 
00042     // Higher-than-address level socket definition.
00043     class Socket {
00044       typedef Socket    This;
00045       enum _dummy_values { _dummy_val };
00046       inline Socket(_dummy_values);
00047     public:
00048       // Some utility definitions
00049       typedef address_t::sockaddr_t     sockaddr_t;
00050       typedef address_t                 addr_t;
00051       typedef u_int16_t                 port_t;
00052 
00053       // Constructors, for each kind of funky use.
00054 
00055       inline Socket();
00056       inline Socket(unsigned mtu);
00057       inline Socket(unsigned mtu, const addr_t& addr, port_t port);
00058       inline Socket(unsigned mtu, const std::string& host, port_t port);
00059       inline Socket(unsigned mtu, const char* host, port_t port);
00060 
00061       inline void       close();
00062 
00063       unsigned  mtu() const { return _mtu; }
00064 
00065       void      set_mtu(unsigned mtu) { _mtu = mtu; }
00066 
00067       inline void       bind_to_device(const std::string& name);
00068 
00069       inline void       set_multicast(const RealInterfaceInfo& info);
00070 
00071       inline void       set_priority();
00072 
00073       inline void       bind(const sockaddr_t& sin);
00074 
00075       inline void       bind_multicast(const RealInterfaceInfo& info,
00076                                        const address_t& a, port_t port);
00077 
00078 #  if QOLYESTER_FAMILY_INET == 6
00079       inline void       bind(const addr_t& addr, port_t port,
00080                              unsigned index = 0);
00081 #  else // QOLYESTER_FAMILY_INET != 6
00082       inline void       bind(const addr_t& addr, port_t port);
00083 #  endif
00084 
00085       inline void       connect(const sockaddr_t& sin);
00086 
00087       inline void       connect(const addr_t& addr, port_t port);
00088 
00089       inline utl::Data  receive(address_t& sender) const;
00090 
00091       inline void       send(const utl::ConstData& d) const;
00092 
00093       void      set_baddr(const address_t& a) { _baddr = a; }
00094 
00095       inline void       sendto(const utl::ConstData& d,
00096                                const address_t::sockaddr_t& s) const;
00097 
00098       inline void       sendto_bcast(const utl::ConstData& d) const;
00099 
00100       inline sch::IOEvent::p_t  read_p() const;
00101       inline sch::IOEvent::p_t  write_p() const;
00102 
00103       inline bool       operator<(const This& rhs) const;
00104 
00105       static const This&        dummy() { return _dummy; }
00106 
00107     private:
00108 
00109       // Internal utility function used by constructors.
00110       void      init();
00111 
00112       int       _fd;
00113       unsigned  _mtu;
00114       address_t _baddr;
00115       unsigned  _index;
00116 
00117       static This       _dummy;
00118     };
00119 
00120   } // namespace sys
00121 
00122 } // namespace olsr
00123 
00124 #  include "socket.hxx"
00125 
00126 # endif // ! QOLYESTER_DAEMON_SYS_SOCKET_HH
00127 
00128 #endif // ! QOLYESTER_ENABLE_VIRTUAL

Generated on Mon Sep 4 00:02:16 2006 for Qolyester daemon by  doxygen 1.4.6