bug 839193 - test for corresponding bug r=bent
[gecko.git] / ipc / netd / Netd.h
blob59cd9a8c00d2884d640c9071f9852d36ee400c59
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 "mozilla/RefPtr.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 {
19 * Represents raw data going to or coming from the Netd socket.
21 struct NetdCommand
23 uint8_t mData[MAX_COMMAND_SIZE];
25 // Number of octets in mData.
26 size_t mSize;
29 class NetdConsumer : public mozilla::RefCounted<NetdConsumer>
31 public:
32 virtual ~NetdConsumer() { }
33 virtual void MessageReceived(NetdCommand* aMessage) = 0;
36 class NetdWriteTask : public Task
38 virtual void Run();
41 class NetdClient : public MessageLoopForIO::LineWatcher,
42 public RefCounted<NetdClient>
44 public:
45 typedef std::queue<NetdCommand*> NetdCommandQueue;
47 NetdClient();
48 virtual ~NetdClient();
49 static void Start();
50 static void SendNetdCommandIOThread(NetdCommand* aMessage);
52 private:
53 void WriteNetdCommand();
54 virtual void OnError();
55 virtual void OnLineRead(int aFd, nsDependentCSubstring& aMessage);
56 virtual void OnFileCanWriteWithoutBlocking(int aFd);
57 bool OpenSocket();
59 MessageLoopForIO *mIOLoop;
60 MessageLoopForIO::FileDescriptorWatcher mReadWatcher;
61 MessageLoopForIO::FileDescriptorWatcher mWriteWatcher;
62 ScopedClose mSocket;
63 NetdCommandQueue mOutgoingQ;
64 nsAutoPtr<NetdCommand> mCurrentNetdCommand;
65 size_t mCurrentWriteOffset;
66 size_t mReConnectTimes;
69 void StartNetd(NetdConsumer *);
70 void StopNetd();
71 void SendNetdCommand(NetdCommand *);
73 } // namespace ipc
74 } // namespace mozilla
76 #endif // mozilla_system_netd_h__