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 #include "TCPSocketChild.h"
9 #include "TCPServerSocket.h"
10 #include "mozilla/net/NeckoChild.h"
11 #include "mozilla/dom/PBrowserChild.h"
12 #include "mozilla/dom/TabChild.h"
13 #include "nsJSUtils.h"
14 #include "jsfriendapi.h"
15
16 using mozilla::net::gNeckoChild;
17
18 namespace mozilla {
19 namespace dom {
20
NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase,mServerSocket)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()
30 : mIPCOpen(false)
31 {
32 }
33
~TCPServerSocketChildBase()34 TCPServerSocketChildBase::~TCPServerSocketChildBase()
35 {
36 }
37
NS_IMETHODIMP_(MozExternalRefCountType)38 NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void)
39 {
40 nsrefcnt refcnt = TCPServerSocketChildBase::Release();
41 if (refcnt == 1 && mIPCOpen) {
42 PTCPServerSocketChild::SendRequestDelete();
43 return 1;
44 }
45 return refcnt;
46 }
47
TCPServerSocketChild(TCPServerSocket * aServerSocket,uint16_t aLocalPort,uint16_t aBacklog,bool aUseArrayBuffers)48 TCPServerSocketChild::TCPServerSocketChild(TCPServerSocket* aServerSocket, uint16_t aLocalPort,
49 uint16_t aBacklog, bool aUseArrayBuffers)
50 {
51 mServerSocket = aServerSocket;
52 AddIPDLReference();
53 gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, aUseArrayBuffers);
54 }
55
56 void
ReleaseIPDLReference()57 TCPServerSocketChildBase::ReleaseIPDLReference()
58 {
59 MOZ_ASSERT(mIPCOpen);
60 mIPCOpen = false;
61 this->Release();
62 }
63
64 void
AddIPDLReference()65 TCPServerSocketChildBase::AddIPDLReference()
66 {
67 MOZ_ASSERT(!mIPCOpen);
68 mIPCOpen = true;
69 this->AddRef();
70 }
71
~TCPServerSocketChild()72 TCPServerSocketChild::~TCPServerSocketChild()
73 {
74 }
75
76 bool
RecvCallbackAccept(PTCPSocketChild * psocket)77 TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket)
78 {
79 RefPtr<TCPSocketChild> socket = static_cast<TCPSocketChild*>(psocket);
80 nsresult rv = mServerSocket->AcceptChildSocket(socket);
81 NS_ENSURE_SUCCESS(rv, true);
82 return true;
83 }
84
85 void
Close()86 TCPServerSocketChild::Close()
87 {
88 SendClose();
89 }
90
91 } // namespace dom
92 } // namespace mozilla
93