moonbridge

diff moonbridge_http.lua @ 88:fca51922b708

Extended I/O library; Integrated new I/O library into moonbridge.c and moonbridge_http.lua
author jbe
date Tue Apr 07 02:15:17 2015 +0200 (2015-04-07)
parents 0ec070d6f5d9
children 7014436d88ea
line diff
     1.1 --- a/moonbridge_http.lua	Tue Apr 07 01:17:55 2015 +0200
     1.2 +++ b/moonbridge_http.lua	Tue Apr 07 02:15:17 2015 +0200
     1.3 @@ -238,7 +238,7 @@
     1.4          io.stderr:write(errmsg, "\n")
     1.5          if not socket_closed then
     1.6            socket_closed = true
     1.7 -          socket:cancel()
     1.8 +          socket:reset()
     1.9          end
    1.10          error("Could not send data to client: " .. errmsg)
    1.11        end
    1.12 @@ -270,7 +270,7 @@
    1.13          else
    1.14            if not socket_closed then
    1.15              socket_closed = true
    1.16 -            socket:cancel()
    1.17 +            socket:reset()
    1.18            end
    1.19          end
    1.20          if throw_error then
    1.21 @@ -309,10 +309,10 @@
    1.22        local function finish_response()
    1.23          if connection_close_responded then
    1.24            -- close output stream:
    1.25 -          assert_output(socket.output:close())
    1.26 +          assert_output(socket:finish())
    1.27            -- wait for EOF of peer to avoid immediate TCP RST condition:
    1.28            timeout(2, function()
    1.29 -            while socket.input:read(input_chunk_size) do end
    1.30 +            socket:drain()
    1.31            end)
    1.32            -- fully close socket:
    1.33            socket_closed = true  -- avoid double close on error
    1.34 @@ -832,7 +832,7 @@
    1.35            end
    1.36            if request.headers_flags["Transfer-Encoding"]["chunked"] then
    1.37              while true do
    1.38 -              local line = socket:readuntil("\n", 32 + remaining_body_size_limit)
    1.39 +              local line = socket:read(32 + remaining_body_size_limit, "\n")
    1.40                if not line then
    1.41                  request_error(true, "400 Bad Request", "Unexpected EOF while reading next chunk of request body")
    1.42                end
    1.43 @@ -853,13 +853,13 @@
    1.44                end
    1.45                if len == 0 then break end
    1.46                read_body_bytes(len, callback)
    1.47 -              local term = socket:readuntil("\n", 2)
    1.48 +              local term = socket:read(2, "\n")
    1.49                if term ~= "\r\n" and term ~= "\n" then
    1.50                  request_error(true, "400 Bad Request", "Encoding error while reading chunk of request body")
    1.51                end
    1.52              end
    1.53              while true do
    1.54 -              local line = socket:readuntil("\n", 2 + remaining_body_size_limit)
    1.55 +              local line = socket:read(2 + remaining_body_size_limit, "\n")
    1.56                if line == "\r\n" or line == "\n" then break end
    1.57                remaining_body_size_limit = remaining_body_size_limit - #line
    1.58                if remaining_body_size_limit < 0 then
    1.59 @@ -894,7 +894,7 @@
    1.60          end
    1.61        })
    1.62        -- read and parse request line:
    1.63 -      local line = socket:readuntil("\n", remaining_header_size_limit)
    1.64 +      local line = socket:read(remaining_header_size_limit, "\n")
    1.65        if not line then return survive end
    1.66        remaining_header_size_limit = remaining_header_size_limit - #line
    1.67        if remaining_header_size_limit == 0 then
    1.68 @@ -910,7 +910,7 @@
    1.69        end
    1.70        -- read and parse headers:
    1.71        while true do
    1.72 -        local line = socket:readuntil("\n", remaining_header_size_limit);
    1.73 +        local line = socket:read(remaining_header_size_limit, "\n");
    1.74          remaining_header_size_limit = remaining_header_size_limit - #line
    1.75          if not line then
    1.76            return request_error(false, "400 Bad Request")

Impressum / About Us