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
AsyncSocket()15 AsyncSocket::AsyncSocket() {
16 }
17
~AsyncSocket()18 AsyncSocket::~AsyncSocket() {
19 }
20
AsyncSocketAdapter(AsyncSocket * socket)21 AsyncSocketAdapter::AsyncSocketAdapter(AsyncSocket* socket) : socket_(NULL) {
22 Attach(socket);
23 }
24
~AsyncSocketAdapter()25 AsyncSocketAdapter::~AsyncSocketAdapter() {
26 delete socket_;
27 }
28
Attach(AsyncSocket * socket)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
GetLocalAddress() const41 SocketAddress AsyncSocketAdapter::GetLocalAddress() const {
42 return socket_->GetLocalAddress();
43 }
44
GetRemoteAddress() const45 SocketAddress AsyncSocketAdapter::GetRemoteAddress() const {
46 return socket_->GetRemoteAddress();
47 }
48
Bind(const SocketAddress & addr)49 int AsyncSocketAdapter::Bind(const SocketAddress& addr) {
50 return socket_->Bind(addr);
51 }
52
Connect(const SocketAddress & addr)53 int AsyncSocketAdapter::Connect(const SocketAddress& addr) {
54 return socket_->Connect(addr);
55 }
56
Send(const void * pv,size_t cb)57 int AsyncSocketAdapter::Send(const void* pv, size_t cb) {
58 return socket_->Send(pv, cb);
59 }
60
SendTo(const void * pv,size_t cb,const SocketAddress & addr)61 int AsyncSocketAdapter::SendTo(const void* pv,
62 size_t cb,
63 const SocketAddress& addr) {
64 return socket_->SendTo(pv, cb, addr);
65 }
66
Recv(void * pv,size_t cb)67 int AsyncSocketAdapter::Recv(void* pv, size_t cb) {
68 return socket_->Recv(pv, cb);
69 }
70
RecvFrom(void * pv,size_t cb,SocketAddress * paddr)71 int AsyncSocketAdapter::RecvFrom(void* pv, size_t cb, SocketAddress* paddr) {
72 return socket_->RecvFrom(pv, cb, paddr);
73 }
74
Listen(int backlog)75 int AsyncSocketAdapter::Listen(int backlog) {
76 return socket_->Listen(backlog);
77 }
78
Accept(SocketAddress * paddr)79 AsyncSocket* AsyncSocketAdapter::Accept(SocketAddress* paddr) {
80 return socket_->Accept(paddr);
81 }
82
Close()83 int AsyncSocketAdapter::Close() {
84 return socket_->Close();
85 }
86
GetError() const87 int AsyncSocketAdapter::GetError() const {
88 return socket_->GetError();
89 }
90
SetError(int error)91 void AsyncSocketAdapter::SetError(int error) {
92 return socket_->SetError(error);
93 }
94
GetState() const95 AsyncSocket::ConnState AsyncSocketAdapter::GetState() const {
96 return socket_->GetState();
97 }
98
EstimateMTU(uint16_t * mtu)99 int AsyncSocketAdapter::EstimateMTU(uint16_t* mtu) {
100 return socket_->EstimateMTU(mtu);
101 }
102
GetOption(Option opt,int * value)103 int AsyncSocketAdapter::GetOption(Option opt, int* value) {
104 return socket_->GetOption(opt, value);
105 }
106
SetOption(Option opt,int value)107 int AsyncSocketAdapter::SetOption(Option opt, int value) {
108 return socket_->SetOption(opt, value);
109 }
110
OnConnectEvent(AsyncSocket * socket)111 void AsyncSocketAdapter::OnConnectEvent(AsyncSocket* socket) {
112 SignalConnectEvent(this);
113 }
114
OnReadEvent(AsyncSocket * socket)115 void AsyncSocketAdapter::OnReadEvent(AsyncSocket* socket) {
116 SignalReadEvent(this);
117 }
118
OnWriteEvent(AsyncSocket * socket)119 void AsyncSocketAdapter::OnWriteEvent(AsyncSocket* socket) {
120 SignalWriteEvent(this);
121 }
122
OnCloseEvent(AsyncSocket * socket,int err)123 void AsyncSocketAdapter::OnCloseEvent(AsyncSocket* socket, int err) {
124 SignalCloseEvent(this, err);
125 }
126
127 } // namespace rtc
128