-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathstream.go
45 lines (36 loc) · 995 Bytes
/
stream.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package goSam
import (
"fmt"
)
// StreamConnect asks SAM for a TCP-Like connection to dest, has to be called on a new Client
func (c *Client) StreamConnect(id int32, dest string) error {
r, err := c.sendCmd("STREAM CONNECT ID=%d DESTINATION=%s\n", id, dest)
if err != nil {
return err
}
// TODO: move check into sendCmd()
if r.Topic != "STREAM" || r.Type != "STATUS" {
return fmt.Errorf("Unknown Reply: %+v\n", r)
}
result := r.Pairs["RESULT"]
if result != "OK" {
return ReplyError{result, r}
}
return nil
}
// StreamAccept asks SAM to accept a TCP-Like connection
func (c *Client) StreamAccept(id int32) (*Reply, error) {
r, err := c.sendCmd("STREAM ACCEPT ID=%d SILENT=false\n", id)
if err != nil {
return nil, err
}
// TODO: move check into sendCmd()
if r.Topic != "STREAM" || r.Type != "STATUS" {
return nil, fmt.Errorf("Unknown Reply: %+v\n", r)
}
result := r.Pairs["RESULT"]
if result != "OK" {
return nil, ReplyError{result, r}
}
return r, nil
}