unixsocket.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 
00026 
00027 #ifndef QOLYESTER_SYS_UNIXSOCKET_HH
00028 # define QOLYESTER_SYS_UNIXSOCKET_HH 1
00029 
00030 # include <sys/un.h>
00031 
00032 # ifndef UNIX_PATH_MAX
00033 #  define UNIX_PATH_MAX 108
00034 # endif
00035 
00036 # include "sch/scheduler.hh"
00037 # include "utl/data.hh"
00038 
00039 namespace olsr {
00040 
00041   namespace sys {
00042 
00043 # define UNIX_BACKLOG           100
00044 
00054 
00055     class UnixClosedConnection {};
00056 
00057     class UnixSocket {
00058       typedef UnixSocket        This;
00059       enum _dummy_values { _dummy_val };
00060 
00064       UnixSocket(_dummy_values);
00065 
00066       explicit inline UnixSocket(int fd);
00067     public:
00068 
00072       typedef struct ::sockaddr_un      sockaddr_t;
00076       typedef std::string               path_t;
00080       inline UnixSocket();
00081 //       ///
00082 //       /// A constructor to copy an object
00083 //       ///
00084 //       UnixSocket(const This& other);
00089       inline UnixSocket(const path_t& fname);
00090 
00091       virtual inline ~UnixSocket();
00092 
00093 //       ///
00094 //       /// Sets the socket to be blockant, default is to be non-blockant
00095 //       ///
00096 //       void set_blocking() { _non_blocking = false; }
00097 
00102       inline void       bind(const path_t& fname);
00103 
00104       inline void       listen();
00105 
00110       inline void       connect(const path_t& fname);
00111 
00112       inline This       accept(path_t& fname);
00113 
00114       inline void       close();
00115 //       ///
00116 //       /// listen primitive, deprecated because of using SOCK_DGRAM
00117 //       ///
00118 //       void   listen();
00119 //       ///
00120 //       /// accept primitive, deprecated because of using SOCK_DGRAM
00121 //       ///
00122 //       void   accept(const path_t& fname);
00123 
00129 //       utl::Data      receive(path_t& sender) const throw (errnoexcept_t);
00130       inline utl::Data  receive() const;
00131 
00136       inline bool       send(const utl::ConstData& d, int flags =  0) const;
00137 //       ///
00138 //       /// sendto primitive, sends a packet to a specified filename
00139 //       /// @arg d the data to send
00140 //       /// @arg fname the destination
00141 //       ///
00142 //       void   sendto(const utl::ConstData& d, const path_t& fname) const throw (errnoexcept_t);
00143 
00144       inline sch::IOEvent::p_t  read_p() const;
00145       inline sch::IOEvent::p_t  write_p() const;
00146 
00152       inline bool       operator<(const This& rhs) const;
00153 
00158       static const This&        dummy() { return _dummy; }
00159 
00160       static void       lock() {
00161         _locked = true;
00162       }
00163 
00164     private:
00165 
00169       inline void init();
00170 
00171       int               _fd;            
00172       bool              _bound;
00173 
00174       static bool       _locked;
00175       static This       _dummy;         
00176     };
00177 
00178     bool        UnixSocket::_locked = 0;
00179 
00180   } // namespace sys
00181 
00182 } // namespace olsr
00183 
00184 # include "unixsocket.hxx"
00185 
00186 #endif // ! QOLYESTER_SYS_UNIXSOCKET_HH

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