// // mp::ipc_vector // // Copyright (C) 2008 FURUHASHI Sadayuki // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef MP_IPC_VECTOR_H__ #define MP_IPC_VECTOR_H__ #include "mp/exception.h" #include #include #include #include #include namespace mp { struct ipc_vector_error : system_error { ipc_vector_error(int errno_, const std::string& msg) : system_error(errno, msg) {} }; class ipc_vector { private: class base; public: class server; class client; class buffer; private: ipc_vector(); }; class ipc_vector::base { protected: base(); ~base(); public: void receive(buffer& result); bool try_receive(buffer& result); void push(const char* ptr, size_t size); protected: void expand_map(size_t size); void reserve_map(size_t size); sem_t* ctlmap_lock(); sem_t* ctlmap_notify(); volatile size_t* ctlmap_size(); protected: class sem_scoped_lock; char* m_ctlmap; char* m_vecmap; size_t m_vecmap_size; int m_fd; static const size_t CTL_RESERVE_SIZE; private: base(const base&); }; class ipc_vector::server : private base { public: server(const char* path, mode_t create_mode = S_IRWXU); ~server(); public: void receive(buffer& result); bool try_receive(buffer& result); void push(const char* ptr, size_t size); private: std::string m_path; private: server(); server(const server&); }; class ipc_vector::client : private base { public: client(const char* path); ~client(); public: void receive(buffer& result); bool try_receive(buffer& result); void push(const char* ptr, size_t size); private: client(); client(const client&); }; } // namespace mp #include "ipc_vector_impl.h" #endif /* mp/ipc_vector.h */