Bumping manifests a=b2g-bump
[gecko.git] / ipc / unixfd / UnixFdWatcher.h
blob676b1dbf0bcaf1d126da7490676496ff1010821e
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
18 public:
19 enum {
20 READ_WATCHER = 1<<0,
21 WRITE_WATCHER = 1<<1
24 virtual ~UnixFdWatcher();
26 MessageLoop* GetIOLoop() const
28 return mIOLoop;
31 int GetFd() const
33 return mFd;
36 bool IsOpen() const
38 return GetFd() >= 0;
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;
69 #endif