diff options
-rw-r--r-- | jingle/glue/thread_wrapper.cc | 3 | ||||
-rw-r--r-- | jingle/glue/thread_wrapper.h | 2 | ||||
-rw-r--r-- | remoting/protocol/jingle_session_unittest.cc | 20 | ||||
-rw-r--r-- | third_party/libjingle/libjingle.gyp | 19 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/byteorder.h | 1 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/messagequeue.cc | 73 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/messagequeue.h | 9 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/thread.cc | 23 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/thread.h | 5 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/win32.cc | 46 | ||||
-rw-r--r-- | third_party/libjingle/overrides/talk/base/win32.h | 9 |
11 files changed, 160 insertions, 50 deletions
diff --git a/jingle/glue/thread_wrapper.cc b/jingle/glue/thread_wrapper.cc index 456a619..62538da 100644 --- a/jingle/glue/thread_wrapper.cc +++ b/jingle/glue/thread_wrapper.cc @@ -43,7 +43,8 @@ JingleThreadWrapper* JingleThreadWrapper::current() { } JingleThreadWrapper::JingleThreadWrapper(MessageLoop* message_loop) - : message_loop_(message_loop), + : talk_base::Thread(NULL), + message_loop_(message_loop), send_allowed_(false), last_task_id_(0), pending_send_event_(true, false) { diff --git a/jingle/glue/thread_wrapper.h b/jingle/glue/thread_wrapper.h index 284c762..553dbbd 100644 --- a/jingle/glue/thread_wrapper.h +++ b/jingle/glue/thread_wrapper.h @@ -12,7 +12,7 @@ #include "base/message_loop.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" -#include "third_party/libjingle/source/talk/base/thread.h" +#include "third_party/libjingle/overrides/talk/base/thread.h" namespace jingle_glue { diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index 9361da4..a8b9797 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -81,8 +81,10 @@ class MockStreamChannelCallback { class JingleSessionTest : public testing::Test { public: - JingleSessionTest() - : message_loop_(talk_base::Thread::Current()) { + JingleSessionTest() { + talk_base::ThreadManager::Instance()->WrapCurrentThread(); + message_loop_.reset( + new JingleThreadMessageLoop(talk_base::Thread::Current())); } // Helper method that handles OnIncomingSession(). @@ -113,7 +115,7 @@ class JingleSessionTest : public testing::Test { virtual void TearDown() { CloseSessions(); CloseSessionManager(); - message_loop_.RunAllPending(); + message_loop_->RunAllPending(); } void CloseSessions() { @@ -224,7 +226,7 @@ class JingleSessionTest : public testing::Test { base::Bind(&MockSessionCallback::OnStateChange, base::Unretained(&client_connection_callback_))); - message_loop_.RunAllPending(); + message_loop_->RunAllPending(); } void CreateChannel(bool expect_fail) { @@ -238,7 +240,7 @@ class JingleSessionTest : public testing::Test { .WillOnce(QuitThreadOnCounter(&counter)); EXPECT_CALL(host_channel_callback_, OnDone(_)) .WillOnce(QuitThreadOnCounter(&counter)); - message_loop_.Run(); + message_loop_->Run(); if (expect_fail) { // At least one socket should fail to connect. @@ -249,7 +251,7 @@ class JingleSessionTest : public testing::Test { } } - JingleThreadMessageLoop message_loop_; + scoped_ptr<JingleThreadMessageLoop> message_loop_; scoped_ptr<FakeSignalStrategy> host_signal_strategy_; scoped_ptr<FakeSignalStrategy> client_signal_strategy_; @@ -305,7 +307,7 @@ TEST_F(JingleSessionTest, RejectConnection) { base::Bind(&MockSessionCallback::OnStateChange, base::Unretained(&client_connection_callback_))); - message_loop_.RunAllPending(); + message_loop_->RunAllPending(); } // Verify that we can connect two endpoints with single-step authentication. @@ -353,7 +355,7 @@ TEST_F(JingleSessionTest, TestStreamChannel) { StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), kMessageSize, kMessages); tester.Start(); - message_loop_.Run(); + message_loop_->Run(); tester.CheckResults(); } @@ -368,7 +370,7 @@ TEST_F(JingleSessionTest, TestMultistepAuthStreamChannel) { StreamConnectionTester tester(host_socket_.get(), client_socket_.get(), kMessageSize, kMessages); tester.Start(); - message_loop_.Run(); + message_loop_->Run(); tester.CheckResults(); } diff --git a/third_party/libjingle/libjingle.gyp b/third_party/libjingle/libjingle.gyp index 9f8ee890..b67dd43 100644 --- a/third_party/libjingle/libjingle.gyp +++ b/third_party/libjingle/libjingle.gyp @@ -174,6 +174,14 @@ 'overrides/talk/base/logging.h', 'overrides/talk/base/scoped_ptr.h', + + # TODO(ronghuawu): Remove below overrides once below bug is fixed: + # http://crbug.com/115702 + 'overrides/talk/base/byteorder.h', + 'overrides/talk/base/messagequeue.cc', + 'overrides/talk/base/messagequeue.h', + 'overrides/talk/base/thread.cc', + 'overrides/talk/base/thread.h', 'source/talk/base/Equifax_Secure_Global_eBusiness_CA-1.h', 'source/talk/base/asyncfile.cc', @@ -196,7 +204,6 @@ 'source/talk/base/basicpacketsocketfactory.h', 'source/talk/base/bytebuffer.cc', 'source/talk/base/bytebuffer.h', - 'source/talk/base/byteorder.h', 'source/talk/base/checks.cc', 'source/talk/base/checks.h', 'source/talk/base/common.cc', @@ -235,8 +242,6 @@ 'source/talk/base/md5c.c', 'source/talk/base/messagehandler.cc', 'source/talk/base/messagehandler.h', - 'source/talk/base/messagequeue.cc', - 'source/talk/base/messagequeue.h', 'source/talk/base/nethelpers.cc', 'source/talk/base/nethelpers.h', 'source/talk/base/network.cc', @@ -287,8 +292,6 @@ 'source/talk/base/taskparent.h', 'source/talk/base/taskrunner.cc', 'source/talk/base/taskrunner.h', - 'source/talk/base/thread.cc', - 'source/talk/base/thread.h', 'source/talk/base/timeutils.cc', 'source/talk/base/timeutils.h', 'source/talk/base/timing.cc', @@ -349,8 +352,10 @@ 'overrides/talk/base/win32socketinit.cc', 'source/talk/base/schanneladapter.cc', 'source/talk/base/schanneladapter.h', - 'source/talk/base/win32.h', - 'source/talk/base/win32.cc', + # TODO(ronghuawu): Remove below overrides once below bug is fixed: + # http://crbug.com/115702 + 'overrides/talk/base/win32.h', + 'overrides/talk/base/win32.cc', 'source/talk/base/win32filesystem.cc', 'source/talk/base/win32filesystem.h', 'source/talk/base/win32window.h', diff --git a/third_party/libjingle/overrides/talk/base/byteorder.h b/third_party/libjingle/overrides/talk/base/byteorder.h index 08094b8..b1375b6 100644 --- a/third_party/libjingle/overrides/talk/base/byteorder.h +++ b/third_party/libjingle/overrides/talk/base/byteorder.h @@ -34,6 +34,7 @@ #ifdef WIN32 #include <winsock2.h> +#include "talk/base/win32.h" #endif #include "talk/base/basictypes.h" diff --git a/third_party/libjingle/overrides/talk/base/messagequeue.cc b/third_party/libjingle/overrides/talk/base/messagequeue.cc index 8c3a8ce..4d66b12 100644 --- a/third_party/libjingle/overrides/talk/base/messagequeue.cc +++ b/third_party/libjingle/overrides/talk/base/messagequeue.cc @@ -34,10 +34,44 @@ #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" +namespace { +//------------------------------------------------------------------ +// NullSocketServer + +class NullSocketServer : public talk_base::SocketServer { + public: + NullSocketServer() : event_(false, false) {} + + virtual bool Wait(int cms, bool process_io) { + return event_.Wait(talk_base::kForever); + } + + virtual void WakeUp() { + event_.Set(); + } + + virtual talk_base::Socket* CreateSocket(int type) { + ASSERT(false); + return NULL; + } + + // Returns a new socket for nonblocking communication. The type can be + // SOCK_DGRAM and/or SOCK_STREAM. + virtual talk_base::AsyncSocket* CreateAsyncSocket(int type) { + ASSERT(false); + return NULL; + } + + private: + talk_base::Event event_; +}; + +} // namespace namespace talk_base { @@ -105,18 +139,33 @@ void MessageQueueManager::Clear(MessageHandler *handler) { //------------------------------------------------------------------ // 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. + owned_ss_.reset(new PhysicalSocketServer()); + ss_ = owned_ss_.get(); + Construct(); +} + +MessageQueue::MessageQueue(SocketServer* ss) { + if (ss) { + ss_ = ss; + } else { + owned_ss_.reset(new NullSocketServer()); + ss_ = owned_ss_.get(); } + Construct(); +} + +void MessageQueue::Construct() { + fStop_ = false; + fPeekKeep_ = false; + active_ = false; + dmsgq_next_num_ = 0; ss_->SetMessageQueue(this); } @@ -135,7 +184,7 @@ MessageQueue::~MessageQueue() { } void MessageQueue::set_socketserver(SocketServer* ss) { - ss_ = ss ? ss : default_ss_.get(); + ss_ = ss ? ss : owned_ss_.get(); ss_->SetMessageQueue(this); } diff --git a/third_party/libjingle/overrides/talk/base/messagequeue.h b/third_party/libjingle/overrides/talk/base/messagequeue.h index 2857182..634fa2a 100644 --- a/third_party/libjingle/overrides/talk/base/messagequeue.h +++ b/third_party/libjingle/overrides/talk/base/messagequeue.h @@ -171,9 +171,14 @@ class DelayedMessage { class MessageQueue { public: - explicit MessageQueue(SocketServer* ss = NULL); + // A phiscal socket server will be created for this ctor. + MessageQueue(); + // If |ss| is NULL, a dummy socket server will be created. + explicit MessageQueue(SocketServer* ss); virtual ~MessageQueue(); + void Construct(); + SocketServer* socketserver() { return ss_; } void set_socketserver(SocketServer* ss); @@ -240,7 +245,7 @@ class MessageQueue { // The SocketServer is not owned by MessageQueue. SocketServer* ss_; // If a server isn't supplied in the constructor, use this one. - scoped_ptr<SocketServer> default_ss_; + scoped_ptr<SocketServer> owned_ss_; bool fStop_; bool fPeekKeep_; Message msgPeek_; diff --git a/third_party/libjingle/overrides/talk/base/thread.cc b/third_party/libjingle/overrides/talk/base/thread.cc index 8b11485..7236ab8 100644 --- a/third_party/libjingle/overrides/talk/base/thread.cc +++ b/third_party/libjingle/overrides/talk/base/thread.cc @@ -85,7 +85,6 @@ void ThreadManager::SetCurrentThread(Thread *thread) { #ifdef WIN32 ThreadManager::ThreadManager() { key_ = TlsAlloc(); - WrapCurrentThread(); } ThreadManager::~ThreadManager() { @@ -126,16 +125,24 @@ struct ThreadInit { Runnable* runnable; }; +Thread::Thread() { + Construct(); +} + Thread::Thread(SocketServer* ss) - : MessageQueue(ss), - priority_(PRIORITY_NORMAL), - started_(false), - has_sends_(false), + : MessageQueue(ss) { + Construct(); +} + +void Thread::Construct() { + priority_ = PRIORITY_NORMAL; + started_ = false; + has_sends_ = false; #if defined(WIN32) - thread_(NULL), + thread_ = NULL; #endif - owned_(true), - delete_self_when_complete_(false) { + owned_ = true; + delete_self_when_complete_ = false; SetName("Thread", this); // default name } diff --git a/third_party/libjingle/overrides/talk/base/thread.h b/third_party/libjingle/overrides/talk/base/thread.h index 13fc68c..d050182 100644 --- a/third_party/libjingle/overrides/talk/base/thread.h +++ b/third_party/libjingle/overrides/talk/base/thread.h @@ -116,9 +116,12 @@ class Runnable { class Thread : public MessageQueue { public: - Thread(SocketServer* ss = NULL); + Thread(); + explicit Thread(SocketServer* ss); virtual ~Thread(); + void Construct(); + static inline Thread* Current() { return ThreadManager::Instance()->CurrentThread(); } diff --git a/third_party/libjingle/overrides/talk/base/win32.cc b/third_party/libjingle/overrides/talk/base/win32.cc index 3937781..cda3c0e 100644 --- a/third_party/libjingle/overrides/talk/base/win32.cc +++ b/third_party/libjingle/overrides/talk/base/win32.cc @@ -63,10 +63,7 @@ const char* win32_inet_ntop(int af, const void *src, return NULL; } -// As above, but for inet_pton. Wraps inet_addr for v4, and implements inet_pton -// for v6. Slightly more permissive than the RFC specified inet_pton, as it uses -// windows' inet_addr which permits octal and hexadecimal values in v4 -// addresses, while inet_pton only allows decimal. +// As above, but for inet_pton. Implements inet_pton for v4 and v6. // Note that our inet_ntop will output normal 'dotted' v4 addresses only. int win32_inet_pton(int af, const char* src, void* dst) { if (!src || !dst) { @@ -172,14 +169,45 @@ const char* inet_ntop_v6(const void* src, char* dst, socklen_t size) { } // Helper function for inet_pton for IPv4 addresses. -// Uses win32's inet_addr. +// |src| points to a character string containing an IPv4 network address in +// dotted-decimal format, "ddd.ddd.ddd.ddd", where ddd is a decimal number +// of up to three digits in the range 0 to 255. +// The address is converted and copied to dst, +// which must be sizeof(struct in_addr) (4) bytes (32 bits) long. int inet_pton_v4(const char* src, void* dst) { - uint32 ip = inet_addr(src); - if (ip == 0xFFFFFFFF && strcmp(src, "255.255.255.255") != 0) { + const int kIpv4AddressSize = 4; + int num_dot = 0; + const char* src_pos = src; + unsigned char result[kIpv4AddressSize] = {0}; + + while (*src_pos != 0) { + // strtol won't treat whitespace characters in the begining as an error, + // so check to ensure this is started with digit before passing to strtol. + if (!isdigit(*src_pos)) { + return 0; + } + char* end_pos; + long int value = strtol(src_pos, &end_pos, 10); + if (value < 0 || value > 255 || src_pos == end_pos) { + return 0; + } + result[num_dot] = value; + if (*end_pos == 0) { + break; + } + src_pos = end_pos; + if (*src_pos == '.') { + ++num_dot; + if (num_dot > kIpv4AddressSize - 1) { + return 0; + } + } + ++src_pos; + } + if (num_dot != kIpv4AddressSize - 1) { return 0; } - struct in_addr* dst_as_in_addr = reinterpret_cast<struct in_addr*>(dst); - dst_as_in_addr->s_addr = ip; + memcpy(dst, result, sizeof(result)); return 1; } diff --git a/third_party/libjingle/overrides/talk/base/win32.h b/third_party/libjingle/overrides/talk/base/win32.h index 9c6ea3f..5cb8d9f 100644 --- a/third_party/libjingle/overrides/talk/base/win32.h +++ b/third_party/libjingle/overrides/talk/base/win32.h @@ -47,11 +47,20 @@ typedef struct _TOKEN_MANDATORY_LABEL { #undef SetPort +#include <stdlib.h> #include <string> #include "talk/base/stringutils.h" #include "talk/base/basictypes.h" +// This is to remove the dependency to ws2_32.dll especially for chrome, +// where we don't load the ws2_32.dll in the render process. +// This is correct only on little-endian machines. +#define ntohl(x) _byteswap_ulong(x) +#define ntohs(x) _byteswap_ushort(x) +#define htonl(x) _byteswap_ulong(x) +#define htons(x) _byteswap_ushort(x) + namespace talk_base { const char* win32_inet_ntop(int af, const void *src, char* dst, socklen_t size); |