Bug Summary

File:var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp
Warning:line 1381, column 10
Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name nr_socket_prsock.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/media/webrtc/transport/build -resource-dir /usr/lib/llvm-13/lib/clang/13.0.0 -include /var/lib/jenkins/workspace/firefox-scan-build/config/gcc_hidden.h -include /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D OS_POSIX=1 -D OS_LINUX=1 -D LINUX -D HAVE_STRDUP -D NR_SOCKET_IS_VOID_PTR -D R_DEFINED_INT2=int16_t -D R_DEFINED_UINT2=uint16_t -D R_DEFINED_INT4=int32_t -D R_DEFINED_UINT4=uint32_t -D R_DEFINED_INT8=int64_t -D R_DEFINED_UINT8=uint64_t -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D STATIC_EXPORTABLE_JS_API -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/build -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/media/webrtc/transport/build -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/ipc/ipdl/_ipdlheaders -I /var/lib/jenkins/workspace/firefox-scan-build/ipc/chromium/src -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/crypto -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/ice -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/net -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/stun -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nICEr/src/util -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/event -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/log -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/plugin -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/port/generic/include -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/registry -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/share -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/stats -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/util/libekr -I /var/lib/jenkins/workspace/firefox-scan-build/third_party/libsrtp/src/crypto/include -I /var/lib/jenkins/workspace/firefox-scan-build/third_party/libsrtp/src/include -I /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/third_party/nrappkit/src/port/linux/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -isysroot /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu -internal-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/lib/llvm-13/lib/clang/13.0.0/include -internal-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/usr/local/include -internal-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/usr/include/x86_64-linux-gnu -internal-externc-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/include -internal-externc-isystem /var/lib/jenkins/.mozbuild/sysroot-x86_64-linux-gnu/usr/include -Os -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=backend-plugin -Wno-error=free-nonheap-object -Wno-error=return-std-move -Wno-error=atomic-alignment -Wno-error=deprecated-copy -Wno-error=unused-but-set-variable -Wno-gnu-zero-variadic-macro-arguments -Wno-psabi -Wno-unknown-warning-option -Wno-error=shadow -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/var/lib/jenkins/workspace/firefox-scan-build/obj-x86_64-pc-linux-gnu/dom/media/webrtc/transport/build -ferror-limit 19 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-legacy-pass-manager -fno-aligned-allocation -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2021-08-14-100053-19830-1 -x c++ /var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=2 et sw=2 tw=80: */
3/* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
6/*
7Modified version of nr_socket_local, adapted for NSPR
8*/
9
10/* This Source Code Form is subject to the terms of the Mozilla Public
11 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
12 * You can obtain one at http://mozilla.org/MPL/2.0/. */
13
14/*
15Original code from nICEr and nrappkit.
16
17nICEr copyright:
18
19Copyright (c) 2007, Adobe Systems, Incorporated
20All rights reserved.
21
22Redistribution and use in source and binary forms, with or without
23modification, are permitted provided that the following conditions are
24met:
25
26* Redistributions of source code must retain the above copyright
27 notice, this list of conditions and the following disclaimer.
28
29* Redistributions in binary form must reproduce the above copyright
30 notice, this list of conditions and the following disclaimer in the
31 documentation and/or other materials provided with the distribution.
32
33* Neither the name of Adobe Systems, Network Resonance nor the names of its
34 contributors may be used to endorse or promote products derived from
35 this software without specific prior written permission.
36
37THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
49
50nrappkit copyright:
51
52 Copyright (C) 2001-2003, Network Resonance, Inc.
53 Copyright (C) 2006, Network Resonance, Inc.
54 All Rights Reserved
55
56 Redistribution and use in source and binary forms, with or without
57 modification, are permitted provided that the following conditions
58 are met:
59
60 1. Redistributions of source code must retain the above copyright
61 notice, this list of conditions and the following disclaimer.
62 2. Redistributions in binary form must reproduce the above copyright
63 notice, this list of conditions and the following disclaimer in the
64 documentation and/or other materials provided with the distribution.
65 3. Neither the name of Network Resonance, Inc. nor the name of any
66 contributors to this software may be used to endorse or promote
67 products derived from this software without specific prior written
68 permission.
69
70 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
71 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
74 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
75 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
76 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
77 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
78 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
79 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
80 POSSIBILITY OF SUCH DAMAGE.
81
82
83 ekr@rtfm.com Thu Dec 20 20:14:49 2001
84*/
85
86#include <csi_platform.h>
87#include <stdio.h>
88#include <string.h>
89#include <sys/types.h>
90#include <assert.h>
91#include <errno(*__errno_location ()).h>
92#include <string>
93
94#include "nspr.h"
95#include "prerror.h"
96#include "prio.h"
97#include "prnetdb.h"
98
99#include "mozilla/net/DNS.h"
100#include "nsCOMPtr.h"
101#include "nsASocketHandler.h"
102#include "nsISocketTransportService.h"
103#include "nsNetCID.h"
104#include "nsISupportsImpl.h"
105#include "nsServiceManagerUtils.h"
106#include "nsComponentManagerUtils.h"
107#include "nsXPCOM.h"
108#include "nsXULAppAPI.h"
109#include "runnable_utils.h"
110#include "mozilla/SyncRunnable.h"
111#include "nsTArray.h"
112#include "nsISocketFilter.h"
113#include "nsDebug.h"
114#include "nsNetUtil.h"
115
116#ifdef XP_WIN
117# include "mozilla/WindowsVersion.h"
118#endif
119
120#if defined(MOZILLA_INTERNAL_API1)
121// csi_platform.h deep in nrappkit defines LOG_INFO and LOG_WARNING
122# ifdef LOG_INFO6
123# define LOG_TEMP_INFO LOG_INFO6
124# undef LOG_INFO6
125# endif
126# ifdef LOG_WARNING4
127# define LOG_TEMP_WARNING LOG_WARNING4
128# undef LOG_WARNING4
129# endif
130# if defined(LOG_DEBUG7)
131# define LOG_TEMP_DEBUG LOG_DEBUG7
132# undef LOG_DEBUG7
133# endif
134# undef strlcpy
135
136# include "mozilla/dom/network/UDPSocketChild.h"
137
138# ifdef LOG_TEMP_INFO
139# define LOG_INFO6 LOG_TEMP_INFO
140# endif
141# ifdef LOG_TEMP_WARNING
142# define LOG_WARNING4 LOG_TEMP_WARNING
143# endif
144
145# ifdef LOG_TEMP_DEBUG
146# define LOG_DEBUG7 LOG_TEMP_DEBUG
147# endif
148# ifdef XP_WIN
149# ifdef LOG_DEBUG7
150# undef LOG_DEBUG7
151# endif
152// cloned from csi_platform.h. Win32 doesn't like how we hide symbols
153# define LOG_DEBUG7 7
154# endif
155#endif
156
157extern "C" {
158#include "nr_api.h"
159#include "async_wait.h"
160#include "nr_socket.h"
161#include "nr_socket_local.h"
162#include "stun_hint.h"
163}
164#include "nr_socket_prsock.h"
165#include "simpletokenbucket.h"
166#include "test_nr_socket.h"
167#include "nr_socket_tcp.h"
168#include "nr_socket_proxy_config.h"
169
170// Implement the nsISupports ref counting
171namespace mozilla {
172
173#if defined(MOZILLA_INTERNAL_API1)
174class SingletonThreadHolder final {
175 private:
176 ~SingletonThreadHolder() {
177 r_log(LOG_GENERIC0, LOG_DEBUG7, "Deleting SingletonThreadHolder");
178 if (mThread) {
179 // Likely a connection is somehow being held in CC or GC
180 NS_WARNING(NS_DebugBreak(NS_DEBUG_WARNING, "SingletonThreads should be Released and shut down before exit!"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 181)
181 "SingletonThreads should be Released and shut down before exit!")NS_DebugBreak(NS_DEBUG_WARNING, "SingletonThreads should be Released and shut down before exit!"
, nullptr, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 181)
;
182 mThread->Shutdown();
183 mThread = nullptr;
184 }
185 }
186
187 DISALLOW_COPY_ASSIGN(SingletonThreadHolder)SingletonThreadHolder(const SingletonThreadHolder& other)
= delete; void operator=(const SingletonThreadHolder& other
) = delete
;
188
189 public:
190 // Must be threadsafe for StaticRefPtr/ClearOnShutdown
191 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SingletonThreadHolder)public: MozExternalRefCountType AddRef(void) { static_assert(
!mozilla::IsDestructible<SingletonThreadHolder>::value,
"Reference-counted class " "SingletonThreadHolder" " should not have a public destructor. "
"Make this class's destructor non-public"); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(int32_t
(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
191; ::abort(); } while (false); } } while (false); nsrefcnt
count = ++mRefCnt; NS_LogAddRef((this), (count), ("SingletonThreadHolder"
), (uint32_t)(sizeof(*this))); return (nsrefcnt)count; } MozExternalRefCountType
Release(void) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0
))) { MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " ("
"dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 191
; ::abort(); } while (false); } } while (false); nsrefcnt count
= --mRefCnt; NS_LogRelease((this), (count), ("SingletonThreadHolder"
)); if (count == 0) { delete (this); return 0; } return count
; } using HasThreadSafeRefCnt = std::true_type; protected: ::
mozilla::ThreadSafeAutoRefCnt mRefCnt; public:
192
193 explicit SingletonThreadHolder(const nsACString& aName) : mName(aName) {
194 mParentThread = NS_GetCurrentThread();
195 }
196
197 nsIThread* GetThread() { return mThread; }
198
199 /*
200 * Keep track of how many instances are using a SingletonThreadHolder.
201 * When no one is using it, shut it down
202 */
203 void AddUse() {
204 MOZ_ASSERT(mParentThread == NS_GetCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mParentThread == NS_GetCurrentThread())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mParentThread == NS_GetCurrentThread()))), 0))) { MOZ_ReportAssertionFailure
("mParentThread == NS_GetCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 204); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mParentThread == NS_GetCurrentThread()"
")"); do { *((volatile int*)__null) = 204; ::abort(); } while
(false); } } while (false)
;
205 MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(int32_t(mUseCount) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mUseCount) >= 0))
), 0))) { MOZ_ReportAssertionFailure("int32_t(mUseCount) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 205); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mUseCount) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
205; ::abort(); } while (false); } } while (false)
;
206 nsrefcnt count = ++mUseCount;
207 if (count == 1) {
208 // idle -> in-use
209 nsresult rv = NS_NewNamedThread(mName, getter_AddRefs(mThread));
210 MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv) && mThread,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)) && mThread)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1))) && mThread))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
" (" "Should successfully create mtransport I/O thread" ")",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 211); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
") (" "Should successfully create mtransport I/O thread" ")"
); do { *((volatile int*)__null) = 211; ::abort(); } while (false
); } } while (false)
211 "Should successfully create mtransport I/O thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)
)) && mThread)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1))) && mThread))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
" (" "Should successfully create mtransport I/O thread" ")",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 211); AnnotateMozCrashReason("MOZ_RELEASE_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1))) && mThread"
") (" "Should successfully create mtransport I/O thread" ")"
); do { *((volatile int*)__null) = 211; ::abort(); } while (false
); } } while (false)
;
212 r_log(LOG_GENERIC0, LOG_DEBUG7, "Created wrapped SingletonThread %p",
213 mThread.get());
214 }
215 r_log(LOG_GENERIC0, LOG_DEBUG7, "AddUse_i: %lu", (unsigned long)count);
216 }
217
218 void ReleaseUse() {
219 MOZ_ASSERT(mParentThread == NS_GetCurrentThread())do { static_assert( mozilla::detail::AssertionConditionType<
decltype(mParentThread == NS_GetCurrentThread())>::isValid
, "invalid assertion condition"); if ((__builtin_expect(!!(!(
!!(mParentThread == NS_GetCurrentThread()))), 0))) { MOZ_ReportAssertionFailure
("mParentThread == NS_GetCurrentThread()", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 219); AnnotateMozCrashReason("MOZ_ASSERT" "(" "mParentThread == NS_GetCurrentThread()"
")"); do { *((volatile int*)__null) = 219; ::abort(); } while
(false); } } while (false)
;
220 nsrefcnt count = --mUseCount;
221 MOZ_ASSERT(int32_t(mUseCount) >= 0, "illegal refcnt")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(int32_t(mUseCount) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mUseCount) >= 0))
), 0))) { MOZ_ReportAssertionFailure("int32_t(mUseCount) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 221); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mUseCount) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
221; ::abort(); } while (false); } } while (false)
;
222 if (mThread && count == 0) {
223 // in-use -> idle -- no one forcing it to remain instantiated
224 r_log(LOG_GENERIC0, LOG_DEBUG7, "Shutting down wrapped SingletonThread %p",
225 mThread.get());
226 mThread->AsyncShutdown();
227 mThread = nullptr;
228 // It'd be nice to use a timer instead... But be careful of
229 // xpcom-shutdown-threads in that case
230 }
231 r_log(LOG_GENERIC0, LOG_DEBUG7, "ReleaseUse_i: %lu", (unsigned long)count);
232 }
233
234 private:
235 nsCString mName;
236 nsAutoRefCnt mUseCount;
237 nsCOMPtr<nsIThread> mParentThread;
238 nsCOMPtr<nsIThread> mThread;
239};
240
241static StaticRefPtr<SingletonThreadHolder> sThread;
242
243static void ClearSingletonOnShutdown() {
244 ClearOnShutdown(&sThread, ShutdownPhase::XPCOMShutdownLoaders);
245}
246#endif
247
248static nsIThread* GetIOThreadAndAddUse_s() {
249 // Always runs on STS thread!
250#if defined(MOZILLA_INTERNAL_API1)
251 // We need to safely release this on shutdown to avoid leaks
252 if (!sThread) {
253 sThread = new SingletonThreadHolder("mtransport"_ns);
254 NS_DispatchToMainThread(mozilla::WrapRunnableNM(&ClearSingletonOnShutdown));
255 }
256 // Mark that we're using the shared thread and need it to stick around
257 sThread->AddUse();
258 return sThread->GetThread();
259#else
260 static nsCOMPtr<nsIThread> sThread;
261 if (!sThread) {
262 (void)NS_NewNamedThread("mtransport", getter_AddRefs(sThread));
263 }
264 return sThread;
265#endif
266}
267
268NrSocketIpc::NrSocketIpc(nsIEventTarget* aThread) : io_thread_(aThread) {}
269
270static TimeStamp nr_socket_short_term_violation_time;
271static TimeStamp nr_socket_long_term_violation_time;
272
273TimeStamp NrSocketBase::short_term_violation_time() {
274 return nr_socket_short_term_violation_time;
275}
276
277TimeStamp NrSocketBase::long_term_violation_time() {
278 return nr_socket_long_term_violation_time;
279}
280
281// NrSocketBase implementation
282// async_event APIs
283int NrSocketBase::async_wait(int how, NR_async_cb cb, void* cb_arg,
284 char* function, int line) {
285 uint16_t flag;
286
287 switch (how) {
288 case NR_ASYNC_WAIT_READ0:
289 flag = PR_POLL_READ0x1;
290 break;
291 case NR_ASYNC_WAIT_WRITE1:
292 flag = PR_POLL_WRITE0x2;
293 break;
294 default:
295 return R_BAD_ARGS6;
296 }
297
298 cbs_[how] = cb;
299 cb_args_[how] = cb_arg;
300 poll_flags_ |= flag;
301
302 return 0;
303}
304
305int NrSocketBase::cancel(int how) {
306 uint16_t flag;
307
308 switch (how) {
309 case NR_ASYNC_WAIT_READ0:
310 flag = PR_POLL_READ0x1;
311 break;
312 case NR_ASYNC_WAIT_WRITE1:
313 flag = PR_POLL_WRITE0x2;
314 break;
315 default:
316 return R_BAD_ARGS6;
317 }
318
319 poll_flags_ &= ~flag;
320
321 return 0;
322}
323
324void NrSocketBase::fire_callback(int how) {
325 // This can't happen unless we are armed because we only set
326 // the flags if we are armed
327 MOZ_ASSERT(cbs_[how])do { static_assert( mozilla::detail::AssertionConditionType<
decltype(cbs_[how])>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(cbs_[how]))), 0))) { MOZ_ReportAssertionFailure
("cbs_[how]", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 327); AnnotateMozCrashReason("MOZ_ASSERT" "(" "cbs_[how]" ")"
); do { *((volatile int*)__null) = 327; ::abort(); } while (false
); } } while (false)
;
328
329 // Now cancel so that we need to be re-armed. Note that
330 // the re-arming probably happens in the callback we are
331 // about to fire.
332 cancel(how);
333
334 cbs_[how](this, how, cb_args_[how]);
335}
336
337// NrSocket implementation
338NS_IMPL_ISUPPORTS0(NrSocket)MozExternalRefCountType NrSocket::AddRef(void) { static_assert
(!mozilla::IsDestructible<NrSocket>::value, "Reference-counted class "
"NrSocket" " should not have a public destructor. " "Make this class's destructor non-public"
); do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 338); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
338; ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype("NrSocket"
!= nullptr)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!("NrSocket" != nullptr))), 0))) { MOZ_ReportAssertionFailure
("\"NrSocket\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 338); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"NrSocket\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 338; ::abort(); } while (false); } } while (false); if (!
mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership("NrSocket"
" not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef
((this), (count), ("NrSocket"), (uint32_t)(sizeof(*this))); return
count; } MozExternalRefCountType NrSocket::Release(void) { do
{ static_assert( mozilla::detail::AssertionConditionType<
decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0
))) { MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " ("
"dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 338); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 338
; ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype("NrSocket"
!= nullptr)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!("NrSocket" != nullptr))), 0))) { MOZ_ReportAssertionFailure
("\"NrSocket\" != nullptr" " (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 338); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"NrSocket\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 338; ::abort(); } while (false); } } while (false); if (!
mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership("NrSocket"
" not thread-safe"); const char* const nametmp = "NrSocket";
nsrefcnt count = --mRefCnt; NS_LogRelease((this), (count), (
nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return
0; } return count; } nsresult NrSocket::QueryInterface(const
nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 338); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static const QITableEntry table[] = { {&(nsISupports::COMTypeInfo
<nsISupports, void>::kIID), int32_t( reinterpret_cast<
char*>(static_cast<nsISupports*>((NrSocket*)0x1000))
- reinterpret_cast<char*>((NrSocket*)0x1000))}, { nullptr
, 0 } } ; static_assert((sizeof(table) / sizeof(table[0])) >
1, "need at least 1 interface"); rv = NS_TableDrivenQI(static_cast
<void*>(this), aIID, aInstancePtr, table); return rv; }
339
340// The nsASocket callbacks
341void NrSocket::OnSocketReady(PRFileDesc* fd, int16_t outflags) {
342 if (outflags & PR_POLL_READ0x1 & poll_flags()) fire_callback(NR_ASYNC_WAIT_READ0);
343 if (outflags & PR_POLL_WRITE0x2 & poll_flags())
344 fire_callback(NR_ASYNC_WAIT_WRITE1);
345 if (outflags & (PR_POLL_ERR0x8 | PR_POLL_NVAL0x10 | PR_POLL_HUP0x20))
346 // TODO: Bug 946423: how do we notify the upper layers about this?
347 close();
348}
349
350void NrSocket::OnSocketDetached(PRFileDesc* fd) {
351 r_log(LOG_GENERIC0, LOG_DEBUG7, "Socket %p detached", fd);
352}
353
354void NrSocket::IsLocal(bool* aIsLocal) {
355 // TODO(jesup): better check? Does it matter? (likely no)
356 *aIsLocal = false;
357}
358
359// async_event APIs
360int NrSocket::async_wait(int how, NR_async_cb cb, void* cb_arg, char* function,
361 int line) {
362 int r = NrSocketBase::async_wait(how, cb, cb_arg, function, line);
363
364 if (!r) {
365 mPollFlags = poll_flags();
366 }
367
368 return r;
369}
370
371int NrSocket::cancel(int how) {
372 int r = NrSocketBase::cancel(how);
373
374 if (!r) {
375 mPollFlags = poll_flags();
376 }
377
378 return r;
379}
380
381// Helper functions for addresses
382static int nr_transport_addr_to_praddr(const nr_transport_addr* addr,
383 PRNetAddr* naddr) {
384 int _status;
385
386 memset(naddr, 0, sizeof(*naddr));
387
388 switch (addr->protocol) {
389 case IPPROTO_TCPIPPROTO_TCP:
390 break;
391 case IPPROTO_UDPIPPROTO_UDP:
392 break;
393 default:
394 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
395 }
396
397 switch (addr->ip_version) {
398 case NR_IPV44:
399 naddr->inet.family = PR_AF_INET2;
400 naddr->inet.port = addr->u.addr4.sin_port;
401 naddr->inet.ip = addr->u.addr4.sin_addr.s_addr;
402 break;
403 case NR_IPV66:
404 naddr->ipv6.family = PR_AF_INET610;
405 naddr->ipv6.port = addr->u.addr6.sin6_port;
406 naddr->ipv6.flowinfo = addr->u.addr6.sin6_flowinfo;
407 memcpy(&naddr->ipv6.ip, &addr->u.addr6.sin6_addr, sizeof(in6_addr));
408 naddr->ipv6.scope_id = addr->u.addr6.sin6_scope_id;
409 break;
410 default:
411 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
412 }
413
414 _status = 0;
415abort:
416 return (_status);
417}
418
419// XXX schien@mozilla.com: copy from PRNetAddrToNetAddr,
420// should be removed after fix the link error in signaling_unittests
421static int praddr_to_netaddr(const PRNetAddr* prAddr, net::NetAddr* addr) {
422 int _status;
423
424 switch (prAddr->raw.family) {
425 case PR_AF_INET2:
426 addr->inet.family = AF_INET2;
427 addr->inet.port = prAddr->inet.port;
428 addr->inet.ip = prAddr->inet.ip;
429 break;
430 case PR_AF_INET610:
431 addr->inet6.family = AF_INET610;
432 addr->inet6.port = prAddr->ipv6.port;
433 addr->inet6.flowinfo = prAddr->ipv6.flowinfo;
434 memcpy(&addr->inet6.ip, &prAddr->ipv6.ip, sizeof(addr->inet6.ip.u8));
435 addr->inet6.scope_id = prAddr->ipv6.scope_id;
436 break;
437 default:
438 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 438); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")");
do { *((volatile int*)__null) = 438; ::abort(); } while (false
); } } while (false)
;
439 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
440 }
441
442 _status = 0;
443abort:
444 return (_status);
445}
446
447static int nr_transport_addr_to_netaddr(const nr_transport_addr* addr,
448 net::NetAddr* naddr) {
449 int r, _status;
450 PRNetAddr praddr;
451
452 if ((r = nr_transport_addr_to_praddr(addr, &praddr))) {
453 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
454 }
455
456 if ((r = praddr_to_netaddr(&praddr, naddr))) {
457 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
458 }
459
460 _status = 0;
461abort:
462 return (_status);
463}
464
465int nr_netaddr_to_transport_addr(const net::NetAddr* netaddr,
466 nr_transport_addr* addr, int protocol) {
467 int _status;
468 int r;
469
470 switch (netaddr->raw.family) {
471 case AF_INET2:
472 if ((r = nr_ip4_port_to_transport_addr(ntohl(netaddr->inet.ip)(__extension__ ({ unsigned int __v, __x = (netaddr->inet.ip
); if (__builtin_constant_p (__x)) __v = ((((__x) & 0xff000000
) >> 24) | (((__x) & 0x00ff0000) >> 8) | (((__x
) & 0x0000ff00) << 8) | (((__x) & 0x000000ff) <<
24)); else __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); __v
; }))
,
473 ntohs(netaddr->inet.port)(__extension__ ({ unsigned short int __v, __x = (unsigned short
int) (netaddr->inet.port); if (__builtin_constant_p (__x)
) __v = ((unsigned short int) ((((__x) >> 8) & 0xff
) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0"
: "=r" (__v) : "0" (__x) : "cc"); __v; }))
,
474 protocol, addr)))
475 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
476 break;
477 case AF_INET610:
478 if ((r = nr_ip6_port_to_transport_addr((in6_addr*)&netaddr->inet6.ip.u8,
479 ntohs(netaddr->inet6.port)(__extension__ ({ unsigned short int __v, __x = (unsigned short
int) (netaddr->inet6.port); if (__builtin_constant_p (__x
)) __v = ((unsigned short int) ((((__x) >> 8) & 0xff
) | (((__x) & 0xff) << 8))); else __asm__ ("rorw $8, %w0"
: "=r" (__v) : "0" (__x) : "cc"); __v; }))
,
480 protocol, addr)))
481 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
482 break;
483 default:
484 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 484); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")");
do { *((volatile int*)__null) = 484; ::abort(); } while (false
); } } while (false)
;
485 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
486 }
487 _status = 0;
488abort:
489 return (_status);
490}
491
492int nr_praddr_to_transport_addr(const PRNetAddr* praddr,
493 nr_transport_addr* addr, int protocol,
494 int keep) {
495 int _status;
496 int r;
497 struct sockaddr_in ip4;
498 struct sockaddr_in6 ip6;
499
500 switch (praddr->raw.family) {
501 case PR_AF_INET2:
502 ip4.sin_family = PF_INET2;
503 ip4.sin_addr.s_addr = praddr->inet.ip;
504 ip4.sin_port = praddr->inet.port;
505 if ((r = nr_sockaddr_to_transport_addr((sockaddr*)&ip4, protocol, keep,
506 addr)))
507 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
508 break;
509 case PR_AF_INET610:
510 ip6.sin6_family = PF_INET610;
511 ip6.sin6_port = praddr->ipv6.port;
512 ip6.sin6_flowinfo = praddr->ipv6.flowinfo;
513 memcpy(&ip6.sin6_addr, &praddr->ipv6.ip, sizeof(in6_addr));
514 ip6.sin6_scope_id = praddr->ipv6.scope_id;
515 if ((r = nr_sockaddr_to_transport_addr((sockaddr*)&ip6, protocol, keep,
516 addr)))
517 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
518 break;
519 default:
520 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 520); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")");
do { *((volatile int*)__null) = 520; ::abort(); } while (false
); } } while (false)
;
521 ABORT(R_BAD_ARGS)do { int _r=6; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
522 }
523
524 _status = 0;
525abort:
526 return (_status);
527}
528
529/*
530 * nr_transport_addr_get_addrstring_and_port
531 * convert nr_transport_addr to IP address string and port number
532 */
533int nr_transport_addr_get_addrstring_and_port(const nr_transport_addr* addr,
534 nsACString* host, int32_t* port) {
535 int r, _status;
536 char addr_string[64];
537
538 // We cannot directly use |nr_transport_addr.as_string| because it contains
539 // more than ip address, therefore, we need to explicity convert it
540 // from |nr_transport_addr_get_addrstring|.
541 if ((r = nr_transport_addr_get_addrstring(addr, addr_string,
542 sizeof(addr_string)))) {
543 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
544 }
545
546 if ((r = nr_transport_addr_get_port(addr, port))) {
547 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
548 }
549
550 *host = addr_string;
551
552 _status = 0;
553abort:
554 return (_status);
555}
556
557// nr_socket APIs (as member functions)
558int NrSocket::create(nr_transport_addr* addr) {
559 int r, _status;
560
561 PRStatus status;
562 PRNetAddr naddr;
563
564 nsresult rv;
565 nsCOMPtr<nsISocketTransportService> stservice =
566 do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
567
568 if (!NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
569 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
570 }
571
572 if ((r = nr_transport_addr_to_praddr(addr, &naddr))) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
573
574 switch (addr->protocol) {
575 case IPPROTO_UDPIPPROTO_UDP:
576 if (!(fd_ = PR_OpenUDPSocket(naddr.raw.family))) {
577 r_log(LOG_GENERIC0, LOG_CRIT2,
578 "Couldn't create UDP socket, "
579 "family=%d, err=%d",
580 naddr.raw.family, PR_GetError());
581 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
582 }
583#ifdef XP_WIN
584 if (!mozilla::IsWin8OrLater()) {
585 // Increase default send and receive buffer sizes on <= Win7 to be able
586 // to receive and send an unpaced HD (>= 720p = 1280x720 - I Frame ~ 21K
587 // size) stream without losing packets. Manual testing showed that 100K
588 // buffer size was not enough and the packet loss dis-appeared with 256K
589 // buffer size. See bug 1252769 for future improvements of this.
590 PRSize min_buffer_size = 256 * 1024;
591 PRSocketOptionData opt_rcvbuf;
592 opt_rcvbuf.option = PR_SockOpt_RecvBufferSize;
593 if ((status = PR_GetSocketOption(fd_, &opt_rcvbuf)) == PR_SUCCESS) {
594 if (opt_rcvbuf.value.recv_buffer_size < min_buffer_size) {
595 opt_rcvbuf.value.recv_buffer_size = min_buffer_size;
596 if ((status = PR_SetSocketOption(fd_, &opt_rcvbuf)) != PR_SUCCESS) {
597 r_log(LOG_GENERIC0, LOG_CRIT2,
598 "Couldn't set socket receive buffer size: %d", status);
599 }
600 } else {
601 r_log(LOG_GENERIC0, LOG_INFO6,
602 "Socket receive buffer size is already: %d",
603 opt_rcvbuf.value.recv_buffer_size);
604 }
605 } else {
606 r_log(LOG_GENERIC0, LOG_CRIT2,
607 "Couldn't get socket receive buffer size: %d", status);
608 }
609 PRSocketOptionData opt_sndbuf;
610 opt_sndbuf.option = PR_SockOpt_SendBufferSize;
611 if ((status = PR_GetSocketOption(fd_, &opt_sndbuf)) == PR_SUCCESS) {
612 if (opt_sndbuf.value.recv_buffer_size < min_buffer_size) {
613 opt_sndbuf.value.recv_buffer_size = min_buffer_size;
614 if ((status = PR_SetSocketOption(fd_, &opt_sndbuf)) != PR_SUCCESS) {
615 r_log(LOG_GENERIC0, LOG_CRIT2,
616 "Couldn't set socket send buffer size: %d", status);
617 }
618 } else {
619 r_log(LOG_GENERIC0, LOG_INFO6,
620 "Socket send buffer size is already: %d",
621 opt_sndbuf.value.recv_buffer_size);
622 }
623 } else {
624 r_log(LOG_GENERIC0, LOG_CRIT2,
625 "Couldn't get socket send buffer size: %d", status);
626 }
627 }
628#endif
629 break;
630 case IPPROTO_TCPIPPROTO_TCP:
631 // TODO: Rewrite this to use WebrtcTcpSocket.
632 // Also use the same logic for TLS.
633 if (my_addr_.fqdn[0] != '\0') ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
634
635 if (!(fd_ = PR_OpenTCPSocket(naddr.raw.family))) {
636 r_log(LOG_GENERIC0, LOG_CRIT2,
637 "Couldn't create TCP socket, "
638 "family=%d, err=%d",
639 naddr.raw.family, PR_GetError());
640 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
641 }
642 // Set ReuseAddr for TCP sockets to enable having several
643 // sockets bound to same local IP and port
644 PRSocketOptionData opt_reuseaddr;
645 opt_reuseaddr.option = PR_SockOpt_Reuseaddr;
646 opt_reuseaddr.value.reuse_addr = PR_TRUE1;
647 status = PR_SetSocketOption(fd_, &opt_reuseaddr);
648 if (status != PR_SUCCESS) {
649 r_log(LOG_GENERIC0, LOG_CRIT2,
650 "Couldn't set reuse addr socket option: %d", status);
651 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
652 }
653 // And also set ReusePort for platforms supporting this socket option
654 PRSocketOptionData opt_reuseport;
655 opt_reuseport.option = PR_SockOpt_Reuseport;
656 opt_reuseport.value.reuse_port = PR_TRUE1;
657 status = PR_SetSocketOption(fd_, &opt_reuseport);
658 if (status != PR_SUCCESS) {
659 if (PR_GetError() != PR_OPERATION_NOT_SUPPORTED_ERROR(-5965L)) {
660 r_log(LOG_GENERIC0, LOG_CRIT2,
661 "Couldn't set reuse port socket option: %d", status);
662 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
663 }
664 }
665 // Try to speedup packet delivery by disabling TCP Nagle
666 PRSocketOptionData opt_nodelay;
667 opt_nodelay.option = PR_SockOpt_NoDelay;
668 opt_nodelay.value.no_delay = PR_TRUE1;
669 status = PR_SetSocketOption(fd_, &opt_nodelay);
670 if (status != PR_SUCCESS) {
671 r_log(LOG_GENERIC0, LOG_WARNING4,
672 "Couldn't set Nodelay socket option: %d", status);
673 }
674 break;
675 default:
676 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
677 }
678
679 status = PR_Bind(fd_, &naddr);
680 if (status != PR_SUCCESS) {
681 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't bind socket to address %s",
682 addr->as_string);
683 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
684 }
685
686 r_log(LOG_GENERIC0, LOG_DEBUG7, "Creating socket %p with addr %s", fd_,
687 addr->as_string);
688 nr_transport_addr_copy(&my_addr_, addr);
689
690 /* If we have a wildcard port, patch up the addr */
691 if (nr_transport_addr_is_wildcard(addr)) {
692 status = PR_GetSockName(fd_, &naddr);
693 if (status != PR_SUCCESS) {
694 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't get sock name for socket");
695 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
696 }
697
698 if ((r = nr_praddr_to_transport_addr(&naddr, &my_addr_, addr->protocol, 1)))
699 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
700 }
701
702 // Set nonblocking
703 PRSocketOptionData opt_nonblock;
704 opt_nonblock.option = PR_SockOpt_Nonblocking;
705 opt_nonblock.value.non_blocking = PR_TRUE1;
706 status = PR_SetSocketOption(fd_, &opt_nonblock);
707 if (status != PR_SUCCESS) {
708 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't make socket nonblocking");
709 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
710 }
711
712 // Remember our thread.
713 ststhread_ = do_QueryInterface(stservice, &rv);
714 if (!NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
715
716 // Finally, register with the STS
717 rv = stservice->AttachSocket(fd_, this);
718 if (!NS_SUCCEEDED(rv)((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))) {
719 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't attach socket to STS, rv=%u",
720 static_cast<unsigned>(rv));
721 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
722 }
723
724 _status = 0;
725
726abort:
727 return (_status);
728}
729
730static int ShouldDrop(size_t len) {
731 // Global rate limiting for stun requests, to mitigate the ice hammer DoS
732 // (see http://tools.ietf.org/html/draft-thomson-mmusic-ice-webrtc)
733
734 // Tolerate rate of 8k/sec, for one second.
735 static SimpleTokenBucket burst(16384 * 1, 16384);
736 // Tolerate rate of 7.2k/sec over twenty seconds.
737 static SimpleTokenBucket sustained(7372 * 20, 7372);
738
739 // Check number of tokens in each bucket.
740 if (burst.getTokens(UINT32_MAX(4294967295U)) < len) {
741 r_log(LOG_GENERIC0, LOG_ERR3,
742 "Short term global rate limit for STUN requests exceeded.");
743#ifdef MOZILLA_INTERNAL_API1
744 nr_socket_short_term_violation_time = TimeStamp::Now();
745#endif
746
747// Bug 1013007
748#if !EARLY_BETA_OR_EARLIER1
749 return R_WOULDBLOCK8;
750#else
751 MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 754); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 754; ::abort(); } while
(false); } } while (false)
752 "Short term global rate limit for STUN requests exceeded. Go "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 754); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 754; ::abort(); } while
(false); } } while (false)
753 "bug bcampen@mozilla.com if you weren't intentionally "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 754); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 754; ::abort(); } while
(false); } } while (false)
754 "spamming ICE candidates, or don't know what that means.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 754); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Short term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 754; ::abort(); } while
(false); } } while (false)
;
755#endif
756 }
757
758 if (sustained.getTokens(UINT32_MAX(4294967295U)) < len) {
759 r_log(LOG_GENERIC0, LOG_ERR3,
760 "Long term global rate limit for STUN requests exceeded.");
761#ifdef MOZILLA_INTERNAL_API1
762 nr_socket_long_term_violation_time = TimeStamp::Now();
763#endif
764// Bug 1013007
765#if !EARLY_BETA_OR_EARLIER1
766 return R_WOULDBLOCK8;
767#else
768 MOZ_ASSERT(false,do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 771); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 771; ::abort(); } while
(false); } } while (false)
769 "Long term global rate limit for STUN requests exceeded. Go "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 771); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 771; ::abort(); } while
(false); } } while (false)
770 "bug bcampen@mozilla.com if you weren't intentionally "do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 771); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 771; ::abort(); } while
(false); } } while (false)
771 "spamming ICE candidates, or don't know what that means.")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 771); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Long term global rate limit for STUN requests exceeded. Go "
"bug bcampen@mozilla.com if you weren't intentionally " "spamming ICE candidates, or don't know what that means."
")"); do { *((volatile int*)__null) = 771; ::abort(); } while
(false); } } while (false)
;
772#endif
773 }
774
775 // Take len tokens from both buckets.
776 // (not threadsafe, but no problem since this is only called from STS)
777 burst.getTokens(len);
778 sustained.getTokens(len);
779 return 0;
780}
781
782// This should be called on the STS thread.
783int NrSocket::sendto(const void* msg, size_t len, int flags,
784 const nr_transport_addr* to) {
785 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 785); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 785; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 785); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 785; ::abort(); } while (false)
; } } while (false); } } while (0)
;
786 int r, _status;
787 PRNetAddr naddr;
788 int32_t status;
789
790 if ((r = nr_transport_addr_to_praddr(to, &naddr))) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
791
792 if (fd_ == nullptr) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
793
794 if (nr_is_stun_request_message((UCHAR*)msg, len) && ShouldDrop(len)) {
795 ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
796 }
797
798 // TODO: Convert flags?
799 status = PR_SendTo(fd_, msg, len, flags, &naddr, PR_INTERVAL_NO_WAIT0UL);
800 if (status < 0 || (size_t)status != len) {
801 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
802
803 r_log(LOG_GENERIC0, LOG_INFO6, "Error in sendto %s: %d", to->as_string,
804 PR_GetError());
805 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
806 }
807
808 _status = 0;
809abort:
810 return (_status);
811}
812
813int NrSocket::recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
814 nr_transport_addr* from) {
815 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 815); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 815; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 815); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 815; ::abort(); } while (false)
; } } while (false); } } while (0)
;
816 int r, _status;
817 PRNetAddr nfrom;
818 int32_t status;
819
820 status = PR_RecvFrom(fd_, buf, maxlen, flags, &nfrom, PR_INTERVAL_NO_WAIT0UL);
821 if (status <= 0) {
822 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
823 r_log(LOG_GENERIC0, LOG_INFO6, "Error in recvfrom: %d", (int)PR_GetError());
824 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
825 }
826 *len = status;
827
828 if ((r = nr_praddr_to_transport_addr(&nfrom, from, my_addr_.protocol, 0)))
829 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
830
831 // r_log(LOG_GENERIC,LOG_DEBUG,"Read %d bytes from %s",*len,addr->as_string);
832
833 _status = 0;
834abort:
835 return (_status);
836}
837
838int NrSocket::getaddr(nr_transport_addr* addrp) {
839 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 839); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 839; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 839); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 839; ::abort(); } while (false)
; } } while (false); } } while (0)
;
840 return nr_transport_addr_copy(addrp, &my_addr_);
841}
842
843// Close the socket so that the STS will detach and then kill it
844void NrSocket::close() {
845 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 845); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 845; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 845); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 845; ::abort(); } while (false)
; } } while (false); } } while (0)
;
846 mCondition = NS_BASE_STREAM_CLOSED;
847 cancel(NR_ASYNC_WAIT_READ0);
848 cancel(NR_ASYNC_WAIT_WRITE1);
849}
850
851int NrSocket::connect(const nr_transport_addr* addr) {
852 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 852); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 852; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 852); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 852; ::abort(); } while (false)
; } } while (false); } } while (0)
;
853 int r, _status;
854 PRNetAddr naddr;
855 int32_t connect_status, getsockname_status;
856
857 if ((r = nr_transport_addr_to_praddr(addr, &naddr))) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
858
859 if (!fd_) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
860
861 // Note: this just means we tried to connect, not that we
862 // are actually live.
863 connect_invoked_ = true;
864 connect_status = PR_Connect(fd_, &naddr, PR_INTERVAL_NO_WAIT0UL);
865 if (connect_status != PR_SUCCESS) {
866 if (PR_GetError() != PR_IN_PROGRESS_ERROR(-5934L)) {
867 r_log(LOG_GENERIC0, LOG_CRIT2, "PR_Connect failed: %d", PR_GetError());
868 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
869 }
870 }
871
872 // If our local address is wildcard, then fill in the
873 // address now.
874 if (nr_transport_addr_is_wildcard(&my_addr_)) {
875 getsockname_status = PR_GetSockName(fd_, &naddr);
876 if (getsockname_status != PR_SUCCESS) {
877 r_log(LOG_GENERIC0, LOG_CRIT2, "Couldn't get sock name for socket");
878 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
879 }
880
881 if ((r = nr_praddr_to_transport_addr(&naddr, &my_addr_, addr->protocol, 1)))
882 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
883 }
884
885 // Now return the WOULDBLOCK if needed.
886 if (connect_status != PR_SUCCESS) {
887 ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
888 }
889
890 _status = 0;
891abort:
892 return (_status);
893}
894
895int NrSocket::write(const void* msg, size_t len, size_t* written) {
896 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 896); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 896; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 896); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 896; ::abort(); } while (false)
; } } while (false); } } while (0)
;
897 int _status;
898 int32_t status;
899
900 if (!connect_invoked_) ABORT(R_FAILED)do { int _r=10; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
901
902 status = PR_Write(fd_, msg, len);
903 if (status < 0) {
904 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
905 r_log(LOG_GENERIC0, LOG_INFO6, "Error in write");
906 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
907 }
908
909 *written = status;
910
911 _status = 0;
912abort:
913 return _status;
914}
915
916int NrSocket::read(void* buf, size_t maxlen, size_t* len) {
917 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 917); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 917; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 917); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 917; ::abort(); } while (false)
; } } while (false); } } while (0)
;
918 int _status;
919 int32_t status;
920
921 if (!connect_invoked_) ABORT(R_FAILED)do { int _r=10; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
922
923 status = PR_Read(fd_, buf, maxlen);
924 if (status < 0) {
925 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
926 r_log(LOG_GENERIC0, LOG_INFO6, "Error in read");
927 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
928 }
929 if (status == 0) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
930
931 *len = (size_t)status; // Guaranteed to be > 0
932 _status = 0;
933abort:
934 return (_status);
935}
936
937int NrSocket::listen(int backlog) {
938 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 938); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 938; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 938); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 938; ::abort(); } while (false)
; } } while (false); } } while (0)
;
939 int32_t status;
940 int _status;
941
942 assert(fd_)((fd_) ? static_cast<void> (0) : __assert_fail ("fd_", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 942, __PRETTY_FUNCTION__))
;
943 status = PR_Listen(fd_, backlog);
944 if (status != PR_SUCCESS) {
945 r_log(LOG_GENERIC0, LOG_CRIT2, "%s: PR_GetError() == %d", __FUNCTION__,
946 PR_GetError());
947 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
948 }
949
950 _status = 0;
951abort:
952 return (_status);
953}
954
955int NrSocket::accept(nr_transport_addr* addrp, nr_socket** sockp) {
956 ASSERT_ON_THREAD(ststhread_)do { if (ststhread_) { bool on; nsresult rv; rv = ststhread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 956); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 956; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 956); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 956; ::abort(); } while (false)
; } } while (false); } } while (0)
;
957 int _status, r;
958 PRStatus status;
959 PRFileDesc* prfd;
960 PRNetAddr nfrom;
961 NrSocket* sock = nullptr;
962 nsresult rv;
963 PRSocketOptionData opt_nonblock, opt_nodelay;
964 nsCOMPtr<nsISocketTransportService> stservice =
965 do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
966
967 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
968 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
969 }
970
971 if (!fd_) ABORT(R_EOD)do { int _r=5; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
972
973 prfd = PR_Accept(fd_, &nfrom, PR_INTERVAL_NO_WAIT0UL);
974
975 if (!prfd) {
976 if (PR_GetError() == PR_WOULD_BLOCK_ERROR(-5998L)) ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
977
978 ABORT(R_IO_ERROR)do { int _r=13; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
979 }
980
981 sock = new NrSocket();
982
983 sock->fd_ = prfd;
984 nr_transport_addr_copy(&sock->my_addr_, &my_addr_);
985
986 if ((r = nr_praddr_to_transport_addr(&nfrom, addrp, my_addr_.protocol, 0)))
987 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
988
989 // Set nonblocking
990 opt_nonblock.option = PR_SockOpt_Nonblocking;
991 opt_nonblock.value.non_blocking = PR_TRUE1;
992 status = PR_SetSocketOption(prfd, &opt_nonblock);
993 if (status != PR_SUCCESS) {
994 r_log(LOG_GENERIC0, LOG_CRIT2,
995 "Failed to make accepted socket nonblocking: %d", status);
996 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
997 }
998 // Disable TCP Nagle
999 opt_nodelay.option = PR_SockOpt_NoDelay;
1000 opt_nodelay.value.no_delay = PR_TRUE1;
1001 status = PR_SetSocketOption(prfd, &opt_nodelay);
1002 if (status != PR_SUCCESS) {
1003 r_log(LOG_GENERIC0, LOG_WARNING4,
1004 "Failed to set Nodelay on accepted socket: %d", status);
1005 }
1006
1007 // Should fail only with OOM
1008 if ((r = nr_socket_create_int(static_cast<void*>(sock), sock->vtbl(), sockp)))
1009 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1010
1011 // Remember our thread.
1012 sock->ststhread_ = do_QueryInterface(stservice, &rv);
1013 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1014
1015 // Finally, register with the STS
1016 rv = stservice->AttachSocket(prfd, sock);
1017 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1018 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1019 }
1020
1021 sock->connect_invoked_ = true;
1022
1023 // Add a reference so that we can delete it in destroy()
1024 sock->AddRef();
1025 _status = 0;
1026abort:
1027 if (_status) {
1028 delete sock;
1029 }
1030
1031 return (_status);
1032}
1033
1034NS_IMPL_ISUPPORTS(NrUdpSocketIpcProxy, nsIUDPSocketInternal)MozExternalRefCountType NrUdpSocketIpcProxy::AddRef(void) { static_assert
(!mozilla::IsDestructible<NrUdpSocketIpcProxy>::value, "Reference-counted class "
"NrUdpSocketIpcProxy" " should not have a public destructor. "
"Make this class's destructor non-public"); do { static_assert
( mozilla::detail::AssertionConditionType<decltype(int32_t
(mRefCnt) >= 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))),
0))) { MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0"
" (" "illegal refcnt" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1034); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0"
") (" "illegal refcnt" ")"); do { *((volatile int*)__null) =
1034; ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype("NrUdpSocketIpcProxy"
!= nullptr)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!("NrUdpSocketIpcProxy" != nullptr)
)), 0))) { MOZ_ReportAssertionFailure("\"NrUdpSocketIpcProxy\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1034); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"NrUdpSocketIpcProxy\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 1034; ::abort(); } while (false); } } while (false); if (
!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership("NrUdpSocketIpcProxy"
" not thread-safe"); nsrefcnt count = ++mRefCnt; NS_LogAddRef
((this), (count), ("NrUdpSocketIpcProxy"), (uint32_t)(sizeof(
*this))); return count; } MozExternalRefCountType NrUdpSocketIpcProxy
::Release(void) { do { static_assert( mozilla::detail::AssertionConditionType
<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) > 0))), 0
))) { MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " ("
"dup release" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1034); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0"
") (" "dup release" ")"); do { *((volatile int*)__null) = 1034
; ::abort(); } while (false); } } while (false); do { static_assert
( mozilla::detail::AssertionConditionType<decltype("NrUdpSocketIpcProxy"
!= nullptr)>::isValid, "invalid assertion condition"); if
((__builtin_expect(!!(!(!!("NrUdpSocketIpcProxy" != nullptr)
)), 0))) { MOZ_ReportAssertionFailure("\"NrUdpSocketIpcProxy\" != nullptr"
" (" "Must specify a name" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1034); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"NrUdpSocketIpcProxy\" != nullptr"
") (" "Must specify a name" ")"); do { *((volatile int*)__null
) = 1034; ::abort(); } while (false); } } while (false); if (
!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership("NrUdpSocketIpcProxy"
" not thread-safe"); const char* const nametmp = "NrUdpSocketIpcProxy"
; nsrefcnt count = --mRefCnt; NS_LogRelease((this), (count), (
nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return
0; } return count; } nsresult NrUdpSocketIpcProxy::QueryInterface
(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr
)) { NS_DebugBreak(NS_DEBUG_ASSERTION, "QueryInterface requires a non-NULL destination!"
, "aInstancePtr", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1034); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE
; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE"
); static const QITableEntry table[] = { {&(nsIUDPSocketInternal
::COMTypeInfo<nsIUDPSocketInternal, void>::kIID), int32_t
( reinterpret_cast<char*>(static_cast<nsIUDPSocketInternal
*>((NrUdpSocketIpcProxy*)0x1000)) - reinterpret_cast<char
*>((NrUdpSocketIpcProxy*)0x1000))}, {&(nsISupports::COMTypeInfo
<nsISupports, void>::kIID), int32_t(reinterpret_cast<
char*>(static_cast<nsISupports*>( static_cast<nsIUDPSocketInternal
*>((NrUdpSocketIpcProxy*)0x1000))) - reinterpret_cast<char
*>((NrUdpSocketIpcProxy*)0x1000))}, { nullptr, 0 } } ; static_assert
((sizeof(table) / sizeof(table[0])) > 1, "need at least 1 interface"
); rv = NS_TableDrivenQI(static_cast<void*>(this), aIID
, aInstancePtr, table); return rv; }
1035
1036nsresult NrUdpSocketIpcProxy::Init(const RefPtr<NrUdpSocketIpc>& socket) {
1037 nsresult rv;
1038 sts_thread_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
1039 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1040 MOZ_ASSERT(false, "Failed to get STS thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to get STS thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1040); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to get STS thread" ")"); do { *((volatile int*)__null
) = 1040; ::abort(); } while (false); } } while (false)
;
1041 return rv;
1042 }
1043
1044 socket_ = socket;
1045 return NS_OK;
1046}
1047
1048NrUdpSocketIpcProxy::~NrUdpSocketIpcProxy() {
1049 // Send our ref to STS to be released
1050 RUN_ON_THREAD(sts_thread_, mozilla::WrapRelease(socket_.forget()),
1051 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1052}
1053
1054// IUDPSocketInternal interfaces
1055// callback while error happened in UDP socket operation
1056NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerError(const nsACString& message,
1057 const nsACString& filename,
1058 uint32_t line_number) {
1059 return socket_->CallListenerError(message, filename, line_number);
1060}
1061
1062// callback while receiving UDP packet
1063NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerReceivedData(
1064 const nsACString& host, uint16_t port, const nsTArray<uint8_t>& data) {
1065 return socket_->CallListenerReceivedData(host, port, data);
1066}
1067
1068// callback while UDP socket is opened
1069NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerOpened() {
1070 return socket_->CallListenerOpened();
1071}
1072
1073// callback while UDP socket is connected
1074NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerConnected() {
1075 return socket_->CallListenerConnected();
1076}
1077
1078// callback while UDP socket is closed
1079NS_IMETHODIMPnsresult NrUdpSocketIpcProxy::CallListenerClosed() {
1080 return socket_->CallListenerClosed();
1081}
1082
1083// NrUdpSocketIpc Implementation
1084NrUdpSocketIpc::NrUdpSocketIpc()
1085 : NrSocketIpc(GetIOThreadAndAddUse_s()),
1086 monitor_("NrUdpSocketIpc"),
1087 err_(false),
1088 state_(NR_INIT) {}
1089
1090NrUdpSocketIpc::~NrUdpSocketIpc() {
1091#if defined(MOZILLA_INTERNAL_API1)
1092 // close(), but transfer the socket_child_ reference to die as well
1093 // destroy_i also dispatches back to STS to call ReleaseUse, to avoid shutting
1094 // down the IO thread before close() runs.
1095 RUN_ON_THREAD(
1096 io_thread_,
1097 mozilla::WrapRunnableNM(&NrUdpSocketIpc::destroy_i,
1098 socket_child_.forget().take(), sts_thread_),
1099 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1100#endif
1101}
1102
1103// IUDPSocketInternal interfaces
1104// callback while error happened in UDP socket operation
1105NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerError(const nsACString& message,
1106 const nsACString& filename,
1107 uint32_t line_number) {
1108 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1108); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1108; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1108); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1108; ::abort(); } while (false
); } } while (false); } } while (0)
;
1109
1110 r_log(LOG_GENERIC0, LOG_ERR3, "UDP socket error:%s at %s:%d this=%p",
1111 message.BeginReading(), filename.BeginReading(), line_number,
1112 (void*)this);
1113
1114 ReentrantMonitorAutoEnter mon(monitor_);
1115 err_ = true;
1116 monitor_.NotifyAll();
1117
1118 return NS_OK;
1119}
1120
1121// callback while receiving UDP packet
1122NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerReceivedData(
1123 const nsACString& host, uint16_t port, const nsTArray<uint8_t>& data) {
1124 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1124); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1124; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1124); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1124; ::abort(); } while (false
); } } while (false); } } while (0)
;
1125
1126 PRNetAddr addr;
1127 memset(&addr, 0, sizeof(addr));
1128
1129 {
1130 ReentrantMonitorAutoEnter mon(monitor_);
1131
1132 if (PR_SUCCESS != PR_StringToNetAddr(host.BeginReading(), &addr)) {
1133 err_ = true;
1134 MOZ_ASSERT(false, "Failed to convert remote host to PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to convert remote host to PRNetAddr" ")"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1134); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to convert remote host to PRNetAddr" ")"); do { *((volatile
int*)__null) = 1134; ::abort(); } while (false); } } while (
false)
;
1135 return NS_OK;
1136 }
1137
1138 // Use PR_IpAddrNull to avoid address being reset to 0.
1139 if (PR_SUCCESS !=
1140 PR_SetNetAddr(PR_IpAddrNull, addr.raw.family, port, &addr)) {
1141 err_ = true;
1142 MOZ_ASSERT(false, "Failed to set port in PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to set port in PRNetAddr" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1142); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to set port in PRNetAddr" ")"); do { *((volatile int
*)__null) = 1142; ::abort(); } while (false); } } while (false
)
;
1143 return NS_OK;
1144 }
1145 }
1146
1147 auto buf = MakeUnique<MediaPacket>();
1148 buf->Copy(data.Elements(), data.Length());
1149 RefPtr<nr_udp_message> msg(new nr_udp_message(addr, std::move(buf)));
1150
1151 RUN_ON_THREAD(sts_thread_,
1152 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1153 &NrUdpSocketIpc::recv_callback_s, msg),
1154 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1155 return NS_OK;
1156}
1157
1158nsresult NrUdpSocketIpc::SetAddress() {
1159 uint16_t port = socket_child_->LocalPort();
1160
1161 nsAutoCString address(socket_child_->LocalAddress());
1162
1163 PRNetAddr praddr;
1164 if (PR_SUCCESS != PR_InitializeNetAddr(PR_IpAddrAny, port, &praddr)) {
1165 err_ = true;
1166 MOZ_ASSERT(false, "Failed to set port in PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to set port in PRNetAddr" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1166); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to set port in PRNetAddr" ")"); do { *((volatile int
*)__null) = 1166; ::abort(); } while (false); } } while (false
)
;
1167 return NS_OK;
1168 }
1169
1170 if (PR_SUCCESS != PR_StringToNetAddr(address.BeginReading(), &praddr)) {
1171 err_ = true;
1172 MOZ_ASSERT(false, "Failed to convert local host to PRNetAddr")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to convert local host to PRNetAddr" ")"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1172); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to convert local host to PRNetAddr" ")"); do { *((volatile
int*)__null) = 1172; ::abort(); } while (false); } } while (
false)
;
1173 return NS_OK;
1174 }
1175
1176 nr_transport_addr expected_addr;
1177 if (nr_transport_addr_copy(&expected_addr, &my_addr_)) {
1178 err_ = true;
1179 MOZ_ASSERT(false, "Failed to copy my_addr_")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to copy my_addr_" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1179); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to copy my_addr_" ")"); do { *((volatile int*)__null
) = 1179; ::abort(); } while (false); } } while (false)
;
1180 }
1181
1182 if (nr_praddr_to_transport_addr(&praddr, &my_addr_, IPPROTO_UDPIPPROTO_UDP, 1)) {
1183 err_ = true;
1184 MOZ_ASSERT(false, "Failed to copy local host to my_addr_")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to copy local host to my_addr_" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1184); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to copy local host to my_addr_" ")"); do { *((volatile
int*)__null) = 1184; ::abort(); } while (false); } } while (
false)
;
1185 }
1186
1187 if (!nr_transport_addr_is_wildcard(&expected_addr) &&
1188 nr_transport_addr_cmp(&expected_addr, &my_addr_,
1189 NR_TRANSPORT_ADDR_CMP_MODE_ADDR3)) {
1190 err_ = true;
1191 MOZ_ASSERT(false, "Address of opened socket is not expected")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Address of opened socket is not expected" ")",
"/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1191); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Address of opened socket is not expected" ")"); do { *((volatile
int*)__null) = 1191; ::abort(); } while (false); } } while (
false)
;
1192 }
1193
1194 return NS_OK;
1195}
1196
1197// callback while UDP socket is opened
1198NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerOpened() {
1199 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1199); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1199; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1199); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1199; ::abort(); } while (false
); } } while (false); } } while (0)
;
1200 ReentrantMonitorAutoEnter mon(monitor_);
1201
1202 r_log(LOG_GENERIC0, LOG_DEBUG7, "UDP socket opened this=%p", (void*)this);
1203 nsresult rv = SetAddress();
1204 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1205 return rv;
1206 }
1207
1208 mon.NotifyAll();
1209
1210 return NS_OK;
1211}
1212
1213// callback while UDP socket is connected
1214NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerConnected() {
1215 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1215); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1215; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1215); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1215; ::abort(); } while (false
); } } while (false); } } while (0)
;
1216
1217 ReentrantMonitorAutoEnter mon(monitor_);
1218
1219 r_log(LOG_GENERIC0, LOG_DEBUG7, "UDP socket connected this=%p", (void*)this);
1220 MOZ_ASSERT(state_ == NR_CONNECTED)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(state_ == NR_CONNECTED)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(state_ == NR_CONNECTED))), 0
))) { MOZ_ReportAssertionFailure("state_ == NR_CONNECTED", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1220); AnnotateMozCrashReason("MOZ_ASSERT" "(" "state_ == NR_CONNECTED"
")"); do { *((volatile int*)__null) = 1220; ::abort(); } while
(false); } } while (false)
;
1221
1222 nsresult rv = SetAddress();
1223 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1224 mon.NotifyAll();
1225 return rv;
1226 }
1227
1228 r_log(LOG_GENERIC0, LOG_INFO6, "Exit UDP socket connected");
1229 mon.NotifyAll();
1230
1231 return NS_OK;
1232}
1233
1234// callback while UDP socket is closed
1235NS_IMETHODIMPnsresult NrUdpSocketIpc::CallListenerClosed() {
1236 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1236); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1236; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1236); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1236; ::abort(); } while (false
); } } while (false); } } while (0)
;
1237
1238 ReentrantMonitorAutoEnter mon(monitor_);
1239
1240 r_log(LOG_GENERIC0, LOG_DEBUG7, "UDP socket closed this=%p", (void*)this);
1241 MOZ_ASSERT(state_ == NR_CONNECTED || state_ == NR_CLOSING)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(state_ == NR_CONNECTED || state_ == NR_CLOSING)>::
isValid, "invalid assertion condition"); if ((__builtin_expect
(!!(!(!!(state_ == NR_CONNECTED || state_ == NR_CLOSING))), 0
))) { MOZ_ReportAssertionFailure("state_ == NR_CONNECTED || state_ == NR_CLOSING"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1241); AnnotateMozCrashReason("MOZ_ASSERT" "(" "state_ == NR_CONNECTED || state_ == NR_CLOSING"
")"); do { *((volatile int*)__null) = 1241; ::abort(); } while
(false); } } while (false)
;
1242 state_ = NR_CLOSED;
1243
1244 return NS_OK;
1245}
1246
1247//
1248// NrSocketBase methods.
1249//
1250int NrUdpSocketIpc::create(nr_transport_addr* addr) {
1251 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); do { static_assert( mozilla::
detail::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1251); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1251; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1251); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1251; ::abort(); } while (false
); } } while (false); } } while (0)
;
1252
1253 int r, _status;
1254 nsresult rv;
1255 int32_t port;
1256 nsCString host;
1257
1258 ReentrantMonitorAutoEnter mon(monitor_);
1259
1260 if (state_ != NR_INIT) {
1261 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1262 }
1263
1264 sts_thread_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID"@mozilla.org/network/socket-transport-service;1", &rv);
1265 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1266 MOZ_ASSERT(false, "Failed to get STS thread")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to get STS thread" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1266); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to get STS thread" ")"); do { *((volatile int*)__null
) = 1266; ::abort(); } while (false); } } while (false)
;
1267 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1268 }
1269
1270 if ((r = nr_transport_addr_get_addrstring_and_port(addr, &host, &port))) {
1271 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1272 }
1273
1274 // wildcard address will be resolved at NrUdpSocketIpc::CallListenerVoid
1275 if ((r = nr_transport_addr_copy(&my_addr_, addr))) {
1276 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1277 }
1278
1279 state_ = NR_CONNECTING;
1280
1281 MOZ_ASSERT(io_thread_)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(io_thread_)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(io_thread_))), 0))) { MOZ_ReportAssertionFailure
("io_thread_", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1281); AnnotateMozCrashReason("MOZ_ASSERT" "(" "io_thread_"
")"); do { *((volatile int*)__null) = 1281; ::abort(); } while
(false); } } while (false)
;
1282 RUN_ON_THREAD(io_thread_,
1283 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1284 &NrUdpSocketIpc::create_i, host,
1285 static_cast<uint16_t>(port)),
1286 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1287
1288 // Wait until socket creation complete.
1289 mon.Wait();
1290
1291 if (err_) {
1292 close();
1293 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1294 }
1295
1296 state_ = NR_CONNECTED;
1297
1298 _status = 0;
1299abort:
1300 return (_status);
1301}
1302
1303int NrUdpSocketIpc::sendto(const void* msg, size_t len, int flags,
1304 const nr_transport_addr* to) {
1305 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); do { static_assert( mozilla::
detail::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1305); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1305; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1305); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1305; ::abort(); } while (false
); } } while (false); } } while (0)
;
1306
1307 ReentrantMonitorAutoEnter mon(monitor_);
1308
1309 // If send err happened before, simply return the error.
1310 if (err_) {
1311 return R_IO_ERROR13;
1312 }
1313
1314 if (state_ != NR_CONNECTED) {
1315 return R_INTERNAL3;
1316 }
1317
1318 int r;
1319 net::NetAddr addr;
1320 if ((r = nr_transport_addr_to_netaddr(to, &addr))) {
1321 return r;
1322 }
1323
1324 if (nr_is_stun_request_message((UCHAR*)msg, len) && ShouldDrop(len)) {
1325 return R_WOULDBLOCK8;
1326 }
1327
1328 UniquePtr<MediaPacket> buf(new MediaPacket);
1329 buf->Copy(static_cast<const uint8_t*>(msg), len);
1330
1331 RUN_ON_THREAD(
1332 io_thread_,
1333 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1334 &NrUdpSocketIpc::sendto_i, addr, std::move(buf)),
1335 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1336 return 0;
1337}
1338
1339void NrUdpSocketIpc::close() {
1340 r_log(LOG_GENERIC0, LOG_DEBUG7, "NrUdpSocketIpc::close()");
1341
1342 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); do { static_assert( mozilla::
detail::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1342); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1342; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1342); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1342; ::abort(); } while (false
); } } while (false); } } while (0)
;
1343
1344 ReentrantMonitorAutoEnter mon(monitor_);
1345 state_ = NR_CLOSING;
1346
1347 RUN_ON_THREAD(io_thread_,
1348 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1349 &NrUdpSocketIpc::close_i),
1350 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1351
1352 // remove all enqueued messages
1353 std::queue<RefPtr<nr_udp_message>> empty;
1354 std::swap(received_msgs_, empty);
1355}
1356
1357int NrUdpSocketIpc::recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
1358 nr_transport_addr* from) {
1359 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); do { static_assert( mozilla::
detail::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1359); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1359; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1359); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1359; ::abort(); } while (false
); } } while (false); } } while (0)
;
1360
1361 ReentrantMonitorAutoEnter mon(monitor_);
1362
1363 int r, _status;
1364 uint32_t consumed_len;
1365
1366 *len = 0;
1367
1368 if (state_ != NR_CONNECTED) {
1369 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1370 }
1371
1372 if (received_msgs_.empty()) {
1373 ABORT(R_WOULDBLOCK)do { int _r=8; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1374 }
1375
1376 {
1377 RefPtr<nr_udp_message> msg(received_msgs_.front());
1378
1379 received_msgs_.pop();
1380
1381 if ((r = nr_praddr_to_transport_addr(&msg->from, from, IPPROTO_UDPIPPROTO_UDP, 0))) {
Although the value stored to 'r' is used in the enclosing expression, the value is never actually read from 'r'
1382 err_ = true;
1383 MOZ_ASSERT(false, "Get bogus address for received UDP packet")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Get bogus address for received UDP packet" ")"
, "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1383); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Get bogus address for received UDP packet" ")"); do { *((volatile
int*)__null) = 1383; ::abort(); } while (false); } } while (
false)
;
1384 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1385 }
1386
1387 consumed_len = std::min(maxlen, msg->data->len());
1388 if (consumed_len < msg->data->len()) {
1389 r_log(LOG_GENERIC0, LOG_DEBUG7,
1390 "Partial received UDP packet will be discard");
1391 }
1392
1393 memcpy(buf, msg->data->data(), consumed_len);
1394 *len = consumed_len;
1395 }
1396
1397 _status = 0;
1398abort:
1399 return (_status);
1400}
1401
1402int NrUdpSocketIpc::getaddr(nr_transport_addr* addrp) {
1403 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); do { static_assert( mozilla::
detail::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1403); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1403; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1403); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1403; ::abort(); } while (false
); } } while (false); } } while (0)
;
1404
1405 ReentrantMonitorAutoEnter mon(monitor_);
1406
1407 return nr_transport_addr_copy(addrp, &my_addr_);
1408}
1409
1410int NrUdpSocketIpc::connect(const nr_transport_addr* addr) {
1411 int r, _status;
1412 int32_t port;
1413 nsCString host;
1414
1415 ReentrantMonitorAutoEnter mon(monitor_);
1416 r_log(LOG_GENERIC0, LOG_DEBUG7, "NrUdpSocketIpc::connect(%s) this=%p",
1417 addr->as_string, (void*)this);
1418
1419 if ((r = nr_transport_addr_get_addrstring_and_port(addr, &host, &port))) {
1420 ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1421 }
1422
1423 RUN_ON_THREAD(io_thread_,
1424 mozilla::WrapRunnable(RefPtr<NrUdpSocketIpc>(this),
1425 &NrUdpSocketIpc::connect_i, host,
1426 static_cast<uint16_t>(port)),
1427 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1428
1429 // Wait until connect() completes.
1430 mon.Wait();
1431
1432 r_log(LOG_GENERIC0, LOG_DEBUG7,
1433 "NrUdpSocketIpc::connect this=%p completed err_ = %s", (void*)this,
1434 err_ ? "true" : "false");
1435
1436 if (err_) {
1437 ABORT(R_INTERNAL)do { int _r=3; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1438 }
1439
1440 _status = 0;
1441abort:
1442 return _status;
1443}
1444
1445int NrUdpSocketIpc::write(const void* msg, size_t len, size_t* written) {
1446 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1446); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1446; ::abort(); } while (false
); } } while (false)
;
1447 return R_INTERNAL3;
1448}
1449
1450int NrUdpSocketIpc::read(void* buf, size_t maxlen, size_t* len) {
1451 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1451); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1451; ::abort(); } while (false
); } } while (false)
;
1452 return R_INTERNAL3;
1453}
1454
1455int NrUdpSocketIpc::listen(int backlog) {
1456 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1456); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1456; ::abort(); } while (false
); } } while (false)
;
1457 return R_INTERNAL3;
1458}
1459
1460int NrUdpSocketIpc::accept(nr_transport_addr* addrp, nr_socket** sockp) {
1461 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1461); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1461; ::abort(); } while (false
); } } while (false)
;
1462 return R_INTERNAL3;
1463}
1464
1465// IO thread executors
1466void NrUdpSocketIpc::create_i(const nsACString& host, const uint16_t port) {
1467 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1467); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1467; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1467); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1467; ::abort(); } while (false
); } } while (false); } } while (0)
;
1468
1469 uint32_t minBuffSize = 0;
1470 RefPtr<dom::UDPSocketChild> socketChild = new dom::UDPSocketChild();
1471
1472 // This can spin the event loop; don't do that with the monitor held
1473 socketChild->SetBackgroundSpinsEvents();
1474
1475 ReentrantMonitorAutoEnter mon(monitor_);
1476 if (!socket_child_) {
1477 socket_child_ = socketChild;
1478 socket_child_->SetFilterName(
1479 nsCString(NS_NETWORK_SOCKET_FILTER_HANDLER_STUN_SUFFIX"stun"));
1480 } else {
1481 socketChild = nullptr;
1482 }
1483
1484 RefPtr<NrUdpSocketIpcProxy> proxy(new NrUdpSocketIpcProxy);
1485 nsresult rv = proxy->Init(this);
1486 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1487 err_ = true;
1488 mon.NotifyAll();
1489 return;
1490 }
1491
1492#ifdef XP_WIN
1493 if (!mozilla::IsWin8OrLater()) {
1494 // Increase default receive and send buffer size on <= Win7 to be able to
1495 // receive and send an unpaced HD (>= 720p = 1280x720 - I Frame ~ 21K size)
1496 // stream without losing packets.
1497 // Manual testing showed that 100K buffer size was not enough and the
1498 // packet loss dis-appeared with 256K buffer size.
1499 // See bug 1252769 for future improvements of this.
1500 minBuffSize = 256 * 1024;
1501 }
1502#endif
1503 // XXX bug 1126232 - don't use null Principal!
1504 if (NS_FAILED(socket_child_->Bind(proxy, nullptr, host, port,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
, nullptr))), 0)))
1505 /* addressReuse = */ false,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
, nullptr))), 0)))
1506 /* loopback = */ false,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
, nullptr))), 0)))
1507 /* recv buffer size */ minBuffSize,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
, nullptr))), 0)))
1508 /* send buffer size */ minBuffSize,((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
, nullptr))), 0)))
1509 /* mainThreadEventTarget */ nullptr))((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
Bind(proxy, nullptr, host, port, false, false, minBuffSize, minBuffSize
, nullptr))), 0)))
) {
1510 err_ = true;
1511 MOZ_ASSERT(false, "Failed to create UDP socket")do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false" " (" "Failed to create UDP socket" ")", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1511); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ") ("
"Failed to create UDP socket" ")"); do { *((volatile int*)__null
) = 1511; ::abort(); } while (false); } } while (false)
;
1512 mon.NotifyAll();
1513 return;
1514 }
1515}
1516
1517void NrUdpSocketIpc::connect_i(const nsACString& host, const uint16_t port) {
1518 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1518); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1518; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1518); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1518; ::abort(); } while (false
); } } while (false); } } while (0)
;
1519 nsresult rv;
1520 ReentrantMonitorAutoEnter mon(monitor_);
1521
1522 RefPtr<NrUdpSocketIpcProxy> proxy(new NrUdpSocketIpcProxy);
1523 rv = proxy->Init(this);
1524 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1525 err_ = true;
1526 mon.NotifyAll();
1527 return;
1528 }
1529
1530 socket_child_->Connect(proxy, host, port);
1531}
1532
1533void NrUdpSocketIpc::sendto_i(const net::NetAddr& addr,
1534 UniquePtr<MediaPacket> buf) {
1535 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1535); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1535; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1535); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1535; ::abort(); } while (false
); } } while (false); } } while (0)
;
1536
1537 ReentrantMonitorAutoEnter mon(monitor_);
1538
1539 if (!socket_child_) {
1540 MOZ_ASSERT(false)do { static_assert( mozilla::detail::AssertionConditionType<
decltype(false)>::isValid, "invalid assertion condition");
if ((__builtin_expect(!!(!(!!(false))), 0))) { MOZ_ReportAssertionFailure
("false", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1540); AnnotateMozCrashReason("MOZ_ASSERT" "(" "false" ")")
; do { *((volatile int*)__null) = 1540; ::abort(); } while (false
); } } while (false)
;
1541 err_ = true;
1542 return;
1543 }
1544 if (NS_FAILED(((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
SendWithAddress(&addr, buf->data(), buf->len()))), 0
)))
1545 socket_child_->SendWithAddress(&addr, buf->data(), buf->len()))((bool)(__builtin_expect(!!(NS_FAILED_impl(socket_child_->
SendWithAddress(&addr, buf->data(), buf->len()))), 0
)))
) {
1546 err_ = true;
1547 }
1548}
1549
1550void NrUdpSocketIpc::close_i() {
1551 ASSERT_ON_THREAD(io_thread_)do { if (io_thread_) { bool on; nsresult rv; rv = io_thread_->
IsOnCurrentThread(&on); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1551); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1551; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1551); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1551; ::abort(); } while (false
); } } while (false); } } while (0)
;
1552
1553 if (socket_child_) {
1554 socket_child_->Close();
1555 socket_child_ = nullptr;
1556 }
1557}
1558
1559#if defined(MOZILLA_INTERNAL_API1)
1560
1561static void ReleaseIOThread_s() { sThread->ReleaseUse(); }
1562
1563// close(), but transfer the socket_child_ reference to die as well
1564// static
1565void NrUdpSocketIpc::destroy_i(dom::UDPSocketChild* aChild,
1566 const nsCOMPtr<nsIEventTarget>& aStsThread) {
1567 RefPtr<dom::UDPSocketChild> socket_child_ref =
1568 already_AddRefed<dom::UDPSocketChild>(aChild);
1569 if (socket_child_ref) {
1570 socket_child_ref->Close();
1571 }
1572
1573 RUN_ON_THREAD(aStsThread, WrapRunnableNM(&ReleaseIOThread_s),
1574 NS_DISPATCH_NORMALnsIEventTarget::DISPATCH_NORMAL);
1575}
1576#endif
1577
1578void NrUdpSocketIpc::recv_callback_s(RefPtr<nr_udp_message> msg) {
1579 ASSERT_ON_THREAD(sts_thread_)do { if (sts_thread_) { bool on; nsresult rv; rv = sts_thread_
->IsOnCurrentThread(&on); do { static_assert( mozilla::
detail::AssertionConditionType<decltype(((bool)(__builtin_expect
(!!(!NS_FAILED_impl(rv)), 1))))>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(((bool)(__builtin_expect(!!(
!NS_FAILED_impl(rv)), 1)))))), 0))) { MOZ_ReportAssertionFailure
("((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1579); AnnotateMozCrashReason("MOZ_ASSERT" "(" "((bool)(__builtin_expect(!!(!NS_FAILED_impl(rv)), 1)))"
")"); do { *((volatile int*)__null) = 1579; ::abort(); } while
(false); } } while (false); do { static_assert( mozilla::detail
::AssertionConditionType<decltype(on)>::isValid, "invalid assertion condition"
); if ((__builtin_expect(!!(!(!!(on))), 0))) { MOZ_ReportAssertionFailure
("on", "/var/lib/jenkins/workspace/firefox-scan-build/dom/media/webrtc/transport/nr_socket_prsock.cpp"
, 1579); AnnotateMozCrashReason("MOZ_ASSERT" "(" "on" ")"); do
{ *((volatile int*)__null) = 1579; ::abort(); } while (false
); } } while (false); } } while (0)
;
1580
1581 {
1582 ReentrantMonitorAutoEnter mon(monitor_);
1583 if (state_ != NR_CONNECTED) {
1584 return;
1585 }
1586 }
1587
1588 // enqueue received message
1589 received_msgs_.push(msg);
1590
1591 if ((poll_flags() & PR_POLL_READ0x1)) {
1592 fire_callback(NR_ASYNC_WAIT_READ0);
1593 }
1594}
1595
1596} // namespace mozilla
1597
1598using namespace mozilla;
1599
1600// Bridge to the nr_socket interface
1601static int nr_socket_local_destroy(void** objp);
1602static int nr_socket_local_sendto(void* obj, const void* msg, size_t len,
1603 int flags, const nr_transport_addr* to);
1604static int nr_socket_local_recvfrom(void* obj, void* restrict buf,
1605 size_t maxlen, size_t* len, int flags,
1606 nr_transport_addr* from);
1607static int nr_socket_local_getfd(void* obj, NR_SOCKET* fd);
1608static int nr_socket_local_getaddr(void* obj, nr_transport_addr* addrp);
1609static int nr_socket_local_close(void* obj);
1610static int nr_socket_local_connect(void* obj, const nr_transport_addr* addr);
1611static int nr_socket_local_write(void* obj, const void* msg, size_t len,
1612 size_t* written);
1613static int nr_socket_local_read(void* obj, void* restrict buf, size_t maxlen,
1614 size_t* len);
1615static int nr_socket_local_listen(void* obj, int backlog);
1616static int nr_socket_local_accept(void* obj, nr_transport_addr* addrp,
1617 nr_socket** sockp);
1618
1619static nr_socket_vtbl nr_socket_local_vtbl = {2,
1620 nr_socket_local_destroy,
1621 nr_socket_local_sendto,
1622 nr_socket_local_recvfrom,
1623 nr_socket_local_getfd,
1624 nr_socket_local_getaddr,
1625 nr_socket_local_connect,
1626 nr_socket_local_write,
1627 nr_socket_local_read,
1628 nr_socket_local_close,
1629 nr_socket_local_listen,
1630 nr_socket_local_accept};
1631
1632/* static */
1633int NrSocketBase::CreateSocket(
1634 nr_transport_addr* addr, RefPtr<NrSocketBase>* sock,
1635 const std::shared_ptr<NrSocketProxyConfig>& config) {
1636 int r, _status;
1637
1638 if (IsForbiddenAddress(addr)) {
1639 ABORT(R_REJECTED)do { int _r=11; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1640 }
1641
1642 if (config && config->GetForceProxy() && addr->protocol == IPPROTO_UDPIPPROTO_UDP) {
1643 ABORT(R_REJECTED)do { int _r=11; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1644 }
1645
1646 // create IPC bridge for content process
1647 if (XRE_IsParentProcess()) {
1648 // TODO: Make NrTcpSocket work on the parent process
1649 *sock = new NrSocket();
1650 } else if (XRE_IsSocketProcess()) {
1651 if (addr->protocol == IPPROTO_TCPIPPROTO_TCP) {
1652 *sock = new NrTcpSocket(config);
1653 } else {
1654 *sock = new NrSocket();
1655 }
1656 } else {
1657 if (addr->protocol == IPPROTO_TCPIPPROTO_TCP) {
1658 *sock = new NrTcpSocket(config);
1659 } else {
1660 *sock = new NrUdpSocketIpc();
1661 }
1662 }
1663
1664 r = (*sock)->create(addr);
1665 if (r) ABORT(r)do { int _r=r; if(!_r) _r=-1; ; _status=_r; goto abort;} while
(0)
;
1666
1667 _status = 0;
1668abort:
1669 if (_status) {
1670 *sock = nullptr;
1671 }
1672 return _status;
1673}
1674
1675// static
1676bool NrSocketBase::IsForbiddenAddress(nr_transport_addr* addr) {
1677 int r, port;
1678
1679 r = nr_transport_addr_get_port(addr, &port);
1680 if (r) {
1681 return true;
1682 }
1683
1684 // allow auto assigned ports
1685 if (port != 0) {
1686 // Don't need to check an override scheme
1687 nsresult rv = NS_CheckPortSafety(port, nullptr);
1688 if (NS_FAILED(rv)((bool)(__builtin_expect(!!(NS_FAILED_impl(rv)), 0)))) {
1689 return true;
1690 }
1691 }
1692
1693 return false;
1694}
1695
1696static int nr_socket_local_destroy(void** objp) {
1697 if (!objp || !*objp) return 0;
1698
1699 NrSocketBase* sock = static_cast<NrSocketBase*>(*objp);
1700 *objp = nullptr;
1701
1702 sock->close(); // Signal STS that we want not to listen
1703 sock->Release(); // Decrement the ref count
1704
1705 return 0;
1706}
1707
1708static int nr_socket_local_sendto(void* obj, const void* msg, size_t len,
1709 int flags, const nr_transport_addr* addr) {
1710 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1711
1712 return sock->sendto(msg, len, flags, addr);
1713}
1714
1715static int nr_socket_local_recvfrom(void* obj, void* restrict buf,
1716 size_t maxlen, size_t* len, int flags,
1717 nr_transport_addr* addr) {
1718 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1719
1720 return sock->recvfrom(buf, maxlen, len, flags, addr);
1721}
1722
1723static int nr_socket_local_getfd(void* obj, NR_SOCKET* fd) {
1724 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1725
1726 *fd = sock;
1727
1728 return 0;
1729}
1730
1731static int nr_socket_local_getaddr(void* obj, nr_transport_addr* addrp) {
1732 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1733
1734 return sock->getaddr(addrp);
1735}
1736
1737static int nr_socket_local_close(void* obj) {
1738 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1739
1740 sock->close();
1741
1742 return 0;
1743}
1744
1745static int nr_socket_local_write(void* obj, const void* msg, size_t len,
1746 size_t* written) {
1747 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1748
1749 return sock->write(msg, len, written);
1750}
1751
1752static int nr_socket_local_read(void* obj, void* restrict buf, size_t maxlen,
1753 size_t* len) {
1754 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1755
1756 return sock->read(buf, maxlen, len);
1757}
1758
1759static int nr_socket_local_connect(void* obj, const nr_transport_addr* addr) {
1760 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1761
1762 return sock->connect(addr);
1763}
1764
1765static int nr_socket_local_listen(void* obj, int backlog) {
1766 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1767
1768 return sock->listen(backlog);
1769}
1770
1771static int nr_socket_local_accept(void* obj, nr_transport_addr* addrp,
1772 nr_socket** sockp) {
1773 NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
1774
1775 return sock->accept(addrp, sockp);
1776}
1777
1778// Implement async api
1779int NR_async_wait(NR_SOCKET sock, int how, NR_async_cb cb, void* cb_arg,
1780 char* function, int line) {
1781 NrSocketBase* s = static_cast<NrSocketBase*>(sock);
1782
1783 return s->async_wait(how, cb, cb_arg, function, line);
1784}
1785
1786int NR_async_cancel(NR_SOCKET sock, int how) {
1787 NrSocketBase* s = static_cast<NrSocketBase*>(sock);
1788
1789 return s->cancel(how);
1790}
1791
1792nr_socket_vtbl* NrSocketBase::vtbl() { return &nr_socket_local_vtbl; }