Extract function to listen on Unix socket

This commit is contained in:
Bryan Boreham committed 2016-02-01 10:11:46 +00:00
1 parent c2a869491f
commit 78f2d82984
3 files changed
+22 -11

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
package net
import (
"fmt"
"net"
"os"
)
func ListenUnixSocket(pathname string) (net.Listener, error) {
if err := os.Remove(pathname); err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("Error removing existing unix socket: %s", err)
}
listener, err := net.Listen("unix", pathname)
if err != nil {
return nil, fmt.Errorf("ListenUnixSocket failed: %s", err)
}
return listener, nil
}