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"
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.
29 class NetdConsumer
: public mozilla::RefCounted
<NetdConsumer
>
32 virtual ~NetdConsumer() { }
33 virtual void MessageReceived(NetdCommand
* aMessage
) = 0;
36 class NetdWriteTask
: public Task
41 class NetdClient
: public MessageLoopForIO::LineWatcher
,
42 public RefCounted
<NetdClient
>
45 typedef std::queue
<NetdCommand
*> NetdCommandQueue
;
48 virtual ~NetdClient();
50 static void SendNetdCommandIOThread(NetdCommand
* aMessage
);
53 void WriteNetdCommand();
54 virtual void OnError();
55 virtual void OnLineRead(int aFd
, nsDependentCSubstring
& aMessage
);
56 virtual void OnFileCanWriteWithoutBlocking(int aFd
);
59 MessageLoopForIO
*mIOLoop
;
60 MessageLoopForIO::FileDescriptorWatcher mReadWatcher
;
61 MessageLoopForIO::FileDescriptorWatcher mWriteWatcher
;
63 NetdCommandQueue mOutgoingQ
;
64 nsAutoPtr
<NetdCommand
> mCurrentNetdCommand
;
65 size_t mCurrentWriteOffset
;
66 size_t mReConnectTimes
;
69 void StartNetd(NetdConsumer
*);
71 void SendNetdCommand(NetdCommand
*);
74 } // namespace mozilla
76 #endif // mozilla_system_netd_h__