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"
10 #include "base/message_loop.h"
11 #include "mozilla/FileUtils.h"
13 #define MAX_COMMAND_SIZE 4096
19 * Represents raw data going to or coming from the Netd socket.
23 uint8_t mData
[MAX_COMMAND_SIZE
];
25 // Number of octets in mData.
32 virtual ~NetdConsumer() { }
35 NS_INLINE_DECL_REFCOUNTING(NetdConsumer
)
37 virtual void MessageReceived(NetdCommand
* aMessage
) = 0;
40 class NetdWriteTask
: public Task
45 class NetdClient
: public MessageLoopForIO::LineWatcher
47 virtual ~NetdClient();
50 NS_INLINE_DECL_REFCOUNTING(NetdClient
)
51 typedef std::queue
<NetdCommand
*> NetdCommandQueue
;
55 static void SendNetdCommandIOThread(NetdCommand
* aMessage
);
58 void WriteNetdCommand();
59 virtual void OnError();
60 virtual void OnLineRead(int aFd
, nsDependentCSubstring
& aMessage
);
61 virtual void OnFileCanWriteWithoutBlocking(int aFd
);
64 MessageLoopForIO
*mIOLoop
;
65 MessageLoopForIO::FileDescriptorWatcher mReadWatcher
;
66 MessageLoopForIO::FileDescriptorWatcher mWriteWatcher
;
68 NetdCommandQueue mOutgoingQ
;
69 nsAutoPtr
<NetdCommand
> mCurrentNetdCommand
;
70 size_t mCurrentWriteOffset
;
71 size_t mReConnectTimes
;
74 void StartNetd(NetdConsumer
*);
76 void SendNetdCommand(NetdCommand
*);
79 } // namespace mozilla
81 #endif // mozilla_system_netd_h__