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

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

Issue 2893723002: Add methods to change enabled events in PhysicalSocket. (Closed)
Patch Set: Created 3 years, 7 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/physicalsocketserver.h ('k') | no next file » | 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 #include "webrtc/base/physicalsocketserver.h" 10 #include "webrtc/base/physicalsocketserver.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 0, // End of list marker 114 0, // End of list marker
115 }; 115 };
116 116
117 static const int IP_HEADER_SIZE = 20u; 117 static const int IP_HEADER_SIZE = 20u;
118 static const int IPV6_HEADER_SIZE = 40u; 118 static const int IPV6_HEADER_SIZE = 40u;
119 static const int ICMP_HEADER_SIZE = 8u; 119 static const int ICMP_HEADER_SIZE = 8u;
120 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u; 120 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u;
121 #endif 121 #endif
122 122
123 PhysicalSocket::PhysicalSocket(PhysicalSocketServer* ss, SOCKET s) 123 PhysicalSocket::PhysicalSocket(PhysicalSocketServer* ss, SOCKET s)
124 : ss_(ss), s_(s), enabled_events_(0), error_(0), 124 : ss_(ss), s_(s), error_(0),
125 state_((s == INVALID_SOCKET) ? CS_CLOSED : CS_CONNECTED), 125 state_((s == INVALID_SOCKET) ? CS_CLOSED : CS_CONNECTED),
126 resolver_(nullptr) { 126 resolver_(nullptr) {
127 #if defined(WEBRTC_WIN) 127 #if defined(WEBRTC_WIN)
128 // EnsureWinsockInit() ensures that winsock is initialized. The default 128 // EnsureWinsockInit() ensures that winsock is initialized. The default
129 // version of this function doesn't do anything because winsock is 129 // version of this function doesn't do anything because winsock is
130 // initialized by constructor of a static object. If neccessary libjingle 130 // initialized by constructor of a static object. If neccessary libjingle
131 // users can link it with a different version of this function by replacing 131 // users can link it with a different version of this function by replacing
132 // win32socketinit.cc. See win32socketinit.cc for more details. 132 // win32socketinit.cc. See win32socketinit.cc for more details.
133 EnsureWinsockInit(); 133 EnsureWinsockInit();
134 #endif 134 #endif
135 if (s_ != INVALID_SOCKET) { 135 if (s_ != INVALID_SOCKET) {
136 enabled_events_ = DE_READ | DE_WRITE; 136 SetEnabledEvents(DE_READ | DE_WRITE);
137 137
138 int type = SOCK_STREAM; 138 int type = SOCK_STREAM;
139 socklen_t len = sizeof(type); 139 socklen_t len = sizeof(type);
140 const int res = 140 const int res =
141 getsockopt(s_, SOL_SOCKET, SO_TYPE, (SockOptArg)&type, &len); 141 getsockopt(s_, SOL_SOCKET, SO_TYPE, (SockOptArg)&type, &len);
142 RTC_DCHECK_EQ(0, res); 142 RTC_DCHECK_EQ(0, res);
143 udp_ = (SOCK_DGRAM == type); 143 udp_ = (SOCK_DGRAM == type);
144 } 144 }
145 } 145 }
146 146
147 PhysicalSocket::~PhysicalSocket() { 147 PhysicalSocket::~PhysicalSocket() {
148 Close(); 148 Close();
149 } 149 }
150 150
151 bool PhysicalSocket::Create(int family, int type) { 151 bool PhysicalSocket::Create(int family, int type) {
152 Close(); 152 Close();
153 s_ = ::socket(family, type, 0); 153 s_ = ::socket(family, type, 0);
154 udp_ = (SOCK_DGRAM == type); 154 udp_ = (SOCK_DGRAM == type);
155 UpdateLastError(); 155 UpdateLastError();
156 if (udp_) 156 if (udp_) {
157 enabled_events_ = DE_READ | DE_WRITE; 157 SetEnabledEvents(DE_READ | DE_WRITE);
158 }
158 return s_ != INVALID_SOCKET; 159 return s_ != INVALID_SOCKET;
159 } 160 }
160 161
161 SocketAddress PhysicalSocket::GetLocalAddress() const { 162 SocketAddress PhysicalSocket::GetLocalAddress() const {
162 sockaddr_storage addr_storage = {0}; 163 sockaddr_storage addr_storage = {0};
163 socklen_t addrlen = sizeof(addr_storage); 164 socklen_t addrlen = sizeof(addr_storage);
164 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); 165 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage);
165 int result = ::getsockname(s_, addr, &addrlen); 166 int result = ::getsockname(s_, addr, &addrlen);
166 SocketAddress address; 167 SocketAddress address;
167 if (result >= 0) { 168 if (result >= 0) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 int PhysicalSocket::DoConnect(const SocketAddress& connect_addr) { 260 int PhysicalSocket::DoConnect(const SocketAddress& connect_addr) {
260 if ((s_ == INVALID_SOCKET) && 261 if ((s_ == INVALID_SOCKET) &&
261 !Create(connect_addr.family(), SOCK_STREAM)) { 262 !Create(connect_addr.family(), SOCK_STREAM)) {
262 return SOCKET_ERROR; 263 return SOCKET_ERROR;
263 } 264 }
264 sockaddr_storage addr_storage; 265 sockaddr_storage addr_storage;
265 size_t len = connect_addr.ToSockAddrStorage(&addr_storage); 266 size_t len = connect_addr.ToSockAddrStorage(&addr_storage);
266 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); 267 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage);
267 int err = ::connect(s_, addr, static_cast<int>(len)); 268 int err = ::connect(s_, addr, static_cast<int>(len));
268 UpdateLastError(); 269 UpdateLastError();
270 uint8_t events = DE_READ | DE_WRITE;
269 if (err == 0) { 271 if (err == 0) {
270 state_ = CS_CONNECTED; 272 state_ = CS_CONNECTED;
271 } else if (IsBlockingError(GetError())) { 273 } else if (IsBlockingError(GetError())) {
272 state_ = CS_CONNECTING; 274 state_ = CS_CONNECTING;
273 enabled_events_ |= DE_CONNECT; 275 events |= DE_CONNECT;
274 } else { 276 } else {
275 return SOCKET_ERROR; 277 return SOCKET_ERROR;
276 } 278 }
277 279
278 enabled_events_ |= DE_READ | DE_WRITE; 280 EnableEvents(events);
279 return 0; 281 return 0;
280 } 282 }
281 283
282 int PhysicalSocket::GetError() const { 284 int PhysicalSocket::GetError() const {
283 CritScope cs(&crit_); 285 CritScope cs(&crit_);
284 return error_; 286 return error_;
285 } 287 }
286 288
287 void PhysicalSocket::SetError(int error) { 289 void PhysicalSocket::SetError(int error) {
288 CritScope cs(&crit_); 290 CritScope cs(&crit_);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 #else 336 #else
335 0 337 0
336 #endif 338 #endif
337 ); 339 );
338 UpdateLastError(); 340 UpdateLastError();
339 MaybeRemapSendError(); 341 MaybeRemapSendError();
340 // We have seen minidumps where this may be false. 342 // We have seen minidumps where this may be false.
341 RTC_DCHECK(sent <= static_cast<int>(cb)); 343 RTC_DCHECK(sent <= static_cast<int>(cb));
342 if ((sent > 0 && sent < static_cast<int>(cb)) || 344 if ((sent > 0 && sent < static_cast<int>(cb)) ||
343 (sent < 0 && IsBlockingError(GetError()))) { 345 (sent < 0 && IsBlockingError(GetError()))) {
344 enabled_events_ |= DE_WRITE; 346 EnableEvents(DE_WRITE);
345 } 347 }
346 return sent; 348 return sent;
347 } 349 }
348 350
349 int PhysicalSocket::SendTo(const void* buffer, 351 int PhysicalSocket::SendTo(const void* buffer,
350 size_t length, 352 size_t length,
351 const SocketAddress& addr) { 353 const SocketAddress& addr) {
352 sockaddr_storage saddr; 354 sockaddr_storage saddr;
353 size_t len = addr.ToSockAddrStorage(&saddr); 355 size_t len = addr.ToSockAddrStorage(&saddr);
354 int sent = DoSendTo( 356 int sent = DoSendTo(
355 s_, static_cast<const char *>(buffer), static_cast<int>(length), 357 s_, static_cast<const char *>(buffer), static_cast<int>(length),
356 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) 358 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
357 // Suppress SIGPIPE. See above for explanation. 359 // Suppress SIGPIPE. See above for explanation.
358 MSG_NOSIGNAL, 360 MSG_NOSIGNAL,
359 #else 361 #else
360 0, 362 0,
361 #endif 363 #endif
362 reinterpret_cast<sockaddr*>(&saddr), static_cast<int>(len)); 364 reinterpret_cast<sockaddr*>(&saddr), static_cast<int>(len));
363 UpdateLastError(); 365 UpdateLastError();
364 MaybeRemapSendError(); 366 MaybeRemapSendError();
365 // We have seen minidumps where this may be false. 367 // We have seen minidumps where this may be false.
366 RTC_DCHECK(sent <= static_cast<int>(length)); 368 RTC_DCHECK(sent <= static_cast<int>(length));
367 if ((sent > 0 && sent < static_cast<int>(length)) || 369 if ((sent > 0 && sent < static_cast<int>(length)) ||
368 (sent < 0 && IsBlockingError(GetError()))) { 370 (sent < 0 && IsBlockingError(GetError()))) {
369 enabled_events_ |= DE_WRITE; 371 EnableEvents(DE_WRITE);
370 } 372 }
371 return sent; 373 return sent;
372 } 374 }
373 375
374 int PhysicalSocket::Recv(void* buffer, size_t length, int64_t* timestamp) { 376 int PhysicalSocket::Recv(void* buffer, size_t length, int64_t* timestamp) {
375 int received = ::recv(s_, static_cast<char*>(buffer), 377 int received = ::recv(s_, static_cast<char*>(buffer),
376 static_cast<int>(length), 0); 378 static_cast<int>(length), 0);
377 if ((received == 0) && (length != 0)) { 379 if ((received == 0) && (length != 0)) {
378 // Note: on graceful shutdown, recv can return 0. In this case, we 380 // Note: on graceful shutdown, recv can return 0. In this case, we
379 // pretend it is blocking, and then signal close, so that simplifying 381 // pretend it is blocking, and then signal close, so that simplifying
380 // assumptions can be made about Recv. 382 // assumptions can be made about Recv.
381 LOG(LS_WARNING) << "EOF from socket; deferring close event"; 383 LOG(LS_WARNING) << "EOF from socket; deferring close event";
382 // Must turn this back on so that the select() loop will notice the close 384 // Must turn this back on so that the select() loop will notice the close
383 // event. 385 // event.
384 enabled_events_ |= DE_READ; 386 EnableEvents(DE_READ);
385 SetError(EWOULDBLOCK); 387 SetError(EWOULDBLOCK);
386 return SOCKET_ERROR; 388 return SOCKET_ERROR;
387 } 389 }
388 if (timestamp) { 390 if (timestamp) {
389 *timestamp = GetSocketRecvTimestamp(s_); 391 *timestamp = GetSocketRecvTimestamp(s_);
390 } 392 }
391 UpdateLastError(); 393 UpdateLastError();
392 int error = GetError(); 394 int error = GetError();
393 bool success = (received >= 0) || IsBlockingError(error); 395 bool success = (received >= 0) || IsBlockingError(error);
394 if (udp_ || success) { 396 if (udp_ || success) {
395 enabled_events_ |= DE_READ; 397 EnableEvents(DE_READ);
396 } 398 }
397 if (!success) { 399 if (!success) {
398 LOG_F(LS_VERBOSE) << "Error = " << error; 400 LOG_F(LS_VERBOSE) << "Error = " << error;
399 } 401 }
400 return received; 402 return received;
401 } 403 }
402 404
403 int PhysicalSocket::RecvFrom(void* buffer, 405 int PhysicalSocket::RecvFrom(void* buffer,
404 size_t length, 406 size_t length,
405 SocketAddress* out_addr, 407 SocketAddress* out_addr,
406 int64_t* timestamp) { 408 int64_t* timestamp) {
407 sockaddr_storage addr_storage; 409 sockaddr_storage addr_storage;
408 socklen_t addr_len = sizeof(addr_storage); 410 socklen_t addr_len = sizeof(addr_storage);
409 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); 411 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage);
410 int received = ::recvfrom(s_, static_cast<char*>(buffer), 412 int received = ::recvfrom(s_, static_cast<char*>(buffer),
411 static_cast<int>(length), 0, addr, &addr_len); 413 static_cast<int>(length), 0, addr, &addr_len);
412 if (timestamp) { 414 if (timestamp) {
413 *timestamp = GetSocketRecvTimestamp(s_); 415 *timestamp = GetSocketRecvTimestamp(s_);
414 } 416 }
415 UpdateLastError(); 417 UpdateLastError();
416 if ((received >= 0) && (out_addr != nullptr)) 418 if ((received >= 0) && (out_addr != nullptr))
417 SocketAddressFromSockAddrStorage(addr_storage, out_addr); 419 SocketAddressFromSockAddrStorage(addr_storage, out_addr);
418 int error = GetError(); 420 int error = GetError();
419 bool success = (received >= 0) || IsBlockingError(error); 421 bool success = (received >= 0) || IsBlockingError(error);
420 if (udp_ || success) { 422 if (udp_ || success) {
421 enabled_events_ |= DE_READ; 423 EnableEvents(DE_READ);
422 } 424 }
423 if (!success) { 425 if (!success) {
424 LOG_F(LS_VERBOSE) << "Error = " << error; 426 LOG_F(LS_VERBOSE) << "Error = " << error;
425 } 427 }
426 return received; 428 return received;
427 } 429 }
428 430
429 int PhysicalSocket::Listen(int backlog) { 431 int PhysicalSocket::Listen(int backlog) {
430 int err = ::listen(s_, backlog); 432 int err = ::listen(s_, backlog);
431 UpdateLastError(); 433 UpdateLastError();
432 if (err == 0) { 434 if (err == 0) {
433 state_ = CS_CONNECTING; 435 state_ = CS_CONNECTING;
434 enabled_events_ |= DE_ACCEPT; 436 EnableEvents(DE_ACCEPT);
435 #if !defined(NDEBUG) 437 #if !defined(NDEBUG)
436 dbg_addr_ = "Listening @ "; 438 dbg_addr_ = "Listening @ ";
437 dbg_addr_.append(GetLocalAddress().ToString()); 439 dbg_addr_.append(GetLocalAddress().ToString());
438 #endif 440 #endif
439 } 441 }
440 return err; 442 return err;
441 } 443 }
442 444
443 AsyncSocket* PhysicalSocket::Accept(SocketAddress* out_addr) { 445 AsyncSocket* PhysicalSocket::Accept(SocketAddress* out_addr) {
444 // Always re-subscribe DE_ACCEPT to make sure new incoming connections will 446 // Always re-subscribe DE_ACCEPT to make sure new incoming connections will
445 // trigger an event even if DoAccept returns an error here. 447 // trigger an event even if DoAccept returns an error here.
446 enabled_events_ |= DE_ACCEPT; 448 EnableEvents(DE_ACCEPT);
447 sockaddr_storage addr_storage; 449 sockaddr_storage addr_storage;
448 socklen_t addr_len = sizeof(addr_storage); 450 socklen_t addr_len = sizeof(addr_storage);
449 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); 451 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage);
450 SOCKET s = DoAccept(s_, addr, &addr_len); 452 SOCKET s = DoAccept(s_, addr, &addr_len);
451 UpdateLastError(); 453 UpdateLastError();
452 if (s == INVALID_SOCKET) 454 if (s == INVALID_SOCKET)
453 return nullptr; 455 return nullptr;
454 if (out_addr != nullptr) 456 if (out_addr != nullptr)
455 SocketAddressFromSockAddrStorage(addr_storage, out_addr); 457 SocketAddressFromSockAddrStorage(addr_storage, out_addr);
456 return ss_->WrapSocket(s); 458 return ss_->WrapSocket(s);
457 } 459 }
458 460
459 int PhysicalSocket::Close() { 461 int PhysicalSocket::Close() {
460 if (s_ == INVALID_SOCKET) 462 if (s_ == INVALID_SOCKET)
461 return 0; 463 return 0;
462 int err = ::closesocket(s_); 464 int err = ::closesocket(s_);
463 UpdateLastError(); 465 UpdateLastError();
464 s_ = INVALID_SOCKET; 466 s_ = INVALID_SOCKET;
465 state_ = CS_CLOSED; 467 state_ = CS_CLOSED;
466 enabled_events_ = 0; 468 SetEnabledEvents(0);
467 if (resolver_) { 469 if (resolver_) {
468 resolver_->Destroy(false); 470 resolver_->Destroy(false);
469 resolver_ = nullptr; 471 resolver_ = nullptr;
470 } 472 }
471 return err; 473 return err;
472 } 474 }
473 475
474 SOCKET PhysicalSocket::DoAccept(SOCKET socket, 476 SOCKET PhysicalSocket::DoAccept(SOCKET socket,
475 sockaddr* addr, 477 sockaddr* addr,
476 socklen_t* addrlen) { 478 socklen_t* addrlen) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // Reference/ManPages/man2/sendto.2.html 520 // Reference/ManPages/man2/sendto.2.html
519 // ENOBUFS - The output queue for a network interface is full. 521 // ENOBUFS - The output queue for a network interface is full.
520 // This generally indicates that the interface has stopped sending, 522 // This generally indicates that the interface has stopped sending,
521 // but may be caused by transient congestion. 523 // but may be caused by transient congestion.
522 if (GetError() == ENOBUFS) { 524 if (GetError() == ENOBUFS) {
523 SetError(EWOULDBLOCK); 525 SetError(EWOULDBLOCK);
524 } 526 }
525 #endif 527 #endif
526 } 528 }
527 529
530 void PhysicalSocket::SetEnabledEvents(uint8_t events) {
531 enabled_events_ = events;
532 }
533
534 void PhysicalSocket::EnableEvents(uint8_t events) {
535 enabled_events_ |= events;
536 }
537
538 void PhysicalSocket::DisableEvents(uint8_t events) {
539 enabled_events_ &= ~events;
540 }
541
528 int PhysicalSocket::TranslateOption(Option opt, int* slevel, int* sopt) { 542 int PhysicalSocket::TranslateOption(Option opt, int* slevel, int* sopt) {
529 switch (opt) { 543 switch (opt) {
530 case OPT_DONTFRAGMENT: 544 case OPT_DONTFRAGMENT:
531 #if defined(WEBRTC_WIN) 545 #if defined(WEBRTC_WIN)
532 *slevel = IPPROTO_IP; 546 *slevel = IPPROTO_IP;
533 *sopt = IP_DONTFRAGMENT; 547 *sopt = IP_DONTFRAGMENT;
534 break; 548 break;
535 #elif defined(WEBRTC_MAC) || defined(BSD) || defined(__native_client__) 549 #elif defined(WEBRTC_MAC) || defined(BSD) || defined(__native_client__)
536 LOG(LS_WARNING) << "Socket::OPT_DONTFRAGMENT not supported."; 550 LOG(LS_WARNING) << "Socket::OPT_DONTFRAGMENT not supported.";
537 return -1; 551 return -1;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 // the socket is closed. 706 // the socket is closed.
693 LOG_ERR(LS_WARNING) << "Assuming benign blocking error"; 707 LOG_ERR(LS_WARNING) << "Assuming benign blocking error";
694 return false; 708 return false;
695 } 709 }
696 } 710 }
697 } 711 }
698 712
699 #endif // WEBRTC_POSIX 713 #endif // WEBRTC_POSIX
700 714
701 uint32_t SocketDispatcher::GetRequestedEvents() { 715 uint32_t SocketDispatcher::GetRequestedEvents() {
702 return enabled_events_; 716 return enabled_events();
703 } 717 }
704 718
705 void SocketDispatcher::OnPreEvent(uint32_t ff) { 719 void SocketDispatcher::OnPreEvent(uint32_t ff) {
706 if ((ff & DE_CONNECT) != 0) 720 if ((ff & DE_CONNECT) != 0)
707 state_ = CS_CONNECTED; 721 state_ = CS_CONNECTED;
708 722
709 #if defined(WEBRTC_WIN) 723 #if defined(WEBRTC_WIN)
710 // We set CS_CLOSED from CheckSignalClose. 724 // We set CS_CLOSED from CheckSignalClose.
711 #elif defined(WEBRTC_POSIX) 725 #elif defined(WEBRTC_POSIX)
712 if ((ff & DE_CLOSE) != 0) 726 if ((ff & DE_CLOSE) != 0)
713 state_ = CS_CLOSED; 727 state_ = CS_CLOSED;
714 #endif 728 #endif
715 } 729 }
716 730
717 #if defined(WEBRTC_WIN) 731 #if defined(WEBRTC_WIN)
718 732
719 void SocketDispatcher::OnEvent(uint32_t ff, int err) { 733 void SocketDispatcher::OnEvent(uint32_t ff, int err) {
720 int cache_id = id_; 734 int cache_id = id_;
721 // Make sure we deliver connect/accept first. Otherwise, consumers may see 735 // Make sure we deliver connect/accept first. Otherwise, consumers may see
722 // something like a READ followed by a CONNECT, which would be odd. 736 // something like a READ followed by a CONNECT, which would be odd.
723 if (((ff & DE_CONNECT) != 0) && (id_ == cache_id)) { 737 if (((ff & DE_CONNECT) != 0) && (id_ == cache_id)) {
724 if (ff != DE_CONNECT) 738 if (ff != DE_CONNECT)
725 LOG(LS_VERBOSE) << "Signalled with DE_CONNECT: " << ff; 739 LOG(LS_VERBOSE) << "Signalled with DE_CONNECT: " << ff;
726 enabled_events_ &= ~DE_CONNECT; 740 DisableEvents(DE_CONNECT);
727 #if !defined(NDEBUG) 741 #if !defined(NDEBUG)
728 dbg_addr_ = "Connected @ "; 742 dbg_addr_ = "Connected @ ";
729 dbg_addr_.append(GetRemoteAddress().ToString()); 743 dbg_addr_.append(GetRemoteAddress().ToString());
730 #endif 744 #endif
731 SignalConnectEvent(this); 745 SignalConnectEvent(this);
732 } 746 }
733 if (((ff & DE_ACCEPT) != 0) && (id_ == cache_id)) { 747 if (((ff & DE_ACCEPT) != 0) && (id_ == cache_id)) {
734 enabled_events_ &= ~DE_ACCEPT; 748 DisableEvents(DE_ACCEPT);
735 SignalReadEvent(this); 749 SignalReadEvent(this);
736 } 750 }
737 if ((ff & DE_READ) != 0) { 751 if ((ff & DE_READ) != 0) {
738 enabled_events_ &= ~DE_READ; 752 DisableEvents(DE_READ);
739 SignalReadEvent(this); 753 SignalReadEvent(this);
740 } 754 }
741 if (((ff & DE_WRITE) != 0) && (id_ == cache_id)) { 755 if (((ff & DE_WRITE) != 0) && (id_ == cache_id)) {
742 enabled_events_ &= ~DE_WRITE; 756 DisableEvents(DE_WRITE);
743 SignalWriteEvent(this); 757 SignalWriteEvent(this);
744 } 758 }
745 if (((ff & DE_CLOSE) != 0) && (id_ == cache_id)) { 759 if (((ff & DE_CLOSE) != 0) && (id_ == cache_id)) {
746 signal_close_ = true; 760 signal_close_ = true;
747 signal_err_ = err; 761 signal_err_ = err;
748 } 762 }
749 } 763 }
750 764
751 #elif defined(WEBRTC_POSIX) 765 #elif defined(WEBRTC_POSIX)
752 766
753 void SocketDispatcher::OnEvent(uint32_t ff, int err) { 767 void SocketDispatcher::OnEvent(uint32_t ff, int err) {
754 // Make sure we deliver connect/accept first. Otherwise, consumers may see 768 // Make sure we deliver connect/accept first. Otherwise, consumers may see
755 // something like a READ followed by a CONNECT, which would be odd. 769 // something like a READ followed by a CONNECT, which would be odd.
756 if ((ff & DE_CONNECT) != 0) { 770 if ((ff & DE_CONNECT) != 0) {
757 enabled_events_ &= ~DE_CONNECT; 771 DisableEvents(DE_CONNECT);
758 SignalConnectEvent(this); 772 SignalConnectEvent(this);
759 } 773 }
760 if ((ff & DE_ACCEPT) != 0) { 774 if ((ff & DE_ACCEPT) != 0) {
761 enabled_events_ &= ~DE_ACCEPT; 775 DisableEvents(DE_ACCEPT);
762 SignalReadEvent(this); 776 SignalReadEvent(this);
763 } 777 }
764 if ((ff & DE_READ) != 0) { 778 if ((ff & DE_READ) != 0) {
765 enabled_events_ &= ~DE_READ; 779 DisableEvents(DE_READ);
766 SignalReadEvent(this); 780 SignalReadEvent(this);
767 } 781 }
768 if ((ff & DE_WRITE) != 0) { 782 if ((ff & DE_WRITE) != 0) {
769 enabled_events_ &= ~DE_WRITE; 783 DisableEvents(DE_WRITE);
770 SignalWriteEvent(this); 784 SignalWriteEvent(this);
771 } 785 }
772 if ((ff & DE_CLOSE) != 0) { 786 if ((ff & DE_CLOSE) != 0) {
773 // The socket is now dead to us, so stop checking it. 787 // The socket is now dead to us, so stop checking it.
774 enabled_events_ = 0; 788 SetEnabledEvents(0);
775 SignalCloseEvent(this, err); 789 SignalCloseEvent(this, err);
776 } 790 }
777 } 791 }
778 792
779 #endif // WEBRTC_POSIX 793 #endif // WEBRTC_POSIX
780 794
781 int SocketDispatcher::Close() { 795 int SocketDispatcher::Close() {
782 if (s_ == INVALID_SOCKET) 796 if (s_ == INVALID_SOCKET)
783 return 0; 797 return 0;
784 798
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 break; 1586 break;
1573 } 1587 }
1574 } 1588 }
1575 1589
1576 // Done 1590 // Done
1577 return true; 1591 return true;
1578 } 1592 }
1579 #endif // WEBRTC_WIN 1593 #endif // WEBRTC_WIN
1580 1594
1581 } // namespace rtc 1595 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/physicalsocketserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698