Sitelet https://github.com/openresty/openresty/pull/400
Skip to content

Add abstract socket support on Linux - #400

Open
bjne wants to merge 2 commits into
openresty:masterfrom
bjne:linux-abstract-socket-support
Open

bjne wants to merge 2 commits into
openresty:masterfrom
bjne:linux-abstract-socket-support

Conversation

@bjne

@bjne bjne commented Aug 31, 2018

Copy link
Copy Markdown

This adds abstract socket support for Linux, making it possible
to do for example:

server {
listen unix:@abstract-socket;

location / {
    content_by_lua_block {
        ngx.say("hello from @abstract-socket")
    }
}

location /abstract-socket {
    content_by_lua_block {
        local sock = ngx.socket.tcp()

        local ok, err = sock:connect("unix:@abstract-socket")
        if not ok then
            return ngx.say("could not connect: ", err)
        end

        ok, err = sock:send("GET /\r\n");
        if not ok then
            return ngx.say("failed to send data on socket")
        end

        ngx.say(sock:receive())
    }
}

}

echo -en "GET /abstract-socket\r\n" |
socat abstract-connect:abstract-socket -

I hereby granted the copyright of the changes in this pull request
to the authors of this openresty project.

@Miniwoffer

Copy link
Copy Markdown

Runs fine on a docker instance using the
travisci/ci-garnet:packer-1515445631-7dfb2e1
instance.

OUTPUT

vis@cf2b1bee4a1a:~/openresty/openresty$ prove -I. -r t/
t/001-resolver.t .. 1/55 nginx: [emerg] IPv6 resolver address is too long: "2001:4860:4860::8888:2001:4860:4860::8888:2001" in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39
nginx: [emerg] unable to parse local resolver in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39
WARNING: TEST 10: IPv6 with malformed and long address - 2019/08/02 08:51:39 [emerg] 25941#0: IPv6 resolver address is too long: \"2001:4860:4860::8888:2001:4860:4860::8888:2001\" in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39 at /usr/local/share/perl/5.18.2/Test/Nginx/Socket.pm line 1247.
WARNING: TEST 10: IPv6 with malformed and long address - 2019/08/02 08:51:39 [emerg] 25941#0: unable to parse local resolver in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39 at /usr/local/share/perl/5.18.2/Test/Nginx/Socket.pm line 1247.
nginx: [emerg] no name servers defined in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39
WARNING: TEST 2: malformed file - 2019/08/02 08:51:39 [emerg] 25953#0: no name servers defined in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39 at /usr/local/share/perl/5.18.2/Test/Nginx/Socket.pm line 1247.
t/001-resolver.t .. 39/55 nginx: [emerg] no name servers defined in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39
WARNING: TEST 3: disabled - 2019/08/02 08:51:42 [emerg] 26043#0: no name servers defined in /home/travis/openresty/openresty/t/servroot/conf/nginx.conf:39 at /usr/local/share/perl/5.18.2/Test/Nginx/Socket.pm line 1247.
t/001-resolver.t .. ok
t/sanity.t ........ 270/273 wrote t/sanity.t_
t/sanity.t ........ ok
All tests successful.
Files=2, Tests=328, 17 wallclock secs ( 0.08 usr  0.00 sys +  4.60 cusr  8.77 csys = 13.45 CPU)
Result: PASS

bjne and others added 2 commits January 20, 2022 23:39
This adds abstract socket support for Linux, making it possible
to do for example:

server {
    listen unix:@abstract-socket;

    location / {
        content_by_lua_block {
            ngx.say("hello from @abstract-socket")
        }
    }

    location /abstract-socket {
        content_by_lua_block {
            local sock = ngx.socket.tcp()

            local ok, err = sock:connect("unix:@abstract-socket")
            if not ok then
                return ngx.say("could not connect: ", err)
            end

            ok, err = sock:send("GET /\r\n");
            if not ok then
                return ngx.say("failed to send data on socket")
            end

            ngx.say(sock:receive())
        }
    }
}

echo -en "GET /abstract-socket\r\n" | \
    socat abstract-connect:abstract-socket -
 - Fixed a length bug that would ocure when the socket name was not zero
terminated.
@xiaocang
xiaocang force-pushed the linux-abstract-socket-support branch from ebd6084 to 568889b Compare January 20, 2022 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants