Skip to content

Improve how non-core socket implementations get their value of SOCK_STREAM. #10072

Open
@jepler

Description

@jepler

Recently in Discord, @tannewt encountered that zephyr uses different numeric values for some socket-related constants (vs lwip)

For core ssl support to work with pure Python socket implementations, such as wiznet, we had to promise that socket constants used by the ssl implementation would be the same numeric constants always, regardless of the internal implementation of sockets.

I think that the sole constant we depend on is is SOCK_STREAM = 1. This is because SSL can work on STREAM type sockets but not DGRAM type sockets.

@tannewt suggested that instead of the current approach of promising SOCK_STREAM = 1 (the lwip value, used by raspberrypi & espressif), anytime we enable ssl in the core we could provide a minimal socket library with SOCK_STREAM = (some value), not necessarily 1.

Then, wiznet would have to do something like

try:
    from socket import SOCK_STREAM
except ImportError:
    SOCK_STREAM = 1
SOCK_DGRAM = SOCK_STREAM + 1

wiznet currently has to adapt to different SOCK_ type numbering anyway, because wiznet uses 0x21 for SOCK_STREAM. (though it does so in a somewhat clever way that assumes the current values of 1 & 2)

Marking as a 10.0 milestone because undoing the promise that SOCK_STREAM=1 is an incompatible change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions