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__
10 #include "nsASocketHandler.h"
12 #include "nsIServerSocket.h"
13 #include "mozilla/Mutex.h"
15 //-----------------------------------------------------------------------------
22 class nsServerSocket
: public nsASocketHandler
, public nsIServerSocket
{
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; }
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
; }
43 virtual ~nsServerSocket();
44 PRFileDesc
* mFD
{nullptr};
45 nsCOMPtr
<nsIServerSocketListener
> mListener
;
51 // try attaching our socket (mFD) to the STS's poll list.
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};
66 } // namespace mozilla
68 //-----------------------------------------------------------------------------
70 #endif // nsServerSocket_h__