aboutsummaryrefslogtreecommitdiff
path: root/test/test_socket_error.lua
blob: 9bd0bc704601bd5911ca6f425b93db99de6a2735 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local socket = require "socket"

local host, port = "127.0.0.1", "5462"

assert(socket.bind(host, port)):close()

local sock = socket.tcp()
sock:settimeout(0)

local ok, err = sock:connect(host, port)
assert(not ok)
assert('timeout' == err)

for i = 1, 10 do
  -- select pass even if socket has error
  local _, rec, err = socket.select(nil, {sock}, 1)
  assert('timeout' == err)
  assert(not next(rec))
  err = sock:getoption("error") -- i get 'connection refused' on WinXP
  if err then
    print("Passed! Error is '" .. err .. "'.")
    os.exit(0)
  end
end

print("Fail! No error detected!")
os.exit(1)