Skip to content

polling on a listening socket does not work #8964

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

Open
seandepagnier opened this issue Feb 21, 2024 · 0 comments
Open

polling on a listening socket does not work #8964

seandepagnier opened this issue Feb 21, 2024 · 0 comments
Labels
bug network rp2040 Raspberry Pi RP2040
Milestone

Comments

@seandepagnier
Copy link

CircuitPython version

Adafruit CircuitPython 9.0.0-beta.2 on 2024-02-20; Raspberry Pi Pico W with rp2040
Adafruit CircuitPython 8.2.10 on 2024-02-14; Raspberry Pi Pico W with rp2040

Code/REPL

import time
import wifi, ipaddress, socketpool

import select

ssid="ssid"
password="anything"

#Connect to WLAN                                                                                                                                                                             
pool = socketpool.SocketPool(wifi.radio)

server_connection = False

poller = select.poll()

wifi.radio.connect(ssid, password)
while not wifi.radio.connected:
    time.sleep(1)

print("connected")
# Open a socket                                                                                                                                                                              
host = str(wifi.radio.ipv4_address)

address = (host, 1234)
print('using address', *address)
server_connection = pool.socket(pool.AF_INET, pool.SOCK_STREAM)                                                                                                                                                            
server_connection.bind(address)
server_connection.listen(2)
poller.register(server_connection, select.POLLIN)
print('server socket', server_connection)

while True:
    events = poller.poll(1000)
    for event in events:
        conn = event[0]
        flags = event[1]
        print('event', conn, flags)
        client, addr = conn.accept()
        print('accept return')
        client.send("hi there\n")
        client.close()
    print("poll loop")

Behavior

In micropython it is possible to poll on listening sockets exactly like in regular python. In circuit python, poll always returns with an event on POLLIN, it should only do this when a subsequent call to accept will not block.

Description

This is a simple example, not meant to have practical use, where select.poll always returns immediately even if there is no connection causing conn.accept() to block.

Additional information

No response

@tannewt tannewt added network rp2040 Raspberry Pi RP2040 labels Feb 21, 2024
@tannewt tannewt added this to the Long term milestone Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug network rp2040 Raspberry Pi RP2040
Projects
None yet
Development

No branches or pull requests

2 participants