Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AF_UNIX socket connections #416

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions autoload/fireplace/transport.vim
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,20 @@ augroup fireplace_transport
augroup END

function! fireplace#transport#connect(arg) abort
let url = substitute(a:arg, '#.*', '', '')
if url =~# '^\d\+$'
let url = 'nrepl://localhost:' . url
elseif url =~# '^[^:/@]\+\(:\d\+\)\=$'
let url = 'nrepl://' . url
elseif url !~# '^\a\+://'
throw "Fireplace: invalid connection string " . string(a:arg)
if a:arg =~# '^nrepl+unix:.*'
let url = a:arg
else
let url = substitute(a:arg, '#.*', '', '')
if url =~# '^\d\+$'
let url = 'nrepl://localhost:' . url
elseif url =~# '^[^:/@]\+\(:\d\+\)\=$'
let url = 'nrepl://' . url
elseif url !~# '^\a\+://'
throw "Fireplace: invalid connection string " . string(a:arg)
endif
let url = substitute(url, '^\a\+://[^/]*\zs$', '/', '')
let url = substitute(url, '^nrepl://[^/:]*\zs/', ':7888/', '')
endif
let url = substitute(url, '^\a\+://[^/]*\zs$', '/', '')
let url = substitute(url, '^nrepl://[^/:]*\zs/', ':7888/', '')
if has_key(s:urls, url)
return s:urls[url].transport
endif
Expand Down
27 changes: 18 additions & 9 deletions pythonx/fireplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,22 @@ def quickfix(t, e, tb):
return {'title': str(e), 'items': items}

class Connection:
def __init__(self, host, port, keepalive_file=None):
def __init__(self, host, port, keepalive_file=None, socket_type=socket.AF_INET, socket_path=None):
self.keepalive_file = keepalive_file
self.connected = False
self.host = host
self.port = int(port)
self.port = int(port) if port else None
self.socket_path = socket_path
self.socket_type = socket_type

def socket(self):
if not self.connected:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = socket.socket(self.socket_type, socket.SOCK_STREAM)
s.settimeout(8)
s.connect((self.host, self.port))
if self.socket_type == socket.AF_UNIX:
s.connect(self.socket_path)
else:
s.connect((self.host, self.port))
s.setblocking(1)
self._socket = s
self.connected = True
Expand Down Expand Up @@ -178,11 +183,15 @@ def tunnel(self):

def main(host = None, port = None, *args):
try:
match = re.search('//([^:/@]+)(?::(\d+))?', host)
if match:
host = match.groups()[0]
port = match.groups()[1]
conn = Connection(host, int(port or 7888))
if re.fullmatch('nrepl\+unix:.*', host):
socket_path = re.sub('^nrepl\+unix:', '', host)
conn = Connection(None, None, socket_path=socket_path, socket_type=socket.AF_UNIX)
else:
match = re.search('//([^:/@]+)(?::(\d+))?', host)
if match:
host = match.groups()[0]
port = match.groups()[1]
conn = Connection(host, int(port or 7888))
try:
conn.tunnel()
finally:
Expand Down