~emersion/soju-dev

Add fileno:// listeners v1 PROPOSED

Simon Ser: 1
 Add fileno:// listeners

 2 files changed, 18 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/27230/mbox | git am -3
Learn more about email & git

[PATCH] Add fileno:// listeners Export this patch

This can be used for socket activation, e.g.

    soju -listen fileno://3
---

TODO: figure out TLS implications

 cmd/soju/main.go | 16 ++++++++++++++++
 doc/soju.1.scd   |  2 ++
 2 files changed, 18 insertions(+)

diff --git a/cmd/soju/main.go b/cmd/soju/main.go
index 9219fee1626e..d7c6a4517efe 100644
--- a/cmd/soju/main.go
+++ b/cmd/soju/main.go
@@ -13,6 +13,7 @@ import (
	"net/url"
	"os"
	"os/signal"
	"strconv"
	"strings"
	"sync/atomic"
	"syscall"
@@ -307,6 +308,21 @@ func main() {
					log.Fatalf("serving %q: %v", listen, err)
				}
			}()
		case "fileno":
			fd, err := strconv.Atoi(u.Host)
			if err != nil {
				log.Fatalf("failed to parse FD number: %v", err)
			}
			ln, err := net.FileListener(os.NewFile(uintptr(fd), fmt.Sprintf("/dev/fd/%v", fd)))
			if err != nil {
				log.Fatalf("failed to create listener on %q: %v", listen, err)
			}
			ln = proxyProtoListener(ln, srv)
			go func() {
				if err := srv.Serve(ln); err != nil {
					log.Printf("serving %q: %v", listen, err)
				}
			}()
		default:
			log.Fatalf("failed to listen on %q: unsupported scheme", listen)
		}
diff --git a/doc/soju.1.scd b/doc/soju.1.scd
index 93e07fbb7526..a23a28fe7d6c 100644
--- a/doc/soju.1.scd
+++ b/doc/soju.1.scd
@@ -98,6 +98,8 @@ The following directives are supported:
	  connections (default port: 80)
	- _ident://[host][:port]_ listens for plain-text ident connections (default
	  port: 113)
	- _fileno://[fd]_ accepts connections on an opened file descriptor socket.
	  This can be used for socket activation.
	- _http+prometheus://localhost:<port>_ listens for plain-text HTTP
	  connections and serves Prometheus metrics (host must be "localhost")
	- _http+pprof://localhost:<port>_ listens for plain-text HTTP connections
-- 
2.34.1