henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "rtc_base/async_socket.h" |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 12 | |
Niels Möller | 8729d78 | 2021-08-11 11:22:44 +0200 | [diff] [blame] | 13 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/checks.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 15 | |
| 16 | namespace rtc { |
| 17 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 18 | AsyncSocket::AsyncSocket() {} |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 19 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 20 | AsyncSocket::~AsyncSocket() {} |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 21 | |
Niels Möller | 8729d78 | 2021-08-11 11:22:44 +0200 | [diff] [blame] | 22 | AsyncSocketAdapter::AsyncSocketAdapter(AsyncSocket* socket) |
| 23 | : socket_(absl::WrapUnique(socket)) { |
| 24 | RTC_DCHECK(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); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 30 | } |
| 31 | |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 32 | SocketAddress AsyncSocketAdapter::GetLocalAddress() const { |
| 33 | return socket_->GetLocalAddress(); |
| 34 | } |
| 35 | |
| 36 | SocketAddress AsyncSocketAdapter::GetRemoteAddress() const { |
| 37 | return socket_->GetRemoteAddress(); |
| 38 | } |
| 39 | |
| 40 | int AsyncSocketAdapter::Bind(const SocketAddress& addr) { |
| 41 | return socket_->Bind(addr); |
| 42 | } |
| 43 | |
| 44 | int AsyncSocketAdapter::Connect(const SocketAddress& addr) { |
| 45 | return socket_->Connect(addr); |
| 46 | } |
| 47 | |
| 48 | int AsyncSocketAdapter::Send(const void* pv, size_t cb) { |
| 49 | return socket_->Send(pv, cb); |
| 50 | } |
| 51 | |
| 52 | int AsyncSocketAdapter::SendTo(const void* pv, |
| 53 | size_t cb, |
| 54 | const SocketAddress& addr) { |
| 55 | return socket_->SendTo(pv, cb, addr); |
| 56 | } |
| 57 | |
Stefan Holmer | 9131efd | 2016-05-23 18:19:26 +0200 | [diff] [blame] | 58 | int AsyncSocketAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) { |
| 59 | return socket_->Recv(pv, cb, timestamp); |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Stefan Holmer | 9131efd | 2016-05-23 18:19:26 +0200 | [diff] [blame] | 62 | int AsyncSocketAdapter::RecvFrom(void* pv, |
| 63 | size_t cb, |
| 64 | SocketAddress* paddr, |
| 65 | int64_t* timestamp) { |
| 66 | return socket_->RecvFrom(pv, cb, paddr, timestamp); |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | int AsyncSocketAdapter::Listen(int backlog) { |
| 70 | return socket_->Listen(backlog); |
| 71 | } |
| 72 | |
| 73 | AsyncSocket* AsyncSocketAdapter::Accept(SocketAddress* paddr) { |
| 74 | return socket_->Accept(paddr); |
| 75 | } |
| 76 | |
| 77 | int AsyncSocketAdapter::Close() { |
| 78 | return socket_->Close(); |
| 79 | } |
| 80 | |
| 81 | int AsyncSocketAdapter::GetError() const { |
| 82 | return socket_->GetError(); |
| 83 | } |
| 84 | |
| 85 | void AsyncSocketAdapter::SetError(int error) { |
| 86 | return socket_->SetError(error); |
| 87 | } |
| 88 | |
| 89 | AsyncSocket::ConnState AsyncSocketAdapter::GetState() const { |
| 90 | return socket_->GetState(); |
| 91 | } |
| 92 | |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 93 | int AsyncSocketAdapter::GetOption(Option opt, int* value) { |
| 94 | return socket_->GetOption(opt, value); |
| 95 | } |
| 96 | |
| 97 | int AsyncSocketAdapter::SetOption(Option opt, int value) { |
| 98 | return socket_->SetOption(opt, value); |
| 99 | } |
| 100 | |
| 101 | void AsyncSocketAdapter::OnConnectEvent(AsyncSocket* socket) { |
| 102 | SignalConnectEvent(this); |
| 103 | } |
| 104 | |
| 105 | void AsyncSocketAdapter::OnReadEvent(AsyncSocket* socket) { |
| 106 | SignalReadEvent(this); |
| 107 | } |
| 108 | |
| 109 | void AsyncSocketAdapter::OnWriteEvent(AsyncSocket* socket) { |
| 110 | SignalWriteEvent(this); |
| 111 | } |
| 112 | |
| 113 | void AsyncSocketAdapter::OnCloseEvent(AsyncSocket* socket, int err) { |
| 114 | SignalCloseEvent(this, err); |
| 115 | } |
| 116 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 117 | } // namespace rtc |