2022-09-17 20:07:00 +01:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
|
|
|
"net/url"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Arceliar/phony"
|
|
|
|
)
|
|
|
|
|
|
|
|
type linkUNIX struct {
|
|
|
|
phony.Inbox
|
|
|
|
*links
|
|
|
|
dialer *net.Dialer
|
|
|
|
listener *net.ListenConfig
|
|
|
|
_listeners map[*Listener]context.CancelFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *links) newLinkUNIX() *linkUNIX {
|
|
|
|
lt := &linkUNIX{
|
|
|
|
links: l,
|
|
|
|
dialer: &net.Dialer{
|
|
|
|
Timeout: time.Second * 5,
|
|
|
|
KeepAlive: -1,
|
|
|
|
},
|
|
|
|
listener: &net.ListenConfig{
|
|
|
|
KeepAlive: -1,
|
|
|
|
},
|
|
|
|
_listeners: map[*Listener]context.CancelFunc{},
|
|
|
|
}
|
|
|
|
return lt
|
|
|
|
}
|
|
|
|
|
2023-08-12 18:12:58 +01:00
|
|
|
func (l *linkUNIX) dial(ctx context.Context, url *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
|
2022-09-17 20:07:00 +01:00
|
|
|
addr, err := net.ResolveUnixAddr("unix", url.Path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-08-12 18:12:58 +01:00
|
|
|
return l.dialer.DialContext(ctx, "unix", addr.String())
|
2022-09-17 20:07:00 +01:00
|
|
|
}
|
|
|
|
|
2023-04-06 21:45:49 +01:00
|
|
|
func (l *linkUNIX) listen(ctx context.Context, url *url.URL, _ string) (net.Listener, error) {
|
|
|
|
return l.listener.Listen(ctx, "unix", url.Path)
|
2022-09-17 20:07:00 +01:00
|
|
|
}
|