• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "rtc_base/async_socket.h"
12 
13 #include "rtc_base/checks.h"
14 
15 namespace rtc {
16 
AsyncSocket()17 AsyncSocket::AsyncSocket() {}
18 
~AsyncSocket()19 AsyncSocket::~AsyncSocket() {}
20 
AsyncSocketAdapter(AsyncSocket * socket)21 AsyncSocketAdapter::AsyncSocketAdapter(AsyncSocket* socket) : socket_(nullptr) {
22   Attach(socket);
23 }
24 
~AsyncSocketAdapter()25 AsyncSocketAdapter::~AsyncSocketAdapter() {
26   delete socket_;
27 }
28 
Attach(AsyncSocket * socket)29 void AsyncSocketAdapter::Attach(AsyncSocket* socket) {
30   RTC_DCHECK(!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,int64_t * timestamp)67 int AsyncSocketAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) {
68   return socket_->Recv(pv, cb, timestamp);
69 }
70 
RecvFrom(void * pv,size_t cb,SocketAddress * paddr,int64_t * timestamp)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);
76 }
77 
Listen(int backlog)78 int AsyncSocketAdapter::Listen(int backlog) {
79   return socket_->Listen(backlog);
80 }
81 
Accept(SocketAddress * paddr)82 AsyncSocket* AsyncSocketAdapter::Accept(SocketAddress* paddr) {
83   return socket_->Accept(paddr);
84 }
85 
Close()86 int AsyncSocketAdapter::Close() {
87   return socket_->Close();
88 }
89 
GetError() const90 int AsyncSocketAdapter::GetError() const {
91   return socket_->GetError();
92 }
93 
SetError(int error)94 void AsyncSocketAdapter::SetError(int error) {
95   return socket_->SetError(error);
96 }
97 
GetState() const98 AsyncSocket::ConnState AsyncSocketAdapter::GetState() const {
99   return socket_->GetState();
100 }
101 
GetOption(Option opt,int * value)102 int AsyncSocketAdapter::GetOption(Option opt, int* value) {
103   return socket_->GetOption(opt, value);
104 }
105 
SetOption(Option opt,int value)106 int AsyncSocketAdapter::SetOption(Option opt, int value) {
107   return socket_->SetOption(opt, value);
108 }
109 
OnConnectEvent(AsyncSocket * socket)110 void AsyncSocketAdapter::OnConnectEvent(AsyncSocket* socket) {
111   SignalConnectEvent(this);
112 }
113 
OnReadEvent(AsyncSocket * socket)114 void AsyncSocketAdapter::OnReadEvent(AsyncSocket* socket) {
115   SignalReadEvent(this);
116 }
117 
OnWriteEvent(AsyncSocket * socket)118 void AsyncSocketAdapter::OnWriteEvent(AsyncSocket* socket) {
119   SignalWriteEvent(this);
120 }
121 
OnCloseEvent(AsyncSocket * socket,int err)122 void AsyncSocketAdapter::OnCloseEvent(AsyncSocket* socket, int err) {
123   SignalCloseEvent(this, err);
124 }
125 
126 }  // namespace rtc
127