Page 1 of 1

ESP8266 socket read without allocating new objects.

Posted: Mon Feb 06, 2017 8:07 pm
by MyUsername
My aim is to read from socket without allocating new objects. There is no recv_into or readinto methods in esp sockets. Moreover I have found out that basic onrecv callback is also not implemented in ESP. However, I have found this topic http://forum.micropython.org/viewtopic. ... ket#p17505 and have revealed the possibility of registering callback. But I still do not understand, what is the purpose for registering that handler, because according to the corresponding commit https://github.com/micropython/micropyt ... abe0ea66e3 only socket object is passed into the handler. Which gives us no information about an event and gives no opportunity not to allocate new buffer.

I feel like I'm missing something. If I am not, is there any way to read from socket without allocations?

Re: ESP8266 socket read without allocating new objects.

Posted: Tue Feb 07, 2017 6:53 am
by Roberthh
In one of the recent builds, the readinto() was added. Maybe that helps.
About the socket callback: You can actually allocate memory in that callback. In the callback, you can do almost everything allowed in Python. if you look at my ftp server (https://github.com/robert-hh/ESP8266-FTP-Server) or similar other projects (e.g. @gpopp's telnet server), you'll find that the bulk of the code runs in the callback, including file operations.
And you have the value of the socket. You may register different callbacks for different sockets, or one callback and determine from the value of the socket the purpose of the call.

Re: ESP8266 socket read without allocating new objects.

Posted: Thu Feb 09, 2017 12:01 pm
by MyUsername
Roberthh wrote:In one of the recent builds, the readinto() was added. Maybe that helps.
About the socket callback: You can actually allocate memory in that callback. In the callback, you can do almost everything allowed in Python. if you look at my ftp server (https://github.com/robert-hh/ESP8266-FTP-Server) or similar other projects (e.g. @gpopp's telnet server), you'll find that the bulk of the code runs in the callback, including file operations.
And you have the value of the socket. You may register different callbacks for different sockets, or one callback and determine from the value of the socket the purpose of the call.
Yes, it helped. Thanks!