{"action":"created","issue":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/993","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/993/labels{/name}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/993/comments","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/993/events","html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/993","id":130061633,"number":993,"title":"Queue for net.socket:send","user":{"login":"Hellsy22","id":6323662,"avatar_url":"https://avatars.githubusercontent.com/u/6323662?v=3","gravatar_id":"","url":"https://api.github.com/users/Hellsy22","html_url":"https://github.com/Hellsy22","followers_url":"https://api.github.com/users/Hellsy22/followers","following_url":"https://api.github.com/users/Hellsy22/following{/other_user}","gists_url":"https://api.github.com/users/Hellsy22/gists{/gist_id}","starred_url":"https://api.github.com/users/Hellsy22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hellsy22/subscriptions","organizations_url":"https://api.github.com/users/Hellsy22/orgs","repos_url":"https://api.github.com/users/Hellsy22/repos","events_url":"https://api.github.com/users/Hellsy22/events{/privacy}","received_events_url":"https://api.github.com/users/Hellsy22/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-01-31T01:33:39Z","updated_at":"2016-02-02T02:17:58Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/993","html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/993","diff_url":"https://github.com/nodemcu/nodemcu-firmware/pull/993.diff","patch_url":"https://github.com/nodemcu/nodemcu-firmware/pull/993.patch"},"body":"Implementation of a queue for ```net.socket:send``` (related: https://github.com/nodemcu/nodemcu-firmware/issues/730)\r\n```lua\r\nsk.send(\"one\");\r\nsk.send(\"two\");\r\nsk.send(\"three\");\r\n```\r\n\r\nwill send \"one\", \"two\", \"three\" to the socket, instead of sending \"one\" and discarding all other data. After empting the queue a ```sent``` event will occur.\r\n\r\nBackward compatibility:  previous ```send-sent-send more``` model is\r\nstill usable without any extra memory cost.\r\n\r\nBonus: no more 1460 chars string limit - strings longer then 1460 will\r\nbe chunked to queue.\r\n\r\nFormatting the code: tabs changed to two spaces, trailing spaces\r\nremoved etc.\r\n\r\nTesting: worked for me for TCP client and server for a few days.\r\n\r\nTODO: (discuss) fill entire queue block before creating another one for a bit better performance.\r\n(discuss) Should fire ```sent``` event if connection was closed before queue empty?\r\n(discuss) LUA-side access to the attribute ```sending``` and to the queue size.\r\n\r\nAlso I found undocumented features, like socket:hold() or server connections limit (5 atm) - any suggetions where I can obtain more information about net module?"},"comment":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments/178315560","html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/993#issuecomment-178315560","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/993","id":178315560,"user":{"login":"Hellsy22","id":6323662,"avatar_url":"https://avatars.githubusercontent.com/u/6323662?v=3","gravatar_id":"","url":"https://api.github.com/users/Hellsy22","html_url":"https://github.com/Hellsy22","followers_url":"https://api.github.com/users/Hellsy22/followers","following_url":"https://api.github.com/users/Hellsy22/following{/other_user}","gists_url":"https://api.github.com/users/Hellsy22/gists{/gist_id}","starred_url":"https://api.github.com/users/Hellsy22/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hellsy22/subscriptions","organizations_url":"https://api.github.com/users/Hellsy22/orgs","repos_url":"https://api.github.com/users/Hellsy22/repos","events_url":"https://api.github.com/users/Hellsy22/events{/privacy}","received_events_url":"https://api.github.com/users/Hellsy22/received_events","type":"User","site_admin":false},"created_at":"2016-02-02T02:17:58Z","updated_at":"2016-02-02T02:17:58Z","body":"> You are mallocing and freeing extra string buffers.\r\n\r\nOnly if sending in progress already. Otherwise data will be passed to the ```espconn_sent``` directly.\r\n\r\n> that it trivial to modify your Lua code\r\n\r\nYour lua solution takes 1.5-2k memory for *every* socket even with empty buffer.\r\n\r\n> This should be a different API function, not send.\r\n\r\n```sendq``` is a fine too.\r\n\r\n> If we try to replicate old buggy behaviour, then we we just be recreating old bugs\r\n\r\nWe have pile of data need to be send. So, we can make a queue on firmware side. We can spend twice more memory to make a queue on lua-side. Or we can spend three times more memory to make a queue on lua side via multiple callbacks definitions.\r\nBut problem will persist anyway: because pile of data still need to be send.\r\n\r\n> create your own fork\r\n\r\nSure. Just thought it can be helpful.\r\nSo about this case. I would:\r\n\r\n1. Make all functionality disabled from code by default.\r\n2. Choose another function name (```sendq```).\r\n3. Use lua strings instead of allocating new buffers.\r\n4. Do nothing about ```close``` case because have no idea what problem is (I read the SDK release notes).\r\n"}}