From 0ed39dec0e54164592300bd46018af78bab655e7 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 2 May 2018 22:56:38 +0200 Subject: [PATCH] remove debug + clean main --- cmd/iface/main.go | 24 +++++++++++++----------- ws/client/public.go | 18 +++--------------- ws/server/public.go | 4 ++-- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/cmd/iface/main.go b/cmd/iface/main.go index aca887f..e7559f1 100644 --- a/cmd/iface/main.go +++ b/cmd/iface/main.go @@ -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() diff --git a/ws/client/public.go b/ws/client/public.go index 548e3c7..bb21003 100644 --- a/ws/client/public.go +++ b/ws/client/public.go @@ -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 diff --git a/ws/server/public.go b/ws/server/public.go index 9f2e63e..898b692 100644 --- a/ws/server/public.go +++ b/ws/server/public.go @@ -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()