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