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