Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #300 from luvit/test-tls-client-econnreset
Browse files Browse the repository at this point in the history
Test tls client econnreset
  • Loading branch information
philips committed Aug 14, 2012
2 parents a883ebd + 1ac93de commit 4a8df64
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/luvit/uv.lua
Expand Up @@ -21,6 +21,12 @@ objects.
local Handle = Emitter:extend()
uv.Handle = Handle

function Handle:initialize()
self:on('closed', function()
self._closed = true
end)
end

-- Wrapper around `uv_close`. Closes the underlying file descriptor of a handle.
-- Handle:close()
Handle.close = function(self)
Expand Down Expand Up @@ -99,7 +105,13 @@ function Stream:resume()
end

-- Stream:write(chunk, callback)
Stream.write = native.write
function Stream:write(chunk, callback)
if self._closed then
error("attempting to write to closed stream")
return
end
native.write(self, chunk, callback)
end

Stream.pipe = iStream.pipe

Expand Down
3 changes: 3 additions & 0 deletions src/luv_process.c
Expand Up @@ -153,6 +153,9 @@ int luv_process_kill(lua_State* L) {
uv_process_t* handle = (uv_process_t*)luv_checkudata(L, 1, "process");
int signum = luaL_checkint(L, 2);

if (handle == NULL)
return 0;

if (uv_process_kill(handle, signum)) {
uv_err_t err = uv_last_error(luv_get_loop(L));
return luaL_error(L, "process_kill: %s", uv_strerror(err));
Expand Down
5 changes: 4 additions & 1 deletion tests/test-net.lua
Expand Up @@ -44,9 +44,12 @@ server:listen(PORT, HOST, function(err)
client:on('data', function(data)
assert(#data == 5)
assert(data == 'hello')
client:destroy()
-- Ensure double destroy doesn't return an error
client:destroy()
server:close()
server:close()
-- Ensure double close returns an error
local success, err = pcall(server.close, server)
assert(success == false)
Expand Down
65 changes: 65 additions & 0 deletions tests/test-tls-client-econnreset.lua
@@ -0,0 +1,65 @@
require('helper')
local fixture = require('./fixture-tls')
local childprocess = require('childprocess')
local os = require('os')
local tls = require('tls')
local timer = require('timer')

local args = {
's_server',
'-accept', fixture.commonPort,
'-key', 'fixtures/keys/agent1-key.pem',
'-cert', 'fixtures/keys/agent1-cert.pem',
}

local child = childprocess.spawn('openssl', args)
child:on('error', function(err)
p(err)
end)
child:on('exit', function(exit_status)
print('server exited')
end)
child:on('error', function(err)
p(err)
end)
child.stdout:on('data', function(data)
print('server: ' .. data)
end)
child.stderr:on('data', function(data)
print('server: ' .. data)
end)

interval = timer.setInterval(100, function()
local success, err = pcall(child.stdin.write, child.stdin, "Hello world")
end)

timer.setTimeout(200,function ()
local c
c = tls.connect({port = fixture.commonPort, host = '127.0.0.1'})
c:on('error', function(err)
print("got connection error")
p(err)
end)
c:on('closed', function()
print('got closed signal')
end)
c:on('data', function(data)
print('client got: ' .. data)
end)
c:on('end', function()
c:destroy()
end)
end)

timer.setTimeout(1000, function()
child:kill(9)
end)

timer.setTimeout(1010, function()
process.exit(0)
end)

process:on('error', function(err)
assert(false)
p(err)
end)

0 comments on commit 4a8df64

Please sign in to comment.