summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-26 01:16:35 +0300
committerValery Piashchynski <[email protected]>2020-12-26 01:16:35 +0300
commit6fe39bc935ceb847b21c289adaf700035454de6b (patch)
tree799074fdd110ce754ed495957032e53f44bc136c
parent6cbc67e9bfce7fcb5da2f402adeb9e83cab8f717 (diff)
Fix builds on windowsv2.0.0-beta3
-rw-r--r--plugins/rpc/config.go4
-rw-r--r--plugins/rpc/util.go57
2 files changed, 3 insertions, 58 deletions
diff --git a/plugins/rpc/config.go b/plugins/rpc/config.go
index 7f3474d7..719fd5e3 100644
--- a/plugins/rpc/config.go
+++ b/plugins/rpc/config.go
@@ -4,6 +4,8 @@ import (
"errors"
"net"
"strings"
+
+ "github.com/spiral/roadrunner/v2/util"
)
// Config defines RPC service config.
@@ -33,7 +35,7 @@ func (c *Config) Valid() error {
// Listener creates new rpc socket Listener.
func (c *Config) Listener() (net.Listener, error) {
- return CreateListener(c.Listen)
+ return util.CreateListener(c.Listen)
}
// Dialer creates rpc socket Dialer.
diff --git a/plugins/rpc/util.go b/plugins/rpc/util.go
deleted file mode 100644
index 29a475a4..00000000
--- a/plugins/rpc/util.go
+++ /dev/null
@@ -1,57 +0,0 @@
-package rpc
-
-import (
- "errors"
- "fmt"
- "net"
- "os"
- "strings"
- "syscall"
-
- "github.com/valyala/tcplisten"
-)
-
-// CreateListener crates socket listener based on DSN definition.
-func CreateListener(address string) (net.Listener, error) {
- dsn := strings.Split(address, "://")
- if len(dsn) != 2 {
- return nil, errors.New("invalid DSN (tcp://:6001, unix://file.sock)")
- }
-
- if dsn[0] != "unix" && dsn[0] != "tcp" {
- return nil, errors.New("invalid Protocol (tcp://:6001, unix://file.sock)")
- }
-
- // create unix listener
- if dsn[0] == "unix" {
- // check if the file exist
- if fileExists(dsn[1]) {
- err := syscall.Unlink(dsn[1])
- if err != nil {
- return nil, fmt.Errorf("error during the unlink syscall: error %v", err)
- }
- }
- return net.Listen(dsn[0], dsn[1])
- }
-
- // configure and create tcp4 listener
- cfg := tcplisten.Config{
- ReusePort: true,
- DeferAccept: true,
- FastOpen: true,
- Backlog: 0,
- }
-
- // only tcp4 is currently supported
- return cfg.NewListener("tcp4", dsn[1])
-}
-
-// fileExists checks if a file exists and is not a directory before we
-// try using it to prevent further errors.
-func fileExists(filename string) bool {
- info, err := os.Stat(filename)
- if os.IsNotExist(err) {
- return false
- }
- return !info.IsDir()
-}