Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 08:49:24

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2009. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_XSI_KEY_HPP
0012 #define BOOST_INTERPROCESS_XSI_KEY_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 #include <boost/detail/workaround.hpp>
0026 
0027 #if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
0028 #error "This header can't be used in operating systems without XSI (System V) shared memory support"
0029 #endif
0030 
0031 #include <boost/interprocess/creation_tags.hpp>
0032 #include <boost/interprocess/exceptions.hpp>
0033 #include <boost/interprocess/detail/utilities.hpp>
0034 #include <boost/move/utility_core.hpp>
0035 #include <boost/interprocess/detail/os_file_functions.hpp>
0036 #include <boost/interprocess/interprocess_fwd.hpp>
0037 #include <boost/interprocess/exceptions.hpp>
0038 #include <sys/types.h>
0039 #include <sys/ipc.h>
0040 #include <cstddef>
0041 #include <boost/cstdint.hpp>
0042 
0043 //!\file
0044 //!Describes a class representing a xsi key type.
0045 
0046 namespace boost {
0047 namespace interprocess {
0048 
0049 //!A class that wraps XSI (System V) key_t type.
0050 //!This type calculates key_t from path and id using ftok,
0051 //!sets key to a specified value,
0052 //!or sets key to IPC_PRIVATE using the default constructor.
0053 class xsi_key
0054 {
0055    public:
0056 
0057    //!Default constructor.
0058    //!Represents a private xsi_key.
0059    xsi_key()
0060       : m_key(IPC_PRIVATE)
0061    {}
0062 
0063    //!Creates a new XSI key using a specified value. Constructor is explicit to avoid ambiguity with shmid.
0064    explicit xsi_key(key_t key)
0065       : m_key(key)
0066    {}
0067 
0068    //!Creates a new XSI  shared memory with a key obtained from a call to ftok (with path
0069    //!"path" and id "id"), of size "size" and permissions "perm".
0070    //!If the shared memory previously exists, throws an error.
0071    xsi_key(const char *path, boost::uint8_t id)
0072    {
0073       key_t key;
0074       if(path){
0075          key  = ::ftok(path, id);
0076          if(((key_t)-1) == key){
0077             error_info err = system_error_code();
0078             throw interprocess_exception(err);
0079          }
0080       }
0081       else{
0082          key = IPC_PRIVATE;
0083       }
0084       m_key = key;
0085    }
0086 
0087    //!Returns the internal key_t value
0088    key_t get_key() const
0089    {  return m_key;  }
0090 
0091    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0092    private:
0093    key_t m_key;
0094    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0095 };
0096 
0097 }  //namespace interprocess {
0098 }  //namespace boost {
0099 
0100 #include <boost/interprocess/detail/config_end.hpp>
0101 
0102 #endif   //BOOST_INTERPROCESS_XSI_KEY_HPP