summaryrefslogtreecommitdiff
path: root/protocol.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-17 02:34:44 +0300
committerValery Piashchynski <[email protected]>2020-12-17 02:34:44 +0300
commit9d5fe4f6a98b30fd73be8259f84fa595ac994a71 (patch)
treee49c46b03d8facc73e96f1b6247d83367cc65398 /protocol.go
parent1033c25b6bfc752d6059e446510f651e22cbf49b (diff)
huge refactor
Diffstat (limited to 'protocol.go')
-rwxr-xr-xprotocol.go93
1 files changed, 0 insertions, 93 deletions
diff --git a/protocol.go b/protocol.go
deleted file mode 100755
index ee2d8245..00000000
--- a/protocol.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package roadrunner
-
-import (
- "os"
-
- j "github.com/json-iterator/go"
- "github.com/spiral/errors"
- "github.com/spiral/goridge/v3"
-)
-
-var json = j.ConfigCompatibleWithStandardLibrary
-
-type stopCommand struct {
- Stop bool `json:"stop"`
-}
-
-type pidCommand struct {
- Pid int `json:"pid"`
-}
-
-func sendControl(rl goridge.Relay, v interface{}) error {
- const op = errors.Op("send control frame")
- frame := goridge.NewFrame()
- frame.WriteVersion(goridge.VERSION_1)
- frame.WriteFlags(goridge.CONTROL)
-
- if data, ok := v.([]byte); ok {
- // check if payload no more that 4Gb
- if uint32(len(data)) > ^uint32(0) {
- return errors.E(op, errors.Str("payload is more that 4gb"))
- }
-
- frame.WritePayloadLen(uint32(len(data)))
- frame.WritePayload(data)
- frame.WriteCRC()
-
- err := rl.Send(frame)
- if err != nil {
- return errors.E(op, err)
- }
- return nil
- }
-
- data, err := json.Marshal(v)
- if err != nil {
- return errors.E(op, errors.Errorf("invalid payload: %s", err))
- }
-
- frame.WritePayloadLen(uint32(len(data)))
- frame.WritePayload(data)
- frame.WriteCRC()
-
- err = rl.Send(frame)
- if err != nil {
- return errors.E(op, err)
- }
-
- return nil
-}
-
-func fetchPID(rl goridge.Relay) (int64, error) {
- const op = errors.Op("fetchPID")
- err := sendControl(rl, pidCommand{Pid: os.Getpid()})
- if err != nil {
- return 0, errors.E(op, err)
- }
-
- frameR := goridge.NewFrame()
- err = rl.Receive(frameR)
- if !frameR.VerifyCRC() {
- return 0, errors.E(op, errors.Str("CRC mismatch"))
- }
- if err != nil {
- return 0, errors.E(op, err)
- }
- if frameR == nil {
- return 0, errors.E(op, errors.Str("nil frame received"))
- }
-
- flags := frameR.ReadFlags()
-
- if flags&(byte(goridge.CONTROL)) == 0 {
- return 0, errors.E(op, errors.Str("unexpected response, header is missing, no CONTROL flag"))
- }
-
- link := &pidCommand{}
- err = json.Unmarshal(frameR.Payload(), link)
- if err != nil {
- return 0, errors.E(op, err)
- }
-
- return int64(link.Pid), nil
-}