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, 34 &AsyncSocketAdapter::OnConnectEvent); 35 socket_->SignalReadEvent.connect(this, &AsyncSocketAdapter::OnReadEvent); 36 socket_->SignalWriteEvent.connect(this, &AsyncSocketAdapter::OnWriteEvent); 37 socket_->SignalCloseEvent.connect(this, &AsyncSocketAdapter::OnCloseEvent); 38 } 39 } 40 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 67 int AsyncSocketAdapter::Recv(void* pv, size_t cb) { 68 return socket_->Recv(pv, cb); 69 } 70 71 int AsyncSocketAdapter::RecvFrom(void* pv, size_t cb, SocketAddress* paddr) { 72 return socket_->RecvFrom(pv, cb, paddr); 73 } 74 75 int AsyncSocketAdapter::Listen(int backlog) { 76 return socket_->Listen(backlog); 77 } 78 79 AsyncSocket* AsyncSocketAdapter::Accept(SocketAddress* paddr) { 80 return socket_->Accept(paddr); 81 } 82 83 int AsyncSocketAdapter::Close() { 84 return socket_->Close(); 85 } 86 87 int AsyncSocketAdapter::GetError() const { 88 return socket_->GetError(); 89 } 90 91 void AsyncSocketAdapter::SetError(int error) { 92 return socket_->SetError(error); 93 } 94 95 AsyncSocket::ConnState AsyncSocketAdapter::GetState() const { 96 return socket_->GetState(); 97 } 98 99 int AsyncSocketAdapter::EstimateMTU(uint16_t* mtu) { 100 return socket_->EstimateMTU(mtu); 101 } 102 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 127 } // namespace rtc 128