-
Notifications
You must be signed in to change notification settings - Fork 10
/
reader.go
51 lines (49 loc) · 1.2 KB
/
reader.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
46
47
48
49
50
51
package ucp
import (
"bufio"
"io"
"sync"
)
// readLoop reads incoming messages from the SMSC using the underlying bufio.Reader
func readLoop(reader *bufio.Reader, wg *sync.WaitGroup, closeChan chan struct{},
submitSmRespCh, deliverNotifCh, deliverMsgCh chan []string, logger Logger) {
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case <-closeChan:
logger.Printf("readLoop terminated\n")
return
default:
readData, err := reader.ReadString(etx)
if err != nil {
if err == io.EOF {
logger.Printf("read EOF\n")
return
}
continue
}
opType, fields, err := parseResp(readData)
if err != nil {
continue
}
switch opType {
case opSubmitShortMessage:
logger.Printf("opSubmitShortMessage: %q\n", fields)
submitSmRespCh <- fields
case opDeliveryNotification:
logger.Printf("opDeliveryNotification: %q\n", fields)
deliverNotifCh <- fields
case opDeliveryShortMessage:
logger.Printf("opDeliveryShortMessage: %q\n", fields)
deliverMsgCh <- fields
case opAlert:
logger.Printf("opAlert: %q\n", fields)
default:
logger.Printf("unknown operationType: %q\n", fields)
}
}
}
}()
}