netwerk/system/win32/nsNotifyAddrListener.h
author Daniel Stenberg <daniel@haxx.se>
Sun, 24 Aug 2014 23:19:00 -0400
changeset 201651 37bee525b188aad6912807f36627432fe4716598
parent 194814 415c6545336872702b3307e4fa14efdec6630bb1
child 201656 cc131cf9ef81b6980ab5fe8c091f8758d2b22ae2
permissions -rw-r--r--
Bug 939318 - Detect network interface changes on windows properly. r=mcmanus Now supports IPv6 as well if a new enough windows version is used. Which notification function to use is detect at run-time. Now sends CHANGED event if the online interface(s) are different in any way since it was previously checked and considered UP. CHANGED is sent before UP in case both are detected. nIOService: split up the network event receiver function from the network status init function and have the event receiver act on the incoming event. DNSservice: acts on network changes (flushes the host cache) HttpHandler: acts on network changes

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set et sw=4 ts=4: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef NSNOTIFYADDRLISTENER_H_
#define NSNOTIFYADDRLISTENER_H_

#include <windows.h>
#include <winsock2.h>
#include <iptypes.h>
#include "nsINetworkLinkService.h"
#include "nsIRunnable.h"
#include "nsIObserver.h"
#include "nsThreadUtils.h"
#include "nsCOMPtr.h"

class nsNotifyAddrListener : public nsINetworkLinkService,
                             public nsIRunnable,
                             public nsIObserver
{
    virtual ~nsNotifyAddrListener();

public:
    NS_DECL_THREADSAFE_ISUPPORTS
    NS_DECL_NSINETWORKLINKSERVICE
    NS_DECL_NSIRUNNABLE
    NS_DECL_NSIOBSERVER

    nsNotifyAddrListener();

    nsresult Init(void);
    void CheckLinkStatus(void);

protected:
    class ChangeEvent : public nsRunnable {
    public:
        NS_DECL_NSIRUNNABLE
        ChangeEvent(nsINetworkLinkService *aService, const char *aEventID)
            : mService(aService), mEventID(aEventID) {
        }
    private:
        nsCOMPtr<nsINetworkLinkService> mService;
        const char *mEventID;
    };

    bool mLinkUp;
    bool mStatusKnown;
    bool mCheckAttempted;

    nsresult Shutdown(void);
    nsresult SendEvent(const char *aEventID);

    DWORD CheckAdaptersAddresses(void);

    // Checks for an Internet Connection Sharing (ICS) gateway.
    bool  CheckICSGateway(PIP_ADAPTER_ADDRESSES aAdapter);
    bool  CheckICSStatus(PWCHAR aAdapterName);

    nsCOMPtr<nsIThread> mThread;

    HANDLE        mShutdownEvent;

private:
    // This is a checksum of various meta data for all network interfaces
    // considered UP at last check.
    ULONG mIPInterfaceChecksum;
};

#endif /* NSNOTIFYADDRLISTENER_H_ */