Backed out 2 changesets (bug 1900622) for causing Bug 1908553 and ktlint failure...
[gecko.git] / netwerk / base / nsServerSocket.h
blob76908697fec2dbe9de735d05906167674cfdc848
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 "nsCOMPtr.h"
12 #include "nsIServerSocket.h"
13 #include "mozilla/Mutex.h"
15 //-----------------------------------------------------------------------------
17 class nsIEventTarget;
18 namespace mozilla {
19 namespace net {
20 union NetAddr;
22 class nsServerSocket : public nsASocketHandler, public nsIServerSocket {
23 public:
24 NS_DECL_THREADSAFE_ISUPPORTS
25 NS_DECL_NSISERVERSOCKET
27 // nsASocketHandler methods:
28 virtual void OnSocketReady(PRFileDesc* fd, int16_t outFlags) override;
29 virtual void OnSocketDetached(PRFileDesc* fd) override;
30 virtual void IsLocal(bool* aIsLocal) override;
31 virtual void KeepWhenOffline(bool* aKeepWhenOffline) override;
33 virtual uint64_t ByteCountSent() override { return 0; }
34 virtual uint64_t ByteCountReceived() override { return 0; }
35 nsServerSocket();
37 virtual void CreateClientTransport(PRFileDesc* clientFD,
38 const mozilla::net::NetAddr& clientAddr);
39 virtual nsresult SetSocketDefaults() { return NS_OK; }
40 virtual nsresult OnSocketListen() { return NS_OK; }
42 protected:
43 virtual ~nsServerSocket();
44 PRFileDesc* mFD{nullptr};
45 nsCOMPtr<nsIServerSocketListener> mListener;
47 private:
48 void OnMsgClose();
49 void OnMsgAttach();
51 // try attaching our socket (mFD) to the STS's poll list.
52 nsresult TryAttach();
54 nsresult InitWithAddressInternal(const PRNetAddr* aAddr, int32_t aBackLog,
55 bool aDualStack = false);
57 // lock protects access to mListener; so it is not cleared while being used.
58 mozilla::Mutex mLock MOZ_UNANNOTATED{"nsServerSocket.mLock"};
59 PRNetAddr mAddr = {.raw = {0, {0}}};
60 nsCOMPtr<nsIEventTarget> mListenerTarget;
61 bool mAttached{false};
62 bool mKeepWhenOffline{false};
65 } // namespace net
66 } // namespace mozilla
68 //-----------------------------------------------------------------------------
70 #endif // nsServerSocket_h__