lua-users home
lua-l archive

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


On Mon, Jun 22, 2009 at 10:36 AM, Francisco Sant'anna <francisco.santanna@gmail.com> wrote:

Hello,

The documented patterns for client:receive are '*a', '*l', or a number. Is it possible to get everything that is available on the socket in a given moment? (I'm using socket.select with all connections with settimeout(0).)

Its harder than it should be. I do this:
--[[-
-- data, emsg = sockext.read(client, pattern[, prefix])
 
Identical to client:receive(), except that if partial data was read, it returns
it instead of returning nil.
 
This is convenient for binary/non-line-delimited protocols.
]]
function read(client, pattern, prefix)
  local data, emsg, partial = client:receive(pattern, prefix)
  if data then
    return data
  end
  if partial and #partial > 0 then
    return partial
  end
  return nil, emsg
end

From 

http://github.com/sam-github/swirl/blob/af29de8aa44359569504914912010affd874da92/lua/sockext.lua


I couldn't also find in the API a way to check if the client connection with the server is still open.


How would you do that with the underlying C sockets API?

Sam