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