summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authorronghuawu@chromium.org <ronghuawu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 18:35:08 +0000
committerronghuawu@chromium.org <ronghuawu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 18:35:08 +0000
commit836c8975362beb3670717db33e98963c5d2c833e (patch)
tree079bdc30b2a87d5fc6e1353053b97e3dc504f588 /third_party
parent3c21d74b8d7bbe740b21413a378cf83db0abff41 (diff)
downloadchromium_src-836c8975362beb3670717db33e98963c5d2c833e.zip
chromium_src-836c8975362beb3670717db33e98963c5d2c833e.tar.gz
chromium_src-836c8975362beb3670717db33e98963c5d2c833e.tar.bz2
* Remove the dependency to ws2_32.dll from talk_base::ThreadManager and talk_base::Thread.
* Remove the denendency to the htons(), htonl(), ntohs(), ntohl(). * Implement inet_pton_v4 without using ws2. * Update the remoting_unittests. BUG=115501 TEST=Build and run webrtc test on Windows. Review URL: http://codereview.chromium.org/9455070 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124434 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r--third_party/libjingle/libjingle.gyp19
-rw-r--r--third_party/libjingle/overrides/talk/base/byteorder.h1
-rw-r--r--third_party/libjingle/overrides/talk/base/messagequeue.cc73
-rw-r--r--third_party/libjingle/overrides/talk/base/messagequeue.h9
-rw-r--r--third_party/libjingle/overrides/talk/base/thread.cc23
-rw-r--r--third_party/libjingle/overrides/talk/base/thread.h5
-rw-r--r--third_party/libjingle/overrides/talk/base/win32.cc46
-rw-r--r--third_party/libjingle/overrides/talk/base/win32.h9
8 files changed, 146 insertions, 39 deletions
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);