@@ -37,9 +37,18 @@ const (
37
37
BufLen = 4096
38
38
SerializePlain = 0
39
39
SerializeJson = 1
40
+ FSStatusReply = `UP %d years, %d days, %d hours, %d minutes, %d seconds, %d milliseconds, %d microseconds
41
+ FreeSWITCH (Version 1.8.7 git 6047ebd 2019-07-02 20:06:09Z 64bit) is ready
42
+ 0 session(s) since startup
43
+ 0 session(s) - peak 0, last 5min 0
44
+ 0 session(s) per Sec out of max 30, peak 0, last 5min 0
45
+ 1000 session(s) max
46
+ min idle cpu 0.00/99.73
47
+ Current Stack Size/Max 240K/8192K`
40
48
)
41
49
42
50
type Worker struct {
51
+ startTime time.Time
43
52
stop bool
44
53
conn net.Conn
45
54
pass string
@@ -60,6 +69,7 @@ func NewWorker(conn net.Conn, pass, uuid string, events chan *Event) *Worker {
60
69
resUuid = tryUuid
61
70
}
62
71
return & Worker {
72
+ startTime : time .Now (),
63
73
conn : conn ,
64
74
pass : pass ,
65
75
events : make ([]string , 0 ),
@@ -160,6 +170,12 @@ func (fs *Worker) processCommand(s string) {
160
170
fs .customEvents = append (fs .customEvents , events [i ])
161
171
}
162
172
}
173
+ case "status" :
174
+ Y , M , D , H , m , sec := diff (time .Now (), fs .startTime )
175
+ status := fmt .Sprintf (FSStatusReply , Y , M , D , H , m , sec , 0 )
176
+ if _ , err := fs .conn .Write ([]byte (status )); err != nil {
177
+ fs .stop = true
178
+ }
163
179
default :
164
180
if _ , err := fs .conn .Write ([]byte (FsErrCommandNotFound )); err != nil {
165
181
fs .stop = true
@@ -220,3 +236,50 @@ func (fs *Worker) sendMessage(buf string) error {
220
236
}
221
237
return nil
222
238
}
239
+
240
+ func diff (a , b time.Time ) (year , month , day , hour , min , sec int ) {
241
+ if a .Location () != b .Location () {
242
+ b = b .In (a .Location ())
243
+ }
244
+ if a .After (b ) {
245
+ a , b = b , a
246
+ }
247
+ y1 , M1 , d1 := a .Date ()
248
+ y2 , M2 , d2 := b .Date ()
249
+
250
+ h1 , m1 , s1 := a .Clock ()
251
+ h2 , m2 , s2 := b .Clock ()
252
+
253
+ year = int (y2 - y1 )
254
+ month = int (M2 - M1 )
255
+ day = int (d2 - d1 )
256
+ hour = int (h2 - h1 )
257
+ min = int (m2 - m1 )
258
+ sec = int (s2 - s1 )
259
+
260
+ // Normalize negative values
261
+ if sec < 0 {
262
+ sec += 60
263
+ min --
264
+ }
265
+ if min < 0 {
266
+ min += 60
267
+ hour --
268
+ }
269
+ if hour < 0 {
270
+ hour += 24
271
+ day --
272
+ }
273
+ if day < 0 {
274
+ // days in month:
275
+ t := time .Date (y1 , M1 , 32 , 0 , 0 , 0 , 0 , time .UTC )
276
+ day += 32 - t .Day ()
277
+ month --
278
+ }
279
+ if month < 0 {
280
+ month += 12
281
+ year --
282
+ }
283
+
284
+ return
285
+ }
0 commit comments