TCPServerSocketChild.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "TCPServerSocketChild.h"
  6. #include "TCPSocketChild.h"
  7. #include "TCPServerSocket.h"
  8. #include "mozilla/net/NeckoChild.h"
  9. #include "mozilla/dom/PBrowserChild.h"
  10. #include "mozilla/dom/TabChild.h"
  11. #include "nsJSUtils.h"
  12. #include "jsfriendapi.h"
  13. using mozilla::net::gNeckoChild;
  14. namespace mozilla {
  15. namespace dom {
  16. NS_IMPL_CYCLE_COLLECTION(TCPServerSocketChildBase, mServerSocket)
  17. NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketChildBase)
  18. NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketChildBase)
  19. NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketChildBase)
  20. NS_INTERFACE_MAP_ENTRY(nsISupports)
  21. NS_INTERFACE_MAP_END
  22. TCPServerSocketChildBase::TCPServerSocketChildBase()
  23. : mIPCOpen(false)
  24. {
  25. }
  26. TCPServerSocketChildBase::~TCPServerSocketChildBase()
  27. {
  28. }
  29. NS_IMETHODIMP_(MozExternalRefCountType) TCPServerSocketChild::Release(void)
  30. {
  31. nsrefcnt refcnt = TCPServerSocketChildBase::Release();
  32. if (refcnt == 1 && mIPCOpen) {
  33. PTCPServerSocketChild::SendRequestDelete();
  34. return 1;
  35. }
  36. return refcnt;
  37. }
  38. TCPServerSocketChild::TCPServerSocketChild(TCPServerSocket* aServerSocket, uint16_t aLocalPort,
  39. uint16_t aBacklog, bool aUseArrayBuffers)
  40. {
  41. mServerSocket = aServerSocket;
  42. AddIPDLReference();
  43. gNeckoChild->SendPTCPServerSocketConstructor(this, aLocalPort, aBacklog, aUseArrayBuffers);
  44. }
  45. void
  46. TCPServerSocketChildBase::ReleaseIPDLReference()
  47. {
  48. MOZ_ASSERT(mIPCOpen);
  49. mIPCOpen = false;
  50. this->Release();
  51. }
  52. void
  53. TCPServerSocketChildBase::AddIPDLReference()
  54. {
  55. MOZ_ASSERT(!mIPCOpen);
  56. mIPCOpen = true;
  57. this->AddRef();
  58. }
  59. TCPServerSocketChild::~TCPServerSocketChild()
  60. {
  61. }
  62. bool
  63. TCPServerSocketChild::RecvCallbackAccept(PTCPSocketChild *psocket)
  64. {
  65. RefPtr<TCPSocketChild> socket = static_cast<TCPSocketChild*>(psocket);
  66. nsresult rv = mServerSocket->AcceptChildSocket(socket);
  67. NS_ENSURE_SUCCESS(rv, true);
  68. return true;
  69. }
  70. void
  71. TCPServerSocketChild::Close()
  72. {
  73. SendClose();
  74. }
  75. } // namespace dom
  76. } // namespace mozilla