diff options
author | Wolfy-J <[email protected]> | 2018-06-05 16:56:12 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-05 16:56:12 +0300 |
commit | 3112f9b58c73773cea972fd79f04d33f8f7d7edd (patch) | |
tree | 334941e56becd1dde9fd1ce353e63d63775d772b /server_config.go | |
parent | 76ff8d1c95e087749d559ee5a4f8f0348feafffa (diff) |
Cs and refactoring
Diffstat (limited to 'server_config.go')
-rw-r--r-- | server_config.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/server_config.go b/server_config.go new file mode 100644 index 00000000..2816a70b --- /dev/null +++ b/server_config.go @@ -0,0 +1,47 @@ +package roadrunner + +import ( + "time" + "strings" + "net" + "errors" +) + +const ( + FactoryPipes = iota + FactorySocket +) + +type ServerConfig struct { + // Relay defines connection method and factory to be used to connect to workers: + // "pipes", "tcp://:6001", "unix://rr.sock" + // This config section must not change on re-configuration. + Relay string + + // FactoryTimeout defines for how long socket factory will be waiting for worker connection. For socket factory only. + // This config section must not change on re-configuration. + FactoryTimeout time.Duration + + // Pool defines worker pool configuration, number of workers, timeouts and etc. This config section might change + // while server is running. + Pool Config +} + +// buildFactory creates and connects new factory instance based on given parameters. +func (f *ServerConfig) buildFactory() (Factory, error) { + if f.Relay == "pipes" { + return NewPipeFactory(), nil + } + + dsn := strings.Split(f.Relay, "://") + if len(dsn) != 2 { + return nil, errors.New("invalid relay DSN (pipes, tcp://:6001, unix://rr.sock)") + } + + ln, err := net.Listen(dsn[0], dsn[1]) + if err != nil { + return nil, nil + } + + return NewSocketFactory(ln, time.Second*f.FactoryTimeout), nil +} |