Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef mozilla_ipc_UnixFdWatcher_h |
michael@0 | 8 | #define mozilla_ipc_UnixFdWatcher_h |
michael@0 | 9 | |
michael@0 | 10 | #include "base/message_loop.h" |
michael@0 | 11 | #include "mozilla/FileUtils.h" |
michael@0 | 12 | |
michael@0 | 13 | namespace mozilla { |
michael@0 | 14 | namespace ipc { |
michael@0 | 15 | |
michael@0 | 16 | class UnixFdWatcher : public MessageLoopForIO::Watcher |
michael@0 | 17 | { |
michael@0 | 18 | public: |
michael@0 | 19 | enum { |
michael@0 | 20 | READ_WATCHER = 1<<0, |
michael@0 | 21 | WRITE_WATCHER = 1<<1 |
michael@0 | 22 | }; |
michael@0 | 23 | |
michael@0 | 24 | virtual ~UnixFdWatcher(); |
michael@0 | 25 | |
michael@0 | 26 | MessageLoop* GetIOLoop() const |
michael@0 | 27 | { |
michael@0 | 28 | return mIOLoop; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | int GetFd() const |
michael@0 | 32 | { |
michael@0 | 33 | return mFd; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | bool IsOpen() const |
michael@0 | 37 | { |
michael@0 | 38 | return GetFd() >= 0; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | virtual void Close(); |
michael@0 | 42 | |
michael@0 | 43 | void AddWatchers(unsigned long aWatchers, bool aPersistent); |
michael@0 | 44 | void RemoveWatchers(unsigned long aWatchers); |
michael@0 | 45 | |
michael@0 | 46 | // Callback method that's run before closing the file descriptor |
michael@0 | 47 | virtual void OnClose() {}; |
michael@0 | 48 | |
michael@0 | 49 | // Callback method that's run on POSIX errors |
michael@0 | 50 | virtual void OnError(const char* aFunction, int aErrno); |
michael@0 | 51 | |
michael@0 | 52 | protected: |
michael@0 | 53 | UnixFdWatcher(MessageLoop* aIOLoop); |
michael@0 | 54 | UnixFdWatcher(MessageLoop* aIOLoop, int aFd); |
michael@0 | 55 | void SetFd(int aFd); |
michael@0 | 56 | |
michael@0 | 57 | private: |
michael@0 | 58 | static bool FdIsNonBlocking(int aFd); |
michael@0 | 59 | |
michael@0 | 60 | MessageLoop* mIOLoop; |
michael@0 | 61 | ScopedClose mFd; |
michael@0 | 62 | MessageLoopForIO::FileDescriptorWatcher mReadWatcher; |
michael@0 | 63 | MessageLoopForIO::FileDescriptorWatcher mWriteWatcher; |
michael@0 | 64 | }; |
michael@0 | 65 | |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | #endif |