luvit/luvit

Unix domain sockets

Trendyne opened this issue · 2 comments

I'm curious if there's any interest in supporting unix domain sockets as well as network sockets. It could look something like

http.createServer(function(req, res)
...
end):listen("/tmp/luvit.socket")

There's an advantage in being easier to use with a server like nginx to forward requests, is less likely to conflict, can't be accessed on a network, which has fewer security problems and quirks, and is more descriptive and memorable than a random TCP socket number. On unix-like systems TCP/domain sockets just end up as file descriptors with all the standard system calls, so theoretically it should be really easy to implement, and it's standard lib stuff so no bloat

This is supported by Node and Express already in this exact same way

Starts a UNIX socket and listens for connections on the given path. This method is identical to Node’s http.Server.listen().

var express = require('express')
var app = express()
app.listen('/tmp/sock')

Noting that this is already a thing, though doesn't cover http
https://github.com/luvit/luv/blob/master/docs.md#uv_pipe_t--pipe-handle

Supporting arbitrary file descriptors and/or lua file handles along with it could also be an idea. What if I want to pipe connections into the program from stdin? program | luvit server.lua