Skip to content

add net.FRAME_SIZE constant #3689

@dwexel

Description

@dwexel

Missing feature

Using the net module is awkward, because it uses the concept of a network frame in the api design, but doesn't include a way for the programmer to reference that concept in the code we're writing.

That's why I would propose adding net.FRAME_SIZE as a constant, to make code more readable and meaningful.

You could use it to check the size of data chunks to see which sockets will be outputting data that needs to get buffered. Here's how it might work

function receiver(sck, data)
	if data:len() < net.FRAME_SIZE then
		-- a first or last frame
	else
		-- a chunked frame, in the middle of a stream
	end
end

local data = ...

function sender(sck)
	if data:len() > net.FRAME_SIZE then
		-- send the first chunk
		sck:send(string.sub(data, 1, net.FRAME_SIZE))
		data = string.sub(data, net.FRAME_SIZE + 1, -1)
	elseif data:len() > 0 sck:send(data)
        else sck:close()
	end
end

See issue #1010 and note that we reserve the right to close feature requests if the originating poster is not proposing to resource the development him or herself.

I am willing to resource the development myself.

Justification

As above.

Workarounds

Are there any workarounds you currently have in place because the feature is missing?
If anyone has any ideas, let me know!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions