Skip to content

Commit

Permalink
Change sythesised errno from EPROTO to EILSEQ
Browse files Browse the repository at this point in the history
EILSEQ is mandated by C unlike EPROTO (though EPROTO **is** in C++11).
Notably OpenBSD is missing EPROTO
  • Loading branch information
daurnimator committed Dec 16, 2016
1 parent a80b4e9 commit 7f862c2
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 117 deletions.
40 changes: 20 additions & 20 deletions http/h1_connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,20 @@ function connection_methods:read_request_line(timeout)
end
if line == nil then
if err == nil and self.socket:pending() > 0 then
self.socket:seterror("r", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
if preline then
local ok, errno2 = self.socket:unget(preline)
if not ok then
return nil, onerror(self.socket, "unget", errno2)
end
end
return nil, onerror(self.socket, "read_request_line", ce.EPROTO)
return nil, onerror(self.socket, "read_request_line", ce.EILSEQ)
end
return nil, err, errno
end
local method, path, httpversion = line:match("^(%w+) (%S+) HTTP/(1%.[01])\r\n$")
if not method then
self.socket:seterror("r", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
local ok, errno2 = self.socket:unget(line)
if not ok then
return nil, onerror(self.socket, "unget", errno2)
Expand All @@ -170,7 +170,7 @@ function connection_methods:read_request_line(timeout)
return nil, onerror(self.socket, "unget", errno2)
end
end
return nil, onerror(self.socket, "read_request_line", ce.EPROTO)
return nil, onerror(self.socket, "read_request_line", ce.EILSEQ)
end
httpversion = httpversion == "1.0" and 1.0 or 1.1 -- Avoid tonumber() due to locale issues
return method, path, httpversion
Expand All @@ -180,19 +180,19 @@ function connection_methods:read_status_line(timeout)
local line, err, errno = self.socket:xread("*L", timeout)
if line == nil then
if err == nil and self.socket:pending() > 0 then
self.socket:seterror("r", ce.EPROTO)
return nil, onerror(self.socket, "read_status_line", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
return nil, onerror(self.socket, "read_status_line", ce.EILSEQ)
end
return nil, err, errno
end
local httpversion, status_code, reason_phrase = line:match("^HTTP/(1%.[01]) (%d%d%d) (.*)\r\n$")
if not httpversion then
self.socket:seterror("r", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
local ok, errno2 = self.socket:unget(line)
if not ok then
return nil, onerror(self.socket, "unget", errno2)
end
return nil, onerror(self.socket, "read_status_line", ce.EPROTO)
return nil, onerror(self.socket, "read_status_line", ce.EILSEQ)
end
httpversion = httpversion == "1.0" and 1.0 or 1.1 -- Avoid tonumber() due to locale issues
return httpversion, status_code, reason_phrase
Expand All @@ -216,8 +216,8 @@ function connection_methods:read_header(timeout)
end
end
if pending_bytes > 0 then
self.socket:seterror("r", ce.EPROTO)
return nil, onerror(self.socket, "read_header", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
return nil, onerror(self.socket, "read_header", ce.EILSEQ)
end
end
return nil, err, errno
Expand All @@ -232,12 +232,12 @@ function connection_methods:read_header(timeout)
message before forwarding the message downstream.]]
local key, val = line:match("^([^%s:]+):[ \t]*(.-)[ \t]*$")
if not key then
self.socket:seterror("r", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
local ok, errno2 = self.socket:unget(line)
if not ok then
return nil, onerror(self.socket, "unget", errno2)
end
return nil, onerror(self.socket, "read_header", ce.EPROTO)
return nil, onerror(self.socket, "read_header", ce.EILSEQ)
end
return key, val
end
Expand All @@ -247,14 +247,14 @@ function connection_methods:read_headers_done(timeout)
if crlf == "\r\n" then
return true
elseif crlf ~= nil or (err == nil and self.socket:pending() > 0) then
self.socket:seterror("r", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
if crlf then
local ok, errno2 = self.socket:unget(crlf)
if not ok then
return nil, onerror(self.socket, "unget", errno2)
end
end
return nil, onerror(self.socket, "read_headers_done", ce.EPROTO)
return nil, onerror(self.socket, "read_headers_done", ce.EILSEQ)
else
return nil, err, errno
end
Expand All @@ -275,19 +275,19 @@ function connection_methods:read_body_chunk(timeout)
local chunk_header, err, errno = self.socket:xread("*L", timeout)
if chunk_header == nil then
if err == nil and self.socket:pending() > 0 then
self.socket:seterror("r", ce.EPROTO)
return nil, onerror(self.socket, "read_body_chunk", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
return nil, onerror(self.socket, "read_body_chunk", ce.EILSEQ)
end
return nil, err, errno
end
local chunk_size, chunk_ext = chunk_header:match("^(%x+) *(.-)\r\n")
if chunk_size == nil then
self.socket:seterror("r", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
local unget_ok1, unget_errno1 = self.socket:unget(chunk_header)
if not unget_ok1 then
return nil, onerror(self.socket, "unget", unget_errno1)
end
return nil, onerror(self.socket, "read_body_chunk", ce.EPROTO)
return nil, onerror(self.socket, "read_body_chunk", ce.EILSEQ)
elseif #chunk_size > 8 then
self.socket:seterror("r", ce.E2BIG)
return nil, onerror(self.socket, "read_body_chunk", ce.E2BIG)
Expand All @@ -312,7 +312,7 @@ function connection_methods:read_body_chunk(timeout)
local chunk_data = assert(self.socket:xread(chunk_size, "b", 0))
local crlf = assert(self.socket:xread(2, "b", 0))
if crlf ~= "\r\n" then
self.socket:seterror("r", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
local unget_ok3, unget_errno3 = self.socket:unget(crlf)
if not unget_ok3 then
return nil, onerror(self.socket, "unget", unget_errno3)
Expand All @@ -325,7 +325,7 @@ function connection_methods:read_body_chunk(timeout)
if not unget_ok1 then
return nil, onerror(self.socket, "unget", unget_errno1)
end
return nil, onerror(self.socket, "read_body_chunk", ce.EPROTO)
return nil, onerror(self.socket, "read_body_chunk", ce.EILSEQ)
end
-- Success!
return chunk_data, chunk_ext
Expand Down
2 changes: 1 addition & 1 deletion http/h1_stream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function stream_methods:shutdown()
if not self.body_write_type then
-- Can send an automatic error response
local error_headers
if self.connection:error("r") == ce.EPROTO then
if self.connection:error("r") == ce.EILSEQ then
error_headers = bad_request_headers
else
error_headers = server_error_headers
Expand Down
18 changes: 9 additions & 9 deletions http/h2_connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ end

local function handle_frame(self, typ, flag, streamid, payload, deadline)
if self.need_continuation and (typ ~= 0x9 or self.need_continuation.id ~= streamid) then
return nil, h2_error.errors.PROTOCOL_ERROR:new_traceback("CONTINUATION frame expected"), ce.EPROTO
return nil, h2_error.errors.PROTOCOL_ERROR:new_traceback("CONTINUATION frame expected"), ce.EILSEQ
end
local handler = h2_stream.frame_handlers[typ]
-- http2 spec section 4.1:
Expand All @@ -194,7 +194,7 @@ local function handle_frame(self, typ, flag, streamid, payload, deadline)
local stream = self.streams[streamid]
if stream == nil and (not self.recv_goaway_lowest or streamid < self.recv_goaway_lowest) then
if xor(streamid % 2 == 1, self.type == "client") then
return nil, h2_error.errors.PROTOCOL_ERROR:new_traceback("Streams initiated by a client MUST use odd-numbered stream identifiers; those initiated by the server MUST use even-numbered stream identifiers"), ce.EPROTO
return nil, h2_error.errors.PROTOCOL_ERROR:new_traceback("Streams initiated by a client MUST use odd-numbered stream identifiers; those initiated by the server MUST use even-numbered stream identifiers"), ce.EILSEQ
end
-- TODO: check MAX_CONCURRENT_STREAMS
stream = self:new_stream(streamid)
Expand Down Expand Up @@ -227,7 +227,7 @@ function connection_methods:step(timeout)
return nil, err, errno
end
if not ok then
return nil, h2_error.errors.PROTOCOL_ERROR:new_traceback("invalid connection preface. not an http2 client?"), ce.EPROTO
return nil, h2_error.errors.PROTOCOL_ERROR:new_traceback("invalid connection preface. not an http2 client?"), ce.EILSEQ
end
self.has_confirmed_preface = true
end
Expand All @@ -238,7 +238,7 @@ function connection_methods:step(timeout)
-- flag might be `nil` on EOF
ok, connection_error, errno = nil, flag, streamid
elseif not self.has_first_settings and typ ~= 0x4 then -- XXX: Should this be more strict? e.g. what if it's an ACK?
ok, connection_error, errno = false, h2_error.errors.PROTOCOL_ERROR:new_traceback("A SETTINGS frame MUST be the first frame sent in an HTTP/2 connection"), ce.EPROTO
ok, connection_error, errno = false, h2_error.errors.PROTOCOL_ERROR:new_traceback("A SETTINGS frame MUST be the first frame sent in an HTTP/2 connection"), ce.EILSEQ
else
ok, connection_error, errno = handle_frame(self, typ, flag, streamid, payload, deadline)
if ok then
Expand All @@ -258,7 +258,7 @@ function connection_methods:step(timeout)
self:write_goaway_frame(nil, code, message, deadline and deadline-monotime())
end
if errno == nil and h2_error.is(connection_error) and connection_error.code == h2_error.errors.PROTOCOL_ERROR.code then
errno = ce.EPROTO
errno = ce.EILSEQ
end
return nil, connection_error, errno
end
Expand Down Expand Up @@ -376,8 +376,8 @@ function connection_methods:read_http2_frame(timeout)
return nil, err, errno
elseif err == nil then
if self.socket:pending() > 0 then
self.socket:seterror("r", ce.EPROTO)
return nil, onerror(self.socket, "read_http2_frame", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
return nil, onerror(self.socket, "read_http2_frame", ce.EILSEQ)
end
return nil
else
Expand Down Expand Up @@ -407,8 +407,8 @@ function connection_methods:read_http2_frame(timeout)
return nil, onerror(self.socket, "unget", errno3, 2)
end
if err2 == nil then
self.socket:seterror("r", ce.EPROTO)
return nil, onerror(self.socket, "read_http2_frame", ce.EPROTO)
self.socket:seterror("r", ce.EILSEQ)
return nil, onerror(self.socket, "read_http2_frame", ce.EILSEQ)
end
return nil, err2, errno2
end
Expand Down
Loading

0 comments on commit 7f862c2

Please sign in to comment.