ipc/netd/Netd.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozilla_system_netd_h__
     6 #define mozilla_system_netd_h__
     8 #include "nsISupportsImpl.h"
     9 #include "nsAutoPtr.h"
    10 #include "base/message_loop.h"
    11 #include "mozilla/FileUtils.h"
    13 #define MAX_COMMAND_SIZE  4096
    15 namespace mozilla {
    16 namespace ipc {
    18 /*
    19  * Represents raw data going to or coming from the Netd socket.
    20  */
    21 struct NetdCommand
    22 {
    23   uint8_t mData[MAX_COMMAND_SIZE];
    25   // Number of octets in mData.
    26   size_t mSize;
    27 };
    29 class NetdConsumer
    30 {
    31 protected:
    32   virtual ~NetdConsumer() { }
    34 public:
    35   NS_INLINE_DECL_REFCOUNTING(NetdConsumer)
    37   virtual void MessageReceived(NetdCommand* aMessage) = 0;
    38 };
    40 class NetdWriteTask : public Task
    41 {
    42   virtual void Run();
    43 };
    45 class NetdClient : public MessageLoopForIO::LineWatcher
    46 {
    47   virtual ~NetdClient();
    49 public:
    50   NS_INLINE_DECL_REFCOUNTING(NetdClient)
    51   typedef std::queue<NetdCommand*> NetdCommandQueue;
    53   NetdClient();
    54   static void Start();
    55   static void SendNetdCommandIOThread(NetdCommand* aMessage);
    57 private:
    58   void WriteNetdCommand();
    59   virtual void OnError();
    60   virtual void OnLineRead(int aFd, nsDependentCSubstring& aMessage);
    61   virtual void OnFileCanWriteWithoutBlocking(int aFd);
    62   bool OpenSocket();
    64   MessageLoopForIO *mIOLoop;
    65   MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
    66   MessageLoopForIO::FileDescriptorWatcher mWriteWatcher;
    67   ScopedClose mSocket;
    68   NetdCommandQueue mOutgoingQ;
    69   nsAutoPtr<NetdCommand> mCurrentNetdCommand;
    70   size_t mCurrentWriteOffset;
    71   size_t mReConnectTimes;
    72 };
    74 void StartNetd(NetdConsumer *);
    75 void StopNetd();
    76 void SendNetdCommand(NetdCommand *);
    78 } // namespace ipc
    79 } // namespace mozilla
    81 #endif  // mozilla_system_netd_h__

mercurial