Bug 1804798 - Explicitly set auto page name (and corresponding debug flag) when inser...
[gecko.git] / netwerk / base / nsServerSocket.h
blobc28e929b433a38ffe8fc45515953a8d2266707bb
1 /* vim:set ts=2 sw=2 et cindent: */
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
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsServerSocket_h__
7 #define nsServerSocket_h__
9 #include "prio.h"
10 #include "nsASocketHandler.h"
11 #include "nsIServerSocket.h"
12 #include "mozilla/Mutex.h"
14 //-----------------------------------------------------------------------------
16 class nsIEventTarget;
17 namespace mozilla {
18 namespace net {
19 union NetAddr;
21 class nsServerSocket : public nsASocketHandler, public nsIServerSocket {
22 public:
23 NS_DECL_THREADSAFE_ISUPPORTS
24 NS_DECL_NSISERVERSOCKET
26 // nsASocketHandler methods:
27 virtual void OnSocketReady(PRFileDesc* fd, int16_t outFlags) override;
28 virtual void OnSocketDetached(PRFileDesc* fd) override;
29 virtual void IsLocal(bool* aIsLocal) override;
30 virtual void KeepWhenOffline(bool* aKeepWhenOffline) override;
32 virtual uint64_t ByteCountSent() override { return 0; }
33 virtual uint64_t ByteCountReceived() override { return 0; }
34 nsServerSocket();
36 virtual void CreateClientTransport(PRFileDesc* clientFD,
37 const mozilla::net::NetAddr& clientAddr);
38 virtual nsresult SetSocketDefaults() { return NS_OK; }
39 virtual nsresult OnSocketListen() { return NS_OK; }
41 protected:
42 virtual ~nsServerSocket();
43 PRFileDesc* mFD{nullptr};
44 nsCOMPtr<nsIServerSocketListener> mListener;
46 private:
47 void OnMsgClose();
48 void OnMsgAttach();
50 // try attaching our socket (mFD) to the STS's poll list.
51 nsresult TryAttach();
53 nsresult InitWithAddressInternal(const PRNetAddr* aAddr, int32_t aBackLog,
54 bool aDualStack = false);
56 // lock protects access to mListener; so it is not cleared while being used.
57 mozilla::Mutex mLock MOZ_UNANNOTATED{"nsServerSocket.mLock"};
58 PRNetAddr mAddr = {.raw = {0, {0}}};
59 nsCOMPtr<nsIEventTarget> mListenerTarget;
60 bool mAttached{false};
61 bool mKeepWhenOffline{false};
64 } // namespace net
65 } // namespace mozilla
67 //-----------------------------------------------------------------------------
69 #endif // nsServerSocket_h__