You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2010 The WebRTC Project Authors. All rights reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "rtc_base/async_socket.h"
  11. #include "rtc_base/checks.h"
  12. namespace rtc {
  13. AsyncSocket::AsyncSocket() {}
  14. AsyncSocket::~AsyncSocket() {}
  15. AsyncSocketAdapter::AsyncSocketAdapter(AsyncSocket* socket) : socket_(nullptr) {
  16. Attach(socket);
  17. }
  18. AsyncSocketAdapter::~AsyncSocketAdapter() {
  19. delete socket_;
  20. }
  21. void AsyncSocketAdapter::Attach(AsyncSocket* socket) {
  22. RTC_DCHECK(!socket_);
  23. socket_ = socket;
  24. if (socket_) {
  25. socket_->SignalConnectEvent.connect(this,
  26. &AsyncSocketAdapter::OnConnectEvent);
  27. socket_->SignalReadEvent.connect(this, &AsyncSocketAdapter::OnReadEvent);
  28. socket_->SignalWriteEvent.connect(this, &AsyncSocketAdapter::OnWriteEvent);
  29. socket_->SignalCloseEvent.connect(this, &AsyncSocketAdapter::OnCloseEvent);
  30. }
  31. }
  32. SocketAddress AsyncSocketAdapter::GetLocalAddress() const {
  33. return socket_->GetLocalAddress();
  34. }
  35. SocketAddress AsyncSocketAdapter::GetRemoteAddress() const {
  36. return socket_->GetRemoteAddress();
  37. }
  38. int AsyncSocketAdapter::Bind(const SocketAddress& addr) {
  39. return socket_->Bind(addr);
  40. }
  41. int AsyncSocketAdapter::Connect(const SocketAddress& addr) {
  42. return socket_->Connect(addr);
  43. }
  44. int AsyncSocketAdapter::Send(const void* pv, size_t cb) {
  45. return socket_->Send(pv, cb);
  46. }
  47. int AsyncSocketAdapter::SendTo(const void* pv,
  48. size_t cb,
  49. const SocketAddress& addr) {
  50. return socket_->SendTo(pv, cb, addr);
  51. }
  52. int AsyncSocketAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) {
  53. return socket_->Recv(pv, cb, timestamp);
  54. }
  55. int AsyncSocketAdapter::RecvFrom(void* pv,
  56. size_t cb,
  57. SocketAddress* paddr,
  58. int64_t* timestamp) {
  59. return socket_->RecvFrom(pv, cb, paddr, timestamp);
  60. }
  61. int AsyncSocketAdapter::Listen(int backlog) {
  62. return socket_->Listen(backlog);
  63. }
  64. AsyncSocket* AsyncSocketAdapter::Accept(SocketAddress* paddr) {
  65. return socket_->Accept(paddr);
  66. }
  67. int AsyncSocketAdapter::Close() {
  68. return socket_->Close();
  69. }
  70. int AsyncSocketAdapter::GetError() const {
  71. return socket_->GetError();
  72. }
  73. void AsyncSocketAdapter::SetError(int error) {
  74. return socket_->SetError(error);
  75. }
  76. AsyncSocket::ConnState AsyncSocketAdapter::GetState() const {
  77. return socket_->GetState();
  78. }
  79. int AsyncSocketAdapter::GetOption(Option opt, int* value) {
  80. return socket_->GetOption(opt, value);
  81. }
  82. int AsyncSocketAdapter::SetOption(Option opt, int value) {
  83. return socket_->SetOption(opt, value);
  84. }
  85. void AsyncSocketAdapter::OnConnectEvent(AsyncSocket* socket) {
  86. SignalConnectEvent(this);
  87. }
  88. void AsyncSocketAdapter::OnReadEvent(AsyncSocket* socket) {
  89. SignalReadEvent(this);
  90. }
  91. void AsyncSocketAdapter::OnWriteEvent(AsyncSocket* socket) {
  92. SignalWriteEvent(this);
  93. }
  94. void AsyncSocketAdapter::OnCloseEvent(AsyncSocket* socket, int err) {
  95. SignalCloseEvent(this, err);
  96. }
  97. } // namespace rtc