ipc/unixfd/UnixFdWatcher.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/unixfd/UnixFdWatcher.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_ipc_UnixFdWatcher_h
    1.11 +#define mozilla_ipc_UnixFdWatcher_h
    1.12 +
    1.13 +#include "base/message_loop.h"
    1.14 +#include "mozilla/FileUtils.h"
    1.15 +
    1.16 +namespace mozilla {
    1.17 +namespace ipc {
    1.18 +
    1.19 +class UnixFdWatcher : public MessageLoopForIO::Watcher
    1.20 +{
    1.21 +public:
    1.22 +  enum {
    1.23 +    READ_WATCHER = 1<<0,
    1.24 +    WRITE_WATCHER = 1<<1
    1.25 +  };
    1.26 +
    1.27 +  virtual ~UnixFdWatcher();
    1.28 +
    1.29 +  MessageLoop* GetIOLoop() const
    1.30 +  {
    1.31 +    return mIOLoop;
    1.32 +  }
    1.33 +
    1.34 +  int GetFd() const
    1.35 +  {
    1.36 +    return mFd;
    1.37 +  }
    1.38 +
    1.39 +  bool IsOpen() const
    1.40 +  {
    1.41 +    return GetFd() >= 0;
    1.42 +  }
    1.43 +
    1.44 +  virtual void Close();
    1.45 +
    1.46 +  void AddWatchers(unsigned long aWatchers, bool aPersistent);
    1.47 +  void RemoveWatchers(unsigned long aWatchers);
    1.48 +
    1.49 +  // Callback method that's run before closing the file descriptor
    1.50 +  virtual void OnClose() {};
    1.51 +
    1.52 +  // Callback method that's run on POSIX errors
    1.53 +  virtual void OnError(const char* aFunction, int aErrno);
    1.54 +
    1.55 +protected:
    1.56 +  UnixFdWatcher(MessageLoop* aIOLoop);
    1.57 +  UnixFdWatcher(MessageLoop* aIOLoop, int aFd);
    1.58 +  void SetFd(int aFd);
    1.59 +
    1.60 +private:
    1.61 +  static bool FdIsNonBlocking(int aFd);
    1.62 +
    1.63 +  MessageLoop* mIOLoop;
    1.64 +  ScopedClose mFd;
    1.65 +  MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
    1.66 +  MessageLoopForIO::FileDescriptorWatcher mWriteWatcher;
    1.67 +};
    1.68 +
    1.69 +}
    1.70 +}
    1.71 +
    1.72 +#endif

mercurial