55 "encoding/json"
66 "fmt"
77 "io"
8- "os"
98 "strings"
10- "time"
119
1210 "github.com/miketheprogrammer/go-thrust/commands"
1311 . "github.com/miketheprogrammer/go-thrust/common"
@@ -70,42 +68,28 @@ func GetCommunicationChannels() (*Out, *In) {
7068
7169func Reader (out * Out , in * In ) {
7270
73- r := bufio .NewReader (Stdout )
71+ reader := bufio .NewReader (Stdout )
7472 defer Stdin .Close ()
7573 for {
76- select {
77- case quit := <- in .Quit :
78- Log .Errorf ("Connection Reader Received a Quit message from somewhere ... Exiting Now" )
79- os .Exit (quit )
80- default :
81- //a := <-in.Quit
82- //fmt.Println(a)
83- line , err := r .ReadString (byte ('\n' ))
84- if err != nil {
85- fmt .Println (err )
86- panic (err )
87- }
88-
89- Log .Debug ("SOCKET::Line" , line )
90- if ! strings .Contains (line , SOCKET_BOUNDARY ) {
91- response := commands.CommandResponse {}
92- json .Unmarshal ([]byte (line ), & response )
93- //Log.Debug(response)
94- out .CommandResponses <- response
95- }
96-
74+ line , err := reader .ReadString (byte ('\n' ))
75+ if err != nil {
76+ fmt .Println (err )
77+ panic (err )
9778 }
98- time .Sleep (time .Microsecond * 100 )
9979
80+ Log .Debug ("SOCKET::Line" , line )
81+ if ! strings .Contains (line , SOCKET_BOUNDARY ) {
82+ response := commands.CommandResponse {}
83+ json .Unmarshal ([]byte (line ), & response )
84+ out .CommandResponses <- response
85+ }
10086 }
101-
10287}
10388
10489func Writer (out * Out , in * In ) {
10590 for {
10691 select {
10792 case response := <- in .CommandResponses :
108- Log .Info ("CommandResponse Marhshaling." )
10993 cmd , _ := json .Marshal (response )
11094 Log .Debug ("Writing RESPONSE" , string (cmd ), "\n " , SOCKET_BOUNDARY )
11195
@@ -126,7 +110,5 @@ func Writer(out *Out, in *In) {
126110 Stdin .Write ([]byte (SOCKET_BOUNDARY ))
127111 Stdin .Write ([]byte ("\n " ))
128112 }
129-
130- time .Sleep (time .Microsecond * 100 )
131113 }
132114}
0 commit comments