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