diff mbox series

[2/2] lua_swupdate: do not auto-connect in progress()

Message ID 20220221151850.127406-2-michael.adler@siemens.com
State Accepted
Headers show
Series [1/2] lua_swupdate: extend progress_connect method | expand

Commit Message

Michael Adler Feb. 21, 2022, 3:18 p.m. UTC
We do not auto-connect in the case of control() either, so this unifies
the API. Also, if we are interested in the connection handle, we would
need to call connect() anyway, which results in closing the original connection.

Signed-off-by: Michael Adler <michael.adler@siemens.com>
---
 bindings/lua_swupdate.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

Comments

Stefano Babic March 21, 2022, 5:54 p.m. UTC | #1
On 21.02.22 16:18, Michael Adler wrote:
> We do not auto-connect in the case of control() either, so this unifies
> the API. Also, if we are interested in the connection handle, we would
> need to call connect() anyway, which results in closing the original connection.
> 
> Signed-off-by: Michael Adler <michael.adler@siemens.com>
> ---
>   bindings/lua_swupdate.c | 17 +++--------------
>   1 file changed, 3 insertions(+), 14 deletions(-)
> 
> diff --git a/bindings/lua_swupdate.c b/bindings/lua_swupdate.c
> index e8cf8a7..74efad7 100644
> --- a/bindings/lua_swupdate.c
> +++ b/bindings/lua_swupdate.c
> @@ -338,28 +338,17 @@ static int progress_receive(lua_State *L) {
>   }
>   
>   static int progress(lua_State *L) {
> -
> -	int connfd;
> -
> -	connfd = progress_ipc_connect(WAIT);
> -
> -	if (connfd < 0) {
> -		lua_pushnil(L);
> -		return 2;
> -	}
> -
> -	/* allocate   progress object */
> +	/* allocate progress object */

I can do it, but I have to synchronize with :

https://github.com/sbabic/SWUpdateGUI/blob/master/SWUpdateGUI.lua#L979

That means after merging these I have to update in SWUpdateGUI with:
    prog = sw:progress()
    prog->connect()

Right ?


>   	struct prog_obj *p = (struct prog_obj *) lua_newuserdata(L, sizeof(*p));
> -	p->socket = connfd;
> +	p->socket = -1;
>   	p->status = IDLE;
>   
>   	/* set its type as master object */
>   	auxiliar_setclass(L, "swupdate_progress", -1);
>   
>   	return 1;
> -
>   }
> -
> +
>   static const luaL_Reg lua_swupdate[] = {
>     {"progress", progress},
>     {"control", ctrl},

Regards,
Stefano
Michael Adler March 22, 2022, 7:14 a.m. UTC | #2
Hi Stefano,

> That means after merging these I have to update in SWUpdateGUI with:
>    prog = sw:progress()
>    prog->connect()

correct, but : instead of ->. Further you can now check for an error condition, e.g.

local prog = swupdate.prog()
local fd, err = prog:connect()
if not fd then print(err) end

Kind regards,
  Michael
Stefano Babic March 22, 2022, 7:37 a.m. UTC | #3
On 22.03.22 08:14, Michael Adler wrote:
> Hi Stefano,
> 
>> That means after merging these I have to update in SWUpdateGUI with:
>>     prog = sw:progress()
>>     prog->connect()
> 
> correct, but : instead of ->.

Of course !

> Further you can now check for an error condition, e.g.
> 
> local prog = swupdate.prog()
> local fd, err = prog:connect()
> if not fd then print(err) end
> 

Ok, I will take care of it, I will merge first your patches.

Regards,
Stefano

> Kind regards,
>    Michael
>
diff mbox series

Patch

diff --git a/bindings/lua_swupdate.c b/bindings/lua_swupdate.c
index e8cf8a7..74efad7 100644
--- a/bindings/lua_swupdate.c
+++ b/bindings/lua_swupdate.c
@@ -338,28 +338,17 @@  static int progress_receive(lua_State *L) {
 }
 
 static int progress(lua_State *L) {
-
-	int connfd;
-
-	connfd = progress_ipc_connect(WAIT);
-
-	if (connfd < 0) {
-		lua_pushnil(L);
-		return 2;
-	}
-
-	/* allocate   progress object */
+	/* allocate progress object */
 	struct prog_obj *p = (struct prog_obj *) lua_newuserdata(L, sizeof(*p));
-	p->socket = connfd;
+	p->socket = -1;
 	p->status = IDLE;
 
 	/* set its type as master object */
 	auxiliar_setclass(L, "swupdate_progress", -1);
 
 	return 1;
-
 }
- 
+
 static const luaL_Reg lua_swupdate[] = {
   {"progress", progress},
   {"control", ctrl},