OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_BASE_ASYNCSOCKET_H_ | 11 #ifndef WEBRTC_BASE_ASYNCSOCKET_H_ |
12 #define WEBRTC_BASE_ASYNCSOCKET_H_ | 12 #define WEBRTC_BASE_ASYNCSOCKET_H_ |
13 | 13 |
14 #include "webrtc/base/sigslot.h" | |
15 #include "webrtc/base/socket.h" | |
16 | 14 |
17 namespace rtc { | 15 // This header is deprecated and is just left here temporarily during |
18 | 16 // refactoring. See https://bugs.webrtc.org/7634 for more details. |
19 // TODO: Remove Socket and rename AsyncSocket to Socket. | 17 #include "webrtc/rtc_base/asyncsocket.h" |
20 | |
21 // Provides the ability to perform socket I/O asynchronously. | |
22 class AsyncSocket : public Socket { | |
23 public: | |
24 AsyncSocket(); | |
25 ~AsyncSocket() override; | |
26 | |
27 AsyncSocket* Accept(SocketAddress* paddr) override = 0; | |
28 | |
29 // SignalReadEvent and SignalWriteEvent use multi_threaded_local to allow | |
30 // access concurrently from different thread. | |
31 // For example SignalReadEvent::connect will be called in AsyncUDPSocket ctor | |
32 // but at the same time the SocketDispatcher maybe signaling the read event. | |
33 // ready to read | |
34 sigslot::signal1<AsyncSocket*, | |
35 sigslot::multi_threaded_local> SignalReadEvent; | |
36 // ready to write | |
37 sigslot::signal1<AsyncSocket*, | |
38 sigslot::multi_threaded_local> SignalWriteEvent; | |
39 sigslot::signal1<AsyncSocket*> SignalConnectEvent; // connected | |
40 sigslot::signal2<AsyncSocket*, int> SignalCloseEvent; // closed | |
41 }; | |
42 | |
43 class AsyncSocketAdapter : public AsyncSocket, public sigslot::has_slots<> { | |
44 public: | |
45 // The adapted socket may explicitly be null, and later assigned using Attach. | |
46 // However, subclasses which support detached mode must override any methods | |
47 // that will be called during the detached period (usually GetState()), to | |
48 // avoid dereferencing a null pointer. | |
49 explicit AsyncSocketAdapter(AsyncSocket* socket); | |
50 ~AsyncSocketAdapter() override; | |
51 void Attach(AsyncSocket* socket); | |
52 SocketAddress GetLocalAddress() const override; | |
53 SocketAddress GetRemoteAddress() const override; | |
54 int Bind(const SocketAddress& addr) override; | |
55 int Connect(const SocketAddress& addr) override; | |
56 int Send(const void* pv, size_t cb) override; | |
57 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override; | |
58 int Recv(void* pv, size_t cb, int64_t* timestamp) override; | |
59 int RecvFrom(void* pv, | |
60 size_t cb, | |
61 SocketAddress* paddr, | |
62 int64_t* timestamp) override; | |
63 int Listen(int backlog) override; | |
64 AsyncSocket* Accept(SocketAddress* paddr) override; | |
65 int Close() override; | |
66 int GetError() const override; | |
67 void SetError(int error) override; | |
68 ConnState GetState() const override; | |
69 int GetOption(Option opt, int* value) override; | |
70 int SetOption(Option opt, int value) override; | |
71 | |
72 protected: | |
73 virtual void OnConnectEvent(AsyncSocket* socket); | |
74 virtual void OnReadEvent(AsyncSocket* socket); | |
75 virtual void OnWriteEvent(AsyncSocket* socket); | |
76 virtual void OnCloseEvent(AsyncSocket* socket, int err); | |
77 | |
78 AsyncSocket* socket_; | |
79 }; | |
80 | |
81 } // namespace rtc | |
82 | 18 |
83 #endif // WEBRTC_BASE_ASYNCSOCKET_H_ | 19 #endif // WEBRTC_BASE_ASYNCSOCKET_H_ |
OLD | NEW |