summaryrefslogtreecommitdiff
path: root/pipe_factory.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2017-12-26 19:14:53 +0300
committerWolfy-J <[email protected]>2017-12-26 19:14:53 +0300
commite229d83dea4bbe9d0cfe6569c8fbe239690aafb9 (patch)
tree2d4887ffdb167d660b705415f0617458490d0b9f /pipe_factory.go
init
Diffstat (limited to 'pipe_factory.go')
-rw-r--r--pipe_factory.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/pipe_factory.go b/pipe_factory.go
new file mode 100644
index 00000000..ce32dacc
--- /dev/null
+++ b/pipe_factory.go
@@ -0,0 +1,46 @@
+package roadrunner
+
+import (
+ "github.com/spiral/goridge"
+ "os/exec"
+)
+
+// PipeFactory connects to workers using standard streams (STDIN, STDOUT pipes).
+type PipeFactory struct {
+}
+
+// NewPipeFactory returns new factory instance and starts listening
+func NewPipeFactory() *PipeFactory {
+ return &PipeFactory{}
+}
+
+// NewWorker creates worker and connects it to appropriate relay or returns error
+func (f *PipeFactory) NewWorker(cmd *exec.Cmd) (w *Worker, err error) {
+ w, err = NewWorker(cmd)
+ if err != nil {
+ return nil, err
+ }
+
+ in, err := cmd.StdoutPipe()
+ if err != nil {
+ return nil, err
+ }
+
+ out, err := cmd.StdinPipe()
+ if err != nil {
+ return nil, err
+ }
+
+ if err := w.Start(); err != nil {
+ return nil, err
+ }
+
+ w.attach(goridge.NewPipeRelay(in, out))
+
+ return w, nil
+}
+
+// Close closes all open factory descriptors.
+func (f *PipeFactory) Close() error {
+ return nil
+}