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

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

mercurial