Skip to content

Add readline(keep_max) to optimize memory usage #1

@Neradoc

Description

@Neradoc

readline(keep_max) reads a full line, but only returns keep_max characters, avoiding unnecessary memory allocations.
readline(keep_max = 0) simply skips a line, as uwebsockets discards all headers but the first one.
Return the total number of characters in addition to the captured data, to differentiate between an empty line and keep_max = 0.

    header,lenh = sock.readline(keep_max = 13)
    assert header.startswith(b'HTTP/1.1 101 '), header
    while lenh > 0:
        if __debug__: LOGGER.debug(str(header))
        header,lenh = sock.readline(keep_max = 0)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions