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"
11 #include "nsIServerSocket.h"
12 #include "mozilla/Mutex.h"
14 //-----------------------------------------------------------------------------
21 class nsServerSocket
: public nsASocketHandler
, public nsIServerSocket
{
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; }
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
; }
42 virtual ~nsServerSocket();
43 PRFileDesc
* mFD
{nullptr};
44 nsCOMPtr
<nsIServerSocketListener
> mListener
;
50 // try attaching our socket (mFD) to the STS's poll list.
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};
65 } // namespace mozilla
67 //-----------------------------------------------------------------------------
69 #endif // nsServerSocket_h__