// // mp::fdnotify // // 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_FDNOTIFY_H__ #define MP_FDNOTIFY_H__ #include "mp/exception.h" #ifndef MP_FDNOTIFY_VECTOR_SIZE #define MP_FDNOTIFY_VECTOR_SIZE 32 #endif namespace mp { struct fdnotify_error : system_error { fdnotify_error(int errno_, const std::string& msg) : system_error(errno_, msg) {} }; // Note that NotifyObject must be a POD template class fdnotify { public: fdnotify(); ~fdnotify(); public: int getfd() const { return m_pipe[0]; } bool try_receive(NotifyObject* result); void send(const NotifyObject& obj); private: int m_pipe[2]; char m_buffer[sizeof(NotifyObject)*MP_FDNOTIFY_VECTOR_SIZE]; char* m_head; char* m_tail; private: bool receive_next(NotifyObject* result); private: fdnotify(const fdnotify&); }; } // namespace mp #include "mp/fdnotify_impl.h" #endif /* mp/fdnotify.h */