@@ -13,6 +13,7 @@ import (
13
13
"net"
14
14
"strconv"
15
15
"strings"
16
+ "sync"
16
17
"time"
17
18
)
18
19
@@ -21,6 +22,7 @@ type SocketConnection struct {
21
22
net.Conn
22
23
err chan error
23
24
m chan * Message
25
+ mtx sync.Mutex
24
26
}
25
27
26
28
// Dial - Will establish timedout dial against specified address. In this case, it will be freeswitch server
@@ -34,6 +36,9 @@ func (c *SocketConnection) Send(cmd string) error {
34
36
if strings .Contains (cmd , "\r \n " ) {
35
37
fmt .Errorf (EInvalidCommandProvided , cmd )
36
38
}
39
+ // lock mutex
40
+ c .mtx .Lock ()
41
+ defer c .mtx .Unlock ()
37
42
38
43
fmt .Fprintf (c , "%s\r \n \r \n " , cmd )
39
44
@@ -52,6 +57,25 @@ func (c *SocketConnection) SendMany(cmds []string) error {
52
57
return nil
53
58
}
54
59
60
+ // SendEvent - Will loop against passed event headers
61
+ func (c * SocketConnection ) SendEvent (eventHeaders []string ) error {
62
+ if len (eventHeaders ) <= 0 {
63
+ fmt .Errorf (ECouldNotSendEvent , len (eventHeaders ))
64
+ return nil
65
+ }
66
+ // lock mutex to prevent event headers from conflicting
67
+ c .mtx .Lock ()
68
+ defer c .mtx .Unlock ()
69
+
70
+ fmt .Fprint (c , "sendevent " )
71
+ for _ , eventHeader := range eventHeaders {
72
+ fmt .Fprintf (c , "%s\r \n " , eventHeader )
73
+ }
74
+ fmt .Fprint (c , "\r \n " )
75
+
76
+ return nil
77
+ }
78
+
55
79
// Execute - Helper fuck to execute commands with its args and sync/async mode
56
80
func (c * SocketConnection ) Execute (command , args string , sync bool ) (m * Message , err error ) {
57
81
return c .SendMsg (map [string ]string {
0 commit comments