Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: webrtc/base/natsocketfactory.cc

Issue 2718663005: Replace NULL with nullptr or null in webrtc/base/. (Closed)
Patch Set: Fixing Windows and formatting issues. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/nat_unittest.cc ('k') | webrtc/base/nethelpers.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 return kNATEncodedIPv6AddressSize; 64 return kNATEncodedIPv6AddressSize;
65 } 65 }
66 return 0U; 66 return 0U;
67 } 67 }
68 68
69 69
70 // NATSocket 70 // NATSocket
71 class NATSocket : public AsyncSocket, public sigslot::has_slots<> { 71 class NATSocket : public AsyncSocket, public sigslot::has_slots<> {
72 public: 72 public:
73 explicit NATSocket(NATInternalSocketFactory* sf, int family, int type) 73 explicit NATSocket(NATInternalSocketFactory* sf, int family, int type)
74 : sf_(sf), family_(family), type_(type), connected_(false), 74 : sf_(sf),
75 socket_(NULL), buf_(NULL), size_(0) { 75 family_(family),
76 } 76 type_(type),
77 connected_(false),
78 socket_(nullptr),
79 buf_(nullptr),
80 size_(0) {}
77 81
78 ~NATSocket() override { 82 ~NATSocket() override {
79 delete socket_; 83 delete socket_;
80 delete[] buf_; 84 delete[] buf_;
81 } 85 }
82 86
83 SocketAddress GetLocalAddress() const override { 87 SocketAddress GetLocalAddress() const override {
84 return (socket_) ? socket_->GetLocalAddress() : SocketAddress(); 88 return (socket_) ? socket_->GetLocalAddress() : SocketAddress();
85 } 89 }
86 90
(...skipping 10 matching lines...) Expand all
97 socket_ = sf_->CreateInternalSocket(family_, type_, addr, &server_addr_); 101 socket_ = sf_->CreateInternalSocket(family_, type_, addr, &server_addr_);
98 result = (socket_) ? socket_->Bind(addr) : -1; 102 result = (socket_) ? socket_->Bind(addr) : -1;
99 if (result >= 0) { 103 if (result >= 0) {
100 socket_->SignalConnectEvent.connect(this, &NATSocket::OnConnectEvent); 104 socket_->SignalConnectEvent.connect(this, &NATSocket::OnConnectEvent);
101 socket_->SignalReadEvent.connect(this, &NATSocket::OnReadEvent); 105 socket_->SignalReadEvent.connect(this, &NATSocket::OnReadEvent);
102 socket_->SignalWriteEvent.connect(this, &NATSocket::OnWriteEvent); 106 socket_->SignalWriteEvent.connect(this, &NATSocket::OnWriteEvent);
103 socket_->SignalCloseEvent.connect(this, &NATSocket::OnCloseEvent); 107 socket_->SignalCloseEvent.connect(this, &NATSocket::OnCloseEvent);
104 } else { 108 } else {
105 server_addr_.Clear(); 109 server_addr_.Clear();
106 delete socket_; 110 delete socket_;
107 socket_ = NULL; 111 socket_ = nullptr;
108 } 112 }
109 113
110 return result; 114 return result;
111 } 115 }
112 116
113 int Connect(const SocketAddress& addr) override { 117 int Connect(const SocketAddress& addr) override {
114 if (!socket_) { // socket must be bound, for now 118 if (!socket_) { // socket must be bound, for now
115 return -1; 119 return -1;
116 } 120 }
117 121
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 208 }
205 209
206 int Close() override { 210 int Close() override {
207 int result = 0; 211 int result = 0;
208 if (socket_) { 212 if (socket_) {
209 result = socket_->Close(); 213 result = socket_->Close();
210 if (result >= 0) { 214 if (result >= 0) {
211 connected_ = false; 215 connected_ = false;
212 remote_addr_ = SocketAddress(); 216 remote_addr_ = SocketAddress();
213 delete socket_; 217 delete socket_;
214 socket_ = NULL; 218 socket_ = nullptr;
215 } 219 }
216 } 220 }
217 return result; 221 return result;
218 } 222 }
219 223
220 int Listen(int backlog) override { return socket_->Listen(backlog); } 224 int Listen(int backlog) override { return socket_->Listen(backlog); }
221 AsyncSocket* Accept(SocketAddress* paddr) override { 225 AsyncSocket* Accept(SocketAddress* paddr) override {
222 return socket_->Accept(paddr); 226 return socket_->Accept(paddr);
223 } 227 }
224 int GetError() const override { return socket_->GetError(); } 228 int GetError() const override { return socket_->GetError(); }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (type == SOCK_STREAM) { 336 if (type == SOCK_STREAM) {
333 *nat_addr = nat_tcp_addr_; 337 *nat_addr = nat_tcp_addr_;
334 } else { 338 } else {
335 *nat_addr = nat_udp_addr_; 339 *nat_addr = nat_udp_addr_;
336 } 340 }
337 return factory_->CreateAsyncSocket(family, type); 341 return factory_->CreateAsyncSocket(family, type);
338 } 342 }
339 343
340 // NATSocketServer 344 // NATSocketServer
341 NATSocketServer::NATSocketServer(SocketServer* server) 345 NATSocketServer::NATSocketServer(SocketServer* server)
342 : server_(server), msg_queue_(NULL) { 346 : server_(server), msg_queue_(nullptr) {}
343 }
344 347
345 NATSocketServer::Translator* NATSocketServer::GetTranslator( 348 NATSocketServer::Translator* NATSocketServer::GetTranslator(
346 const SocketAddress& ext_ip) { 349 const SocketAddress& ext_ip) {
347 return nats_.Get(ext_ip); 350 return nats_.Get(ext_ip);
348 } 351 }
349 352
350 NATSocketServer::Translator* NATSocketServer::AddTranslator( 353 NATSocketServer::Translator* NATSocketServer::AddTranslator(
351 const SocketAddress& ext_ip, const SocketAddress& int_ip, NATType type) { 354 const SocketAddress& ext_ip, const SocketAddress& int_ip, NATType type) {
352 // Fail if a translator already exists with this extternal address. 355 // Fail if a translator already exists with this extternal address.
353 if (nats_.Get(ext_ip)) 356 if (nats_.Get(ext_ip))
354 return NULL; 357 return nullptr;
355 358
356 return nats_.Add(ext_ip, new Translator(this, type, int_ip, server_, ext_ip)); 359 return nats_.Add(ext_ip, new Translator(this, type, int_ip, server_, ext_ip));
357 } 360 }
358 361
359 void NATSocketServer::RemoveTranslator( 362 void NATSocketServer::RemoveTranslator(
360 const SocketAddress& ext_ip) { 363 const SocketAddress& ext_ip) {
361 nats_.Remove(ext_ip); 364 nats_.Remove(ext_ip);
362 } 365 }
363 366
364 Socket* NATSocketServer::CreateSocket(int type) { 367 Socket* NATSocketServer::CreateSocket(int type) {
(...skipping 20 matching lines...) Expand all
385 bool NATSocketServer::Wait(int cms, bool process_io) { 388 bool NATSocketServer::Wait(int cms, bool process_io) {
386 return server_->Wait(cms, process_io); 389 return server_->Wait(cms, process_io);
387 } 390 }
388 391
389 void NATSocketServer::WakeUp() { 392 void NATSocketServer::WakeUp() {
390 server_->WakeUp(); 393 server_->WakeUp();
391 } 394 }
392 395
393 AsyncSocket* NATSocketServer::CreateInternalSocket(int family, int type, 396 AsyncSocket* NATSocketServer::CreateInternalSocket(int family, int type,
394 const SocketAddress& local_addr, SocketAddress* nat_addr) { 397 const SocketAddress& local_addr, SocketAddress* nat_addr) {
395 AsyncSocket* socket = NULL; 398 AsyncSocket* socket = nullptr;
396 Translator* nat = nats_.FindClient(local_addr); 399 Translator* nat = nats_.FindClient(local_addr);
397 if (nat) { 400 if (nat) {
398 socket = nat->internal_factory()->CreateAsyncSocket(family, type); 401 socket = nat->internal_factory()->CreateAsyncSocket(family, type);
399 *nat_addr = (type == SOCK_STREAM) ? 402 *nat_addr = (type == SOCK_STREAM) ?
400 nat->internal_tcp_address() : nat->internal_udp_address(); 403 nat->internal_tcp_address() : nat->internal_udp_address();
401 } else { 404 } else {
402 socket = server_->CreateAsyncSocket(family, type); 405 socket = server_->CreateAsyncSocket(family, type);
403 } 406 }
404 return socket; 407 return socket;
405 } 408 }
(...skipping 17 matching lines...) Expand all
423 426
424 NATSocketServer::Translator* NATSocketServer::Translator::GetTranslator( 427 NATSocketServer::Translator* NATSocketServer::Translator::GetTranslator(
425 const SocketAddress& ext_ip) { 428 const SocketAddress& ext_ip) {
426 return nats_.Get(ext_ip); 429 return nats_.Get(ext_ip);
427 } 430 }
428 431
429 NATSocketServer::Translator* NATSocketServer::Translator::AddTranslator( 432 NATSocketServer::Translator* NATSocketServer::Translator::AddTranslator(
430 const SocketAddress& ext_ip, const SocketAddress& int_ip, NATType type) { 433 const SocketAddress& ext_ip, const SocketAddress& int_ip, NATType type) {
431 // Fail if a translator already exists with this extternal address. 434 // Fail if a translator already exists with this extternal address.
432 if (nats_.Get(ext_ip)) 435 if (nats_.Get(ext_ip))
433 return NULL; 436 return nullptr;
434 437
435 AddClient(ext_ip); 438 AddClient(ext_ip);
436 return nats_.Add(ext_ip, 439 return nats_.Add(ext_ip,
437 new Translator(server_, type, int_ip, server_, ext_ip)); 440 new Translator(server_, type, int_ip, server_, ext_ip));
438 } 441 }
439 void NATSocketServer::Translator::RemoveTranslator( 442 void NATSocketServer::Translator::RemoveTranslator(
440 const SocketAddress& ext_ip) { 443 const SocketAddress& ext_ip) {
441 nats_.Remove(ext_ip); 444 nats_.Remove(ext_ip);
442 RemoveClient(ext_ip); 445 RemoveClient(ext_ip);
443 } 446 }
(...skipping 26 matching lines...) Expand all
470 // NATSocketServer::TranslatorMap 473 // NATSocketServer::TranslatorMap
471 NATSocketServer::TranslatorMap::~TranslatorMap() { 474 NATSocketServer::TranslatorMap::~TranslatorMap() {
472 for (TranslatorMap::iterator it = begin(); it != end(); ++it) { 475 for (TranslatorMap::iterator it = begin(); it != end(); ++it) {
473 delete it->second; 476 delete it->second;
474 } 477 }
475 } 478 }
476 479
477 NATSocketServer::Translator* NATSocketServer::TranslatorMap::Get( 480 NATSocketServer::Translator* NATSocketServer::TranslatorMap::Get(
478 const SocketAddress& ext_ip) { 481 const SocketAddress& ext_ip) {
479 TranslatorMap::iterator it = find(ext_ip); 482 TranslatorMap::iterator it = find(ext_ip);
480 return (it != end()) ? it->second : NULL; 483 return (it != end()) ? it->second : nullptr;
481 } 484 }
482 485
483 NATSocketServer::Translator* NATSocketServer::TranslatorMap::Add( 486 NATSocketServer::Translator* NATSocketServer::TranslatorMap::Add(
484 const SocketAddress& ext_ip, Translator* nat) { 487 const SocketAddress& ext_ip, Translator* nat) {
485 (*this)[ext_ip] = nat; 488 (*this)[ext_ip] = nat;
486 return nat; 489 return nat;
487 } 490 }
488 491
489 void NATSocketServer::TranslatorMap::Remove( 492 void NATSocketServer::TranslatorMap::Remove(
490 const SocketAddress& ext_ip) { 493 const SocketAddress& ext_ip) {
491 TranslatorMap::iterator it = find(ext_ip); 494 TranslatorMap::iterator it = find(ext_ip);
492 if (it != end()) { 495 if (it != end()) {
493 delete it->second; 496 delete it->second;
494 erase(it); 497 erase(it);
495 } 498 }
496 } 499 }
497 500
498 NATSocketServer::Translator* NATSocketServer::TranslatorMap::FindClient( 501 NATSocketServer::Translator* NATSocketServer::TranslatorMap::FindClient(
499 const SocketAddress& int_ip) { 502 const SocketAddress& int_ip) {
500 Translator* nat = NULL; 503 Translator* nat = nullptr;
501 for (TranslatorMap::iterator it = begin(); it != end() && !nat; ++it) { 504 for (TranslatorMap::iterator it = begin(); it != end() && !nat; ++it) {
502 nat = it->second->FindClient(int_ip); 505 nat = it->second->FindClient(int_ip);
503 } 506 }
504 return nat; 507 return nat;
505 } 508 }
506 509
507 } // namespace rtc 510 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/nat_unittest.cc ('k') | webrtc/base/nethelpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698