tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsServerSocket.h (2225B)


      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/. */
      5 
      6 #ifndef nsServerSocket_h__
      7 #define nsServerSocket_h__
      8 
      9 #include "prio.h"
     10 #include "nsASocketHandler.h"
     11 #include "nsCOMPtr.h"
     12 #include "nsIServerSocket.h"
     13 #include "mozilla/Mutex.h"
     14 
     15 //-----------------------------------------------------------------------------
     16 
     17 class nsIEventTarget;
     18 namespace mozilla {
     19 namespace net {
     20 union NetAddr;
     21 
     22 class nsServerSocket : public nsASocketHandler, public nsIServerSocket {
     23 public:
     24  NS_DECL_THREADSAFE_ISUPPORTS
     25  NS_DECL_NSISERVERSOCKET
     26 
     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;
     32 
     33  virtual uint64_t ByteCountSent() override { return 0; }
     34  virtual uint64_t ByteCountReceived() override { return 0; }
     35  nsServerSocket();
     36 
     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; }
     41 
     42 protected:
     43  virtual ~nsServerSocket();
     44  PRFileDesc* mFD{nullptr};
     45  nsCOMPtr<nsIServerSocketListener> mListener;
     46 
     47 private:
     48  void OnMsgClose();
     49  void OnMsgAttach();
     50 
     51  // try attaching our socket (mFD) to the STS's poll list.
     52  nsresult TryAttach();
     53 
     54  nsresult InitWithAddressInternal(const PRNetAddr* aAddr, int32_t aBackLog,
     55                                   bool aDualStack = false);
     56 
     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};
     63 };
     64 
     65 }  // namespace net
     66 }  // namespace mozilla
     67 
     68 //-----------------------------------------------------------------------------
     69 
     70 #endif  // nsServerSocket_h__