Skip to content
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

Improve usability/factorization of bufferedConnection #52

Open
devyte opened this issue Feb 19, 2016 · 1 comment
Open

Improve usability/factorization of bufferedConnection #52

devyte opened this issue Feb 19, 2016 · 1 comment

Comments

@devyte
Copy link
Contributor

devyte commented Feb 19, 2016

The bufferedConnection code has been pulled out into its own file. This improves usability, but the result needs more work.
Specifically, usage depends on a socket onSent() callback, which is outside the bufferedConnection file, and on coroutine creation/handling/destruction code, which are also outside the bufferedConnection file.
The ideal buffered connection would have a usage model as close as possible to the current socket usage model, have all the coroutine code hidden away, have a small mem footprint, and trivial to integrate into an application for general use.
I would suggest creating something along the lines of another class which wraps the bufferedConnection, maybe called a "threaded" connection, which contains the missing pieces of dependent code. This is just an idea of course, and open for discussion.

@devyte
Copy link
Contributor Author

devyte commented Mar 8, 2016

I have a solution that encapsulates the bufferedConnection as well as the whole coroutine uglyness. Please see nodemcu-platform, file tbconnection.lua, and httpserver for usage. The encapsulation is a threaded-buffered connection. It is constructed with a normal connection, and has a :run() method that receives as arguments a function and optional arguments to pass to the function. The function passed as argument receives as first argument a buffered connection and the optional arguments passed to run(). Inside of it, you can :send() all you wish, the payloads will be buffered into chunks of threshold sice (currently set to 256 bytes), and then they get flush()ed and physically sent.
Example:
local function servefunc(bconn, msg)
bconn:send(msg)
end

local msg = "hello nodemcu"
local tbconn = dofile("tbconnection.lc")(connection)
tbconn:run(servefunc, msg)

It seems to work, but mem footprint is along the lines of 6K, which is large, so any ideas to reduce it are welcome. @marcoskirsch @pjsg I think it solves this issue, but you'd have to pick it up and integrate it into this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant