Index: third_party/libjingle/overrides/talk/base/messagequeue.cc |
=================================================================== |
--- third_party/libjingle/overrides/talk/base/messagequeue.cc (revision 123769) |
+++ third_party/libjingle/overrides/talk/base/messagequeue.cc (working copy) |
@@ -34,6 +34,7 @@ |
#endif |
#include "talk/base/common.h" |
+#include "talk/base/event.h" |
#include "talk/base/logging.h" |
#include "talk/base/messagequeue.h" |
#include "talk/base/physicalsocketserver.h" |
@@ -44,6 +45,34 @@ |
const uint32 kMaxMsgLatency = 150; // 150 ms |
//------------------------------------------------------------------ |
+// NullSocketServer |
+ |
+class NullSocketServer : public SocketServer { |
+ public: |
+ NullSocketServer() : event_(false, false) { } |
tommi (sloooow) - chröme
2012/02/28 21:32:18
fix indent and remove space from {}
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
Done.
|
+ |
+ virtual bool Wait(int cms, bool process_io) OVERRIDE { |
+ return event_.Wait(kForever); |
+ } |
+ |
+ virtual void WakeUp() OVERRIDE { |
+ event_.Set(); |
+ } |
+ |
+ virtual Socket* CreateSocket(int type) OVERRIDE { |
+ return NULL; |
tommi (sloooow) - chröme
2012/02/28 21:32:18
NOTREACHED?
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
This is libjingle code, we don't have NOTREACHED.
tommi (sloooow) - chröme
2012/02/29 09:54:22
ok, but libjingle does have asserts. ASSERT(false
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
+ } |
+ |
+ // Returns a new socket for nonblocking communication. The type can be |
+ // SOCK_DGRAM and/or SOCK_STREAM. |
+ virtual AsyncSocket* CreateAsyncSocket(int type) OVERRIDE { |
+ return NULL; |
tommi (sloooow) - chröme
2012/02/28 21:32:18
here as well
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
No NOTREACHED in libjingle
tommi (sloooow) - chröme
2012/02/29 09:54:22
ASSERT(false);
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Done.
|
+ } |
+ private: |
+ Event event_; |
+}; |
+ |
+//------------------------------------------------------------------ |
// MessageQueueManager |
MessageQueueManager* MessageQueueManager::instance_; |
@@ -105,18 +134,30 @@ |
//------------------------------------------------------------------ |
// MessageQueue |
-MessageQueue::MessageQueue(SocketServer* ss) |
- : ss_(ss), fStop_(false), fPeekKeep_(false), active_(false), |
- dmsgq_next_num_(0) { |
- if (!ss_) { |
- // Currently, MessageQueue holds a socket server, and is the base class for |
- // Thread. It seems like it makes more sense for Thread to hold the socket |
- // server, and provide it to the MessageQueue, since the Thread controls |
- // the I/O model, and MQ is agnostic to those details. Anyway, this causes |
- // messagequeue_unittest to depend on network libraries... yuck. |
- default_ss_.reset(new PhysicalSocketServer()); |
- ss_ = default_ss_.get(); |
+MessageQueue::MessageQueue() { |
+ // TODO(ronghuawu): |
+ // Currently, MessageQueue holds a socket server, and is the base class for |
+ // Thread. It seems like it makes more sense for Thread to hold the socket |
+ // server, and provide it to the MessageQueue, since the Thread controls |
+ // the I/O model, and MQ is agnostic to those details. Anyway, this causes |
+ // messagequeue_unittest to depend on network libraries... yuck. |
+ default_ss_.reset(new PhysicalSocketServer()); |
+ Construct(); |
+} |
+ |
+MessageQueue::MessageQueue(SocketServer* ss) { |
+ if (!ss) { |
+ default_ss_.reset(new NullSocketServer()); |
} |
tommi (sloooow) - chröme
2012/02/28 21:32:18
aren't you missing an else? looks like |ss| is si
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
ooops, thanks.
|
+ Construct(); |
+} |
+ |
+void MessageQueue::Construct() { |
+ fStop_ = false; |
tommi (sloooow) - chröme
2012/02/28 21:32:18
you can initialize all these in an initializer lis
Ronghua Wu (Left Chromium)
2012/02/28 23:16:57
You meant call MessageQueue() in MessageQueue(Sock
tommi (sloooow) - chröme
2012/02/29 09:54:22
yes.
Ronghua Wu (Left Chromium)
2012/03/01 00:50:13
Can't do that as we need a way to tell if should c
|
+ fPeekKeep_ = false; |
+ active_ = false; |
+ dmsgq_next_num_ = 0; |
+ ss_ = default_ss_.get(); |
ss_->SetMessageQueue(this); |
} |