Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: webrtc/base/physicalsocketserver.h

Issue 1452903006: Keep listening if "accept" returns an invalid socket. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed presubmit Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/base/physicalsocketserver.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_PHYSICALSOCKETSERVER_H__ 11 #ifndef WEBRTC_BASE_PHYSICALSOCKETSERVER_H__
12 #define WEBRTC_BASE_PHYSICALSOCKETSERVER_H__ 12 #define WEBRTC_BASE_PHYSICALSOCKETSERVER_H__
13 13
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/base/asyncfile.h" 16 #include "webrtc/base/asyncfile.h"
17 #include "webrtc/base/nethelpers.h"
17 #include "webrtc/base/scoped_ptr.h" 18 #include "webrtc/base/scoped_ptr.h"
18 #include "webrtc/base/socketserver.h" 19 #include "webrtc/base/socketserver.h"
19 #include "webrtc/base/criticalsection.h" 20 #include "webrtc/base/criticalsection.h"
20 21
21 #if defined(WEBRTC_POSIX) 22 #if defined(WEBRTC_POSIX)
22 typedef int SOCKET; 23 typedef int SOCKET;
23 #endif // WEBRTC_POSIX 24 #endif // WEBRTC_POSIX
24 25
25 namespace rtc { 26 namespace rtc {
26 27
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DispatcherList dispatchers_; 109 DispatcherList dispatchers_;
109 IteratorList iterators_; 110 IteratorList iterators_;
110 Signaler* signal_wakeup_; 111 Signaler* signal_wakeup_;
111 CriticalSection crit_; 112 CriticalSection crit_;
112 bool fWait_; 113 bool fWait_;
113 #if defined(WEBRTC_WIN) 114 #if defined(WEBRTC_WIN)
114 WSAEVENT socket_ev_; 115 WSAEVENT socket_ev_;
115 #endif 116 #endif
116 }; 117 };
117 118
119 class PhysicalSocket : public AsyncSocket, public sigslot::has_slots<> {
120 public:
121 PhysicalSocket(PhysicalSocketServer* ss, SOCKET s = INVALID_SOCKET);
122 ~PhysicalSocket() override;
123
124 // Creates the underlying OS socket (same as the "socket" function).
125 virtual bool Create(int family, int type);
126
127 SocketAddress GetLocalAddress() const override;
128 SocketAddress GetRemoteAddress() const override;
129
130 int Bind(const SocketAddress& bind_addr) override;
131 int Connect(const SocketAddress& addr) override;
132
133 int GetError() const override;
134 void SetError(int error) override;
135
136 ConnState GetState() const override;
137
138 int GetOption(Option opt, int* value) override;
139 int SetOption(Option opt, int value) override;
140
141 int Send(const void* pv, size_t cb) override;
142 int SendTo(const void* buffer,
143 size_t length,
144 const SocketAddress& addr) override;
145
146 int Recv(void* buffer, size_t length) override;
147 int RecvFrom(void* buffer, size_t length, SocketAddress* out_addr) override;
148
149 int Listen(int backlog) override;
150 AsyncSocket* Accept(SocketAddress* out_addr) override;
151
152 int Close() override;
153
154 int EstimateMTU(uint16_t* mtu) override;
155
156 SocketServer* socketserver() { return ss_; }
157
158 protected:
159 int DoConnect(const SocketAddress& connect_addr);
160
161 // Make virtual so ::accept can be overwritten in tests.
162 virtual SOCKET DoAccept(SOCKET socket, sockaddr* addr, socklen_t* addrlen);
163
164 void OnResolveResult(AsyncResolverInterface* resolver);
165
166 void UpdateLastError();
167 void MaybeRemapSendError();
168
169 static int TranslateOption(Option opt, int* slevel, int* sopt);
170
171 PhysicalSocketServer* ss_;
172 SOCKET s_;
173 uint8_t enabled_events_;
174 bool udp_;
175 mutable CriticalSection crit_;
176 int error_ GUARDED_BY(crit_);
177 ConnState state_;
178 AsyncResolver* resolver_;
179
180 #if !defined(NDEBUG)
181 std::string dbg_addr_;
182 #endif
183 };
184
185 class SocketDispatcher : public Dispatcher, public PhysicalSocket {
186 public:
187 explicit SocketDispatcher(PhysicalSocketServer *ss);
188 SocketDispatcher(SOCKET s, PhysicalSocketServer *ss);
189 ~SocketDispatcher() override;
190
191 bool Initialize();
192
193 virtual bool Create(int type);
194 bool Create(int family, int type) override;
195
196 #if defined(WEBRTC_WIN)
197 WSAEVENT GetWSAEvent() override;
198 SOCKET GetSocket() override;
199 bool CheckSignalClose() override;
200 #elif defined(WEBRTC_POSIX)
201 int GetDescriptor() override;
202 bool IsDescriptorClosed() override;
203 #endif
204
205 uint32_t GetRequestedEvents() override;
206 void OnPreEvent(uint32_t ff) override;
207 void OnEvent(uint32_t ff, int err) override;
208
209 int Close() override;
210
211 #if defined(WEBRTC_WIN)
212 private:
213 static int next_id_;
214 int id_;
215 bool signal_close_;
216 int signal_err_;
217 #endif // WEBRTC_WIN
218 };
219
118 } // namespace rtc 220 } // namespace rtc
119 221
120 #endif // WEBRTC_BASE_PHYSICALSOCKETSERVER_H__ 222 #endif // WEBRTC_BASE_PHYSICALSOCKETSERVER_H__
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/physicalsocketserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698