Git Product home page Git Product logo

Comments (5)

moteus avatar moteus commented on June 1, 2024

I found only problem in client
handle:write have to have callback. client:write('quit', function() end)
I already thinking about to make it optional.

But there no unexpected crashes.

from lua-lluv.

zhaozg avatar zhaozg commented on June 1, 2024

Sure, I means that should generate lua error, because inner check callable, but invalid pointer report when I debug in visual studio, I think memory or stack somewhere wrong.

I found only problem in client
handle:write have to have callback. client:write('quit', function() end)
I already thinking about to make it optional.

But there no unexpected crashes.

from lua-lluv.

moteus avatar moteus commented on June 1, 2024
  1. I just push version with optional callbak.
  2. You mean client get corruption?

from lua-lluv.

moteus avatar moteus commented on June 1, 2024

I can not reproduce it.
I little cleanup code

local uv = require'lluv'

local host = arg[1] or '127.0.0.1'
local port = arg[2] and tonumber(arg[2]) or 8080

local server = uv.tcp()

local count = 0
local cli_count = 0

local function dec_cli_count() cli_count = cli_count - 1 end

local function setInterval(fn, ms)
  return uv.timer()
    :start(ms, ms, function(timer) fn() end)
end

setInterval(function()
  print(os.date(), count .. "/" .. cli_count)
  collectgarbage()
end, 1000)

server:bind(host, port):listen(function(server, err)
  if err then
    print("LISTEN: ", err)
    return server:close()
  end

  local cli, err = server:accept()

  if not cli then
    print("ACCEPT: ", err)
    return
  end

  count = count + 1
  cli_count = cli_count + 1

  cli:start_read(function(cli, err, data)
    if err then
      print("READ: ", err)
      return cli:close(dec_cli_count)
    end

    if data == 'quit' then
      cli:close(dec_cli_count)
    end
  end)
end)

uv.run()

print("done")
local uv = require'lluv'

local host = arg[1] or '127.0.0.1'
local port = arg[2] and tonumber(arg[2]) or 8080
local step = arg[3] and tonumber(arg[3]) or 1

local count = 0
local keep = true

local function setInterval(fn, ms)
  return uv.timer()
    :start(ms, ms, function(timer) fn() end)
end

function newconnection()
  return uv.tcp():connect(host, port, function(client, err)
    if err then
      print('Connect', err and err or 'OK')
      return client:close()
    end

    client:start_read(function(cli, err, data)
      if err then
        if err:no() ~= uv.EOF then
          print("READ: ", err)
        end
        return cli:close()
      end
      if(data=='quit') then
        cli:close()
      end
    end)

    client:write('quit')

  end)
end

setInterval(function()
  print(os.date(),count)
  --collectgarbage()
  if count < 16000 then
    for i=1,step do
      newconnection()
    end
  end
end, 1000)

print(pcall(uv.run()))

print("done")

from lua-lluv.

zhaozg avatar zhaozg commented on June 1, 2024

after update a76b175 code, works ok.

from lua-lluv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.