TCPServerSocketChild.cpp (2479B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=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 7 #include "TCPServerSocketChild.h" 8 9 #include "TCPServerSocket.h" 10 #include "TCPSocketChild.h" 11 #include "jsfriendapi.h" 12 #include "mozilla/dom/BrowserChild.h" 13 #include "mozilla/dom/PBrowserChild.h" 14 #include "mozilla/net/NeckoChild.h" 15 #include "nsJSUtils.h" 16 17 using mozilla::net::gNeckoChild; 18 19 namespace mozilla::dom { 20 21 NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket) 22 NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase) 23 NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase) 24 25 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketChildBase) 26 NS_INTERFACE_MAP_ENTRY(nsISupports) 27 NS_INTERFACE_MAP_END 28 29 TCPServerSocketChildBase::TCPServerSocketChildBase() : mIPCOpen(false) {} 30 31 TCPServerSocketChildBase::~TCPServerSocketChildBase() = default; 32 33 NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void) { 34 nsrefcnt refcnt = TCPServerSocketChildBase::Release(); 35 if (refcnt == 1 && mIPCOpen) { 36 PTCPServerSocketChild::SendRequestDelete(); 37 return 1; 38 } 39 return refcnt; 40 } 41 42 TCPServerSocketChild::TCPServerSocketChild(TCPServerSocket* aServerSocket, 43 uint16_t aLocalPort, 44 uint16_t aBacklog, 45 bool aUseArrayBuffers) { 46 mServerSocket = aServerSocket; 47 AddIPDLReference(); 48 gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, 49 aUseArrayBuffers); 50 } 51 52 void TCPServerSocketChildBase::ReleaseIPDLReference() { 53 MOZ_ASSERT(mIPCOpen); 54 mIPCOpen = false; 55 this->Release(); 56 } 57 58 void TCPServerSocketChildBase::AddIPDLReference() { 59 MOZ_ASSERT(!mIPCOpen); 60 mIPCOpen = true; 61 this->AddRef(); 62 } 63 64 TCPServerSocketChild::~TCPServerSocketChild() = default; 65 66 mozilla::ipc::IPCResult TCPServerSocketChild::RecvCallbackAccept( 67 PTCPSocketChild* psocket) { 68 RefPtr<TCPSocketChild> socket = static_cast<TCPSocketChild*>(psocket); 69 nsresult rv = mServerSocket->AcceptChildSocket(socket); 70 NS_ENSURE_SUCCESS(rv, IPC_OK()); 71 return IPC_OK(); 72 } 73 74 void TCPServerSocketChild::Close() { SendClose(); } 75 76 } // namespace mozilla::dom