remove debug + clean main
This commit is contained in:
parent
a887bcd0b9
commit
0ed39dec0e
|
@ -19,21 +19,22 @@ func main(){
|
|||
/* (2) Bind default controller */
|
||||
serv.BindDefault(func(client *controller.ClientInterface, receiver <-chan message.T, sender chan<- message.T, closer <-chan func()){
|
||||
|
||||
fmt.Printf("[default] connected\n")
|
||||
for {
|
||||
|
||||
select {
|
||||
case msg := <- receiver:
|
||||
fmt.Printf("[default] received '%s'\n", msg.Data)
|
||||
sender <- msg
|
||||
case closeFunc := <- closer:
|
||||
fmt.Printf("[default] client with protocol '%s' exited\n", client.Protocol)
|
||||
closeFunc()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("[default] unexpectedly closed\n")
|
||||
// if receive message -> send it back
|
||||
case msg := <- receiver:
|
||||
sender <- msg
|
||||
|
||||
// if received closer, close after doing stuff
|
||||
case closeCallback := <- closer:
|
||||
closeCallback()
|
||||
break
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
@ -46,6 +47,7 @@ func main(){
|
|||
select {
|
||||
case msg := <- receiver:
|
||||
fmt.Printf("[uri] received '%s'\n", msg.Data)
|
||||
sender <- msg
|
||||
case closeFunc := <- closer:
|
||||
fmt.Printf("[uri] client with protocol '%s' exited\n", client.Protocol)
|
||||
closeFunc()
|
||||
|
|
|
@ -94,8 +94,6 @@ func Create(s net.Conn, ctl controller.Set, unregister chan <-*T) (*T, error){
|
|||
// reader reads and parses messages from the buffer
|
||||
func (c *T) reader(unregister chan <-*T){
|
||||
|
||||
fmt.Printf("[reader] start\n");
|
||||
|
||||
for {
|
||||
|
||||
/* (1) Parse message */
|
||||
|
@ -104,21 +102,20 @@ func (c *T) reader(unregister chan <-*T){
|
|||
fmt.Printf(" [reader] %s\n", err)
|
||||
break
|
||||
}
|
||||
fmt.Printf(" [reader] ok\n");
|
||||
|
||||
/* (2) If CLOSE */
|
||||
if msg.Type == message.CLOSE {
|
||||
|
||||
fmt.Printf(" [reader] CLOSE\n")
|
||||
// fmt.Printf(" [reader] CLOSE\n")
|
||||
break
|
||||
|
||||
} else if msg.Type == message.PING {
|
||||
|
||||
fmt.Printf(" [reader] PING\n")
|
||||
// fmt.Printf(" [reader] PING\n")
|
||||
msg.Final = true
|
||||
msg.Type = message.PONG
|
||||
c.Ch.Send <- *msg
|
||||
fmt.Printf(" [reader] sent PONG back\n")
|
||||
// fmt.Printf(" [reader] sent PONG back\n")
|
||||
continue
|
||||
|
||||
}
|
||||
|
@ -128,8 +125,6 @@ func (c *T) reader(unregister chan <-*T){
|
|||
|
||||
}
|
||||
|
||||
fmt.Printf("[reader] end\n")
|
||||
|
||||
// return closing callback
|
||||
c.Ch.Close <- func(){
|
||||
unregister <- c
|
||||
|
@ -143,8 +138,6 @@ func (c *T) reader(unregister chan <-*T){
|
|||
// and is triggered by client.ch.send channel
|
||||
func (c *T) writer(unregister chan <-*T){
|
||||
|
||||
fmt.Printf("[writer] start\n");
|
||||
|
||||
for message := range c.Ch.Send {
|
||||
|
||||
c.IO.wriMu.Lock()
|
||||
|
@ -158,13 +151,8 @@ func (c *T) writer(unregister chan <-*T){
|
|||
break;
|
||||
}
|
||||
|
||||
fmt.Printf(" [writer] ok\n")
|
||||
|
||||
}
|
||||
|
||||
|
||||
fmt.Printf("[writer] end\n")
|
||||
|
||||
// return closing callback
|
||||
c.Ch.Close <- func(){
|
||||
unregister <- c
|
||||
|
|
|
@ -126,13 +126,13 @@ func (s *T) scheduler(){
|
|||
/* (1) New client */
|
||||
case client := <- s.ch.register:
|
||||
|
||||
fmt.Printf(" + client\n")
|
||||
// fmt.Printf(" + client\n")
|
||||
s.clients[client.IO.Sock] = client
|
||||
|
||||
/* (2) New client */
|
||||
case client := <- s.ch.unregister:
|
||||
|
||||
fmt.Printf(" - client\n")
|
||||
// fmt.Printf(" - client\n")
|
||||
delete(s.clients, client.IO.Sock)
|
||||
client.IO.Sock.Close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue