Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEAmDNS_Fixes_1_3 #5689

Merged
merged 4 commits into from
Jan 30, 2019
Merged

LEAmDNS_Fixes_1_3 #5689

merged 4 commits into from
Jan 30, 2019

Conversation

LaborEtArs
Copy link
Contributor

Re-Fix 'avoid multiple initialization' code in LEAmDNSResponder::begin()

Copy link
Collaborator

@devyte devyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From gitter discussion:
@LaborEtArs with the UdpContext check, isn't the new hostname passed as arg to begin ignored?
Should the begin() implementation look something like this (unoptimized for the logic tree)?:

bool MDNSResponder::begin(const char* p_pcHostname) {

    bool    bResult = (0 != m_pcHostname);

    if (0 == m_pUDPContext) {
        if (_setHostname(p_pcHostname)) {

            m_GotIPHandler = WiFi.onStationModeGotIP([this](const WiFiEventStationModeGotIP& pEvent) {
                (void) pEvent;
                _restart();
            });

            m_DisconnectedHandler = WiFi.onStationModeDisconnected([this](const WiFiEventStationModeDisconnected& pEvent) {
                (void) pEvent;
                _restart();
            });

            bResult = _restart();
        }
    } else {
        if (_setHostname(p_pcHostname)) {
            bResult = _restart();
        }
        DEBUG_EX_INFO(DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: Ignoring multiple calls (Ignored host domain: '%s')!\n"), (p_pcHostname ?: "-")););
    }
    DEBUG_EX_ERR(if (!bResult) { DEBUG_OUTPUT.printf_P(PSTR("[MDNSResponder] begin: FAILED for '%s'!\n"), (p_pcHostname ?: "-")); } );
    return bResult;
}

Is the use of bool bResult = (0 != m_pcHostname); correct?

@LaborEtArs
Copy link
Contributor Author

@devyte : You're right, the code was TOO 'quick and dirty', but I don't like your proposed code too, When 'begin()' was called once, another call to begin() should fail. At least it shouldn't change something silently (as it would, if OTA will be initialized after mDNS by the user). Unfortunately I can't change the code here (webeditor?, maybe only for branch owners? Maybe not with IE...?)...
The initial 'bool bResult = (0 != m_pcHostname);' should be 'bool bResult = (0 != m_pUDPContext);' if multiple calls should lead to 'false' or simple 'bool bResult = false;' (as I would prefer).
In addition the secend log should to moved to the end of the 'if-clause' to avoid misleading logs.

@LaborEtArs
Copy link
Contributor Author

Updated (and included the 'schedule_function(std::bind(&MDNSResponder::_restart, this));' to avoid calling _restart() in SYS context.

@devyte devyte merged commit 3f267bd into esp8266:master Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants