Skip to content

Use socket.AI_NUMERICHOST ? #9

@vshymanskyy

Description

@vshymanskyy

Currently, we check if hostname is numeric like this (_gai is the original socket.getaddrinfo):

if _ip4(host) or _ip6(host):
    return _gai(host, port, family, type, proto, flags)

We could completely remove _ip4 and _ip6 functions and use AI_NUMERICHOST which will reduce the code size by ~10%:

try:
    return _gai(host, port, family, type, proto, flags | socket.AI_NUMERICHOST)
except Exception:
    pass

This was tested with Python 3 and works fine.
However, AI_NUMERICHOST is currently is not exposed in MicroPython.
It does seem to be available in lwip so we could use it. It requires more testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions