blob: b28b2f9c443742c9258a7064a4b3dfb85b385aea [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/asyncsocket.h"
12#include "rtc_base/checks.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000013
14namespace rtc {
15
16AsyncSocket::AsyncSocket() {
17}
18
19AsyncSocket::~AsyncSocket() {
20}
21
deadbeef37f5ecf2017-02-27 14:06:41 -080022AsyncSocketAdapter::AsyncSocketAdapter(AsyncSocket* socket) : socket_(nullptr) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000023 Attach(socket);
24}
25
26AsyncSocketAdapter::~AsyncSocketAdapter() {
27 delete socket_;
28}
29
30void AsyncSocketAdapter::Attach(AsyncSocket* socket) {
nisseede5da42017-01-12 05:15:36 -080031 RTC_DCHECK(!socket_);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000032 socket_ = socket;
33 if (socket_) {
34 socket_->SignalConnectEvent.connect(this,
kwiberg@webrtc.org67186fe2015-03-09 22:21:53 +000035 &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.orgf0488722014-05-13 18:00:26 +000039 }
40}
41
kwiberg@webrtc.org67186fe2015-03-09 22:21:53 +000042SocketAddress AsyncSocketAdapter::GetLocalAddress() const {
43 return socket_->GetLocalAddress();
44}
45
46SocketAddress AsyncSocketAdapter::GetRemoteAddress() const {
47 return socket_->GetRemoteAddress();
48}
49
50int AsyncSocketAdapter::Bind(const SocketAddress& addr) {
51 return socket_->Bind(addr);
52}
53
54int AsyncSocketAdapter::Connect(const SocketAddress& addr) {
55 return socket_->Connect(addr);
56}
57
58int AsyncSocketAdapter::Send(const void* pv, size_t cb) {
59 return socket_->Send(pv, cb);
60}
61
62int AsyncSocketAdapter::SendTo(const void* pv,
63 size_t cb,
64 const SocketAddress& addr) {
65 return socket_->SendTo(pv, cb, addr);
66}
67
Stefan Holmer9131efd2016-05-23 18:19:26 +020068int AsyncSocketAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) {
69 return socket_->Recv(pv, cb, timestamp);
kwiberg@webrtc.org67186fe2015-03-09 22:21:53 +000070}
71
Stefan Holmer9131efd2016-05-23 18:19:26 +020072int 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.org67186fe2015-03-09 22:21:53 +000077}
78
79int AsyncSocketAdapter::Listen(int backlog) {
80 return socket_->Listen(backlog);
81}
82
83AsyncSocket* AsyncSocketAdapter::Accept(SocketAddress* paddr) {
84 return socket_->Accept(paddr);
85}
86
87int AsyncSocketAdapter::Close() {
88 return socket_->Close();
89}
90
91int AsyncSocketAdapter::GetError() const {
92 return socket_->GetError();
93}
94
95void AsyncSocketAdapter::SetError(int error) {
96 return socket_->SetError(error);
97}
98
99AsyncSocket::ConnState AsyncSocketAdapter::GetState() const {
100 return socket_->GetState();
101}
102
kwiberg@webrtc.org67186fe2015-03-09 22:21:53 +0000103int AsyncSocketAdapter::GetOption(Option opt, int* value) {
104 return socket_->GetOption(opt, value);
105}
106
107int AsyncSocketAdapter::SetOption(Option opt, int value) {
108 return socket_->SetOption(opt, value);
109}
110
111void AsyncSocketAdapter::OnConnectEvent(AsyncSocket* socket) {
112 SignalConnectEvent(this);
113}
114
115void AsyncSocketAdapter::OnReadEvent(AsyncSocket* socket) {
116 SignalReadEvent(this);
117}
118
119void AsyncSocketAdapter::OnWriteEvent(AsyncSocket* socket) {
120 SignalWriteEvent(this);
121}
122
123void AsyncSocketAdapter::OnCloseEvent(AsyncSocket* socket, int err) {
124 SignalCloseEvent(this, err);
125}
126
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000127} // namespace rtc