1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/network/src/TCPServerSocketParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "TCPServerSocketParent.h" 1.9 +#include "nsJSUtils.h" 1.10 +#include "TCPSocketParent.h" 1.11 +#include "mozilla/unused.h" 1.12 +#include "mozilla/AppProcessChecker.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace dom { 1.16 + 1.17 +static void 1.18 +FireInteralError(mozilla::net::PTCPServerSocketParent* aActor, 1.19 + uint32_t aLineNo) 1.20 +{ 1.21 + mozilla::unused << 1.22 + aActor->SendCallbackError(NS_LITERAL_STRING("Internal error"), 1.23 + NS_LITERAL_STRING(__FILE__), aLineNo, 0); 1.24 +} 1.25 + 1.26 +NS_IMPL_CYCLE_COLLECTION(TCPServerSocketParent, mServerSocket, mIntermediary) 1.27 +NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketParent) 1.28 +NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketParent) 1.29 + 1.30 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketParent) 1.31 + NS_INTERFACE_MAP_ENTRY(nsITCPServerSocketParent) 1.32 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.33 +NS_INTERFACE_MAP_END 1.34 + 1.35 +void 1.36 +TCPServerSocketParent::ReleaseIPDLReference() 1.37 +{ 1.38 + MOZ_ASSERT(mIPCOpen); 1.39 + mIPCOpen = false; 1.40 + this->Release(); 1.41 +} 1.42 + 1.43 +void 1.44 +TCPServerSocketParent::AddIPDLReference() 1.45 +{ 1.46 + MOZ_ASSERT(!mIPCOpen); 1.47 + mIPCOpen = true; 1.48 + this->AddRef(); 1.49 +} 1.50 + 1.51 +bool 1.52 +TCPServerSocketParent::Init(PNeckoParent* neckoParent, const uint16_t& aLocalPort, 1.53 + const uint16_t& aBacklog, const nsString& aBinaryType) 1.54 +{ 1.55 + mNeckoParent = neckoParent; 1.56 + 1.57 + nsresult rv; 1.58 + mIntermediary = do_CreateInstance("@mozilla.org/tcp-socket-intermediary;1", &rv); 1.59 + if (NS_FAILED(rv)) { 1.60 + FireInteralError(this, __LINE__); 1.61 + return true; 1.62 + } 1.63 + 1.64 + rv = mIntermediary->Listen(this, aLocalPort, aBacklog, aBinaryType, getter_AddRefs(mServerSocket)); 1.65 + if (NS_FAILED(rv) || !mServerSocket) { 1.66 + FireInteralError(this, __LINE__); 1.67 + return true; 1.68 + } 1.69 + return true; 1.70 +} 1.71 + 1.72 +NS_IMETHODIMP 1.73 +TCPServerSocketParent::SendCallbackAccept(nsITCPSocketParent *socket) 1.74 +{ 1.75 + TCPSocketParent* _socket = static_cast<TCPSocketParent*>(socket); 1.76 + PTCPSocketParent* _psocket = static_cast<PTCPSocketParent*>(_socket); 1.77 + 1.78 + _socket->AddIPDLReference(); 1.79 + 1.80 + if (mNeckoParent) { 1.81 + if (mNeckoParent->SendPTCPSocketConstructor(_psocket)) { 1.82 + mozilla::unused << PTCPServerSocketParent::SendCallbackAccept(_psocket); 1.83 + } 1.84 + else { 1.85 + NS_ERROR("Sending data from PTCPSocketParent was failed."); 1.86 + }; 1.87 + } 1.88 + else { 1.89 + NS_ERROR("The member value for NeckoParent is wrong."); 1.90 + } 1.91 + return NS_OK; 1.92 +} 1.93 + 1.94 +NS_IMETHODIMP 1.95 +TCPServerSocketParent::SendCallbackError(const nsAString& message, 1.96 + const nsAString& filename, 1.97 + uint32_t lineNumber, 1.98 + uint32_t columnNumber) 1.99 +{ 1.100 + mozilla::unused << 1.101 + PTCPServerSocketParent::SendCallbackError(nsString(message), nsString(filename), 1.102 + lineNumber, columnNumber); 1.103 + return NS_OK; 1.104 +} 1.105 + 1.106 +bool 1.107 +TCPServerSocketParent::RecvClose() 1.108 +{ 1.109 + NS_ENSURE_TRUE(mServerSocket, true); 1.110 + mServerSocket->Close(); 1.111 + return true; 1.112 +} 1.113 + 1.114 +void 1.115 +TCPServerSocketParent::ActorDestroy(ActorDestroyReason why) 1.116 +{ 1.117 + if (mServerSocket) { 1.118 + mServerSocket->Close(); 1.119 + mServerSocket = nullptr; 1.120 + } 1.121 + mNeckoParent = nullptr; 1.122 + mIntermediary = nullptr; 1.123 +} 1.124 + 1.125 +bool 1.126 +TCPServerSocketParent::RecvRequestDelete() 1.127 +{ 1.128 + mozilla::unused << Send__delete__(this); 1.129 + return true; 1.130 +} 1.131 + 1.132 +} // namespace dom 1.133 +} // namespace mozilla