tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

TCPServerSocket.h (2721B)


      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 #ifndef mozilla_dom_TCPServerSocket_h
      8 #define mozilla_dom_TCPServerSocket_h
      9 
     10 #include "mozilla/DOMEventTargetHelper.h"
     11 #include "nsIServerSocket.h"
     12 
     13 namespace mozilla {
     14 class ErrorResult;
     15 namespace dom {
     16 
     17 struct ServerSocketOptions;
     18 class GlobalObject;
     19 class TCPSocket;
     20 class TCPSocketChild;
     21 class TCPServerSocketChild;
     22 class TCPServerSocketParent;
     23 
     24 class TCPServerSocket final : public DOMEventTargetHelper,
     25                              public nsIServerSocketListener {
     26 public:
     27  TCPServerSocket(nsIGlobalObject* aGlobal, uint16_t aPort,
     28                  bool aUseArrayBuffers, uint16_t aBacklog);
     29 
     30  NS_DECL_ISUPPORTS_INHERITED
     31  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(TCPServerSocket,
     32                                                         DOMEventTargetHelper)
     33  NS_DECL_NSISERVERSOCKETLISTENER
     34 
     35  nsIGlobalObject* GetParentObject() const { return GetOwnerGlobal(); }
     36  JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
     37 
     38  nsresult Init();
     39 
     40  uint16_t LocalPort() const;
     41  void Close();
     42 
     43  static already_AddRefed<TCPServerSocket> Constructor(
     44      const GlobalObject& aGlobal, uint16_t aPort,
     45      const ServerSocketOptions& aOptions, uint16_t aBacklog,
     46      mozilla::ErrorResult& aRv);
     47 
     48  IMPL_EVENT_HANDLER(connect);
     49  IMPL_EVENT_HANDLER(error);
     50 
     51  // Relay an accepted socket notification from the parent process and
     52  // initialize this object with an existing child actor for the new socket.
     53  nsresult AcceptChildSocket(TCPSocketChild* aSocketChild);
     54  // Associate this object with an IPC actor in the parent process to relay
     55  // notifications to content processes.
     56  void SetServerBridgeParent(TCPServerSocketParent* aBridgeParent);
     57 
     58 private:
     59  ~TCPServerSocket();
     60  // Dispatch a TCPServerSocketEvent event of a given type at this object.
     61  void FireEvent(const nsAString& aType, TCPSocket* aSocket);
     62 
     63  // The server socket associated with this object.
     64  nsCOMPtr<nsIServerSocket> mServerSocket;
     65  // The IPC actor in the content process.
     66  RefPtr<TCPServerSocketChild> mServerBridgeChild;
     67  // The IPC actor in the parent process.
     68  RefPtr<TCPServerSocketParent> mServerBridgeParent;
     69  int32_t mPort;
     70  uint16_t mBacklog;
     71  // True if any accepted sockets should use array buffers for received
     72  // messages.
     73  bool mUseArrayBuffers;
     74 };
     75 
     76 }  // namespace dom
     77 }  // namespace mozilla
     78 
     79 #endif  // mozilla_dom_TCPServerSocket_h