lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Oliver Kroth
> Sent: woensdag 4 maart 2015 9:08
> To: lua-l@lists.lua.org
> Subject: Re: using Copas with LuaSec, non-blocking ssl
> 
> Thijs,
> 
> you are right. I found the same while implementing SSL with LuaSEC in my
> project.
> 
> Currently I am trying get LuaSec and Copas work together in a
> non-blocking fashion, which is not that easy as there are some more
> issues between the socket library and the Copas which make a
> non-blocking connect() not 100% reliable on some OS.
> The LuaSec functions in between complicate this a little bit further:-)
> 
> --
> Oliver
> 

Have a look at this [1] Copas branch. It includes full async LuaSec support. And all of LuaSockets' client libraries (http, ftp, smtp) in async mode. Copas will handle the LuaSec specific "wantread" and "wantwrite" timeout errors.

I updated the `connect` method as mentioned here [2]. To make it resilient for the errors. BTW I'm not sure it is a LuaSocket error or just the way sockets work... and hence something a client needs to handle.

But please test the Copas branch on the platforms you know to be unreliable. I could use some feedback.



Some examples;

For a client you can just wrap the socket with ssl parameters (top of mind, untested);

copas.addthread(function()
  local skt = copas.wrap(socket.tcp(), ssl_param_table)
  
  -- from here, skt:connect() will include the ssl handshake and all read/write is async

end)

For a server handler (top of mind, untested);

local handler = function(skt)
  skt = copas.wrap(skt, ssl_param_table)
  local success, err = skt:handshake()

  -- from here all read/write is async ssl wrapped
  
end

I'm looking into wrapping the server socket (TCP master), in such a way that the `skt` passed to the handler is already wrapped with the ssl handshake completed. But that would be just a convenience.

Thijs

[1] https://github.com/Tieske/copas/tree/ssl_implemented
[2] https://github.com/diegonehab/luasocket/issues/99#issuecomment-77056657