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