struct espconn and reverse field

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

struct espconn and reverse field

Postby kolban » Tue Jul 07, 2015 11:04 am

The struct espconn data structure has a field in it called "reverse". Looking at the SDK API docs, the comment beside the field is:

// reserved for customer use

I am thinking that we have a typo in the field name and instead of "reverse" (which in English means "to go backwards") it should be "reserved" (which in English means to "pre-allocate in advance").

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: struct espconn and reverse field

Postby ESP_Faye » Tue Jul 07, 2015 4:18 pm

Hi,

Thanks for your advice !

So sorry for our poor English .. :oops:

We will revise them in next SDK !

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Re: struct espconn and reverse field

Postby kolban » Tue Jul 07, 2015 10:24 pm

Please ... no need to apologize. I'm a huge fan of the ESP8266 and am grateful for all y'alls work and especially for being super responsive to your community.

zaxl
Posts: 29
Joined: Mon Jun 08, 2015 6:34 pm
Contact:

Re: struct espconn and reverse field

Postby zaxl » Thu Jul 09, 2015 7:07 am

Hi,


If you are going to rename the field, please, please do not name it to "reserved".

In english it may mean "pre-allocate in advance" but in any kind of code it means - reserved - do not touch, do not use . Most common case is reserved for future use. Other variants include but not limited to - get proper struct padding, get specific struct size, get specific struct members alignment.

The right way to name a callback data is:
void *data; // user callback data
or
void *callback_data; // if you want to be more verbose
or
void *priv; // which means it's private to the user, i.e. the sdk would not touch it

TIA!
Regards,
zaxl

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Re: struct espconn and reverse field

Postby kolban » Thu Jul 09, 2015 11:51 am

Great catch Zaxl,

My personal vote would be one of:

void *data;

or

void *userData;

User avatar
kolban
Posts: 131
Joined: Tue Jun 16, 2015 1:09 pm
Location: Fort Worth, Texas, USA

Re: struct espconn and reverse field

Postby kolban » Wed Oct 28, 2015 8:46 am

I'm starting to get nervous that the "struct espconn -> reverse" property may not be safe for end user applications to store arbitrary pointers of data. Does anyone have any evidence one way or the other whether this pointer contained within a struct espconn can be used for end user applications?

ESP_Faye
Posts: 1646
Joined: Mon Oct 27, 2014 11:08 am

Re: struct espconn and reverse field

Postby ESP_Faye » Fri Oct 30, 2015 11:05 am

Hi,

Sorry that we did not modify the "reverse" to be "reserve", because some developers may already use it.

But we are working on RTOS espconn now, it will be fixed in RTOS espconn. It is reserved for user data.

Code: Select all

struct espconn {
    enum espconn_type type;     /**< type of the espconn (TCP or UDP)   */
    enum espconn_state state;   /**< current state of the espconn       */
    union {
        esp_tcp *tcp;
        esp_udp *udp;
    } proto;
    espconn_recv_callback recv_callback;    /**< data received callback */
    espconn_sent_callback sent_callback;    /**< data sent callback     */
    uint8 link_cnt;         /**< link count             */
    void *reserve;          /**< reserved for user data */
};

Who is online

Users browsing this forum: No registered users and 5 guests