Skip to content

Commit e81ab5e

Browse files
committed
fakeFS support 'status' command
1 parent ebd86ac commit e81ab5e

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

test/fakeFS/fakeFsWorker.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ const (
3737
BufLen = 4096
3838
SerializePlain = 0
3939
SerializeJson = 1
40-
FSStatusReply = `UP %d years, %d days, %d hours, %d minutes, %d seconds, %d milliseconds, %d microseconds
40+
FSApiResponseHeader = `Content-Length: %d
41+
Content-Type: api/response`
42+
FSStatusReply = `UP %d years, %d days, %d hours, %d minutes, %d seconds, %d milliseconds, %d microseconds
4143
FreeSWITCH (Version 1.8.7 git 6047ebd 2019-07-02 20:06:09Z 64bit) is ready
4244
0 session(s) since startup
4345
0 session(s) - peak 0, last 5min 0
4446
0 session(s) per Sec out of max 30, peak 0, last 5min 0
4547
1000 session(s) max
4648
min idle cpu 0.00/99.73
47-
Current Stack Size/Max 240K/8192K`
49+
Current Stack Size/Max 240K/8192K\n\n`
4850
)
4951

5052
type Worker struct {
@@ -175,11 +177,19 @@ func (fs *Worker) processCommand(s string) {
175177
if args[0] == "status" {
176178
Y, M, D, H, m, sec := diff(time.Now(), fs.startTime)
177179
reply = fmt.Sprintf(FSStatusReply, Y, M, D, H, m, sec, 0)
180+
s := fmt.Sprintf(FSApiResponseHeader, len(reply)+1)
181+
if _, err := fs.conn.Write([]byte(s)); err != nil {
182+
fs.stop = true
183+
return
184+
}
185+
if _, err := fs.conn.Write([]byte(fmt.Sprintf("%s\n", reply))); err != nil {
186+
fs.stop = true
187+
return
188+
}
178189
} else {
179-
reply = FsErrCommandNotFound
180-
}
181-
if _, err := fs.conn.Write([]byte(reply)); err != nil {
182-
fs.stop = true
190+
if _, err := fs.conn.Write([]byte(FsErrCommandNotFound)); err != nil {
191+
fs.stop = true
192+
}
183193
}
184194
default:
185195
if _, err := fs.conn.Write([]byte(FsErrCommandNotFound)); err != nil {

0 commit comments

Comments
 (0)