Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
travisjeffery committed Oct 16, 2017
1 parent e738825 commit 02a1063
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net"
"net/http"
"os"
"sync"
"time"

"github.com/gorilla/handlers"
Expand All @@ -26,13 +25,12 @@ type Server struct {
protocolLn *net.TCPListener
httpAddr string
httpLn *net.TCPListener
mu sync.Mutex
logger *simplelog.Logger
broker jocko.Broker
shutdownc chan struct{}
shutdownCh chan struct{}
metrics *metrics
requestc chan jocko.Request
responsec chan jocko.Response
requestCh chan jocko.Request
responseCh chan jocko.Response
}

func New(protocolAddr string, broker jocko.Broker, httpAddr string, logger *simplelog.Logger) *Server {
Expand All @@ -41,9 +39,9 @@ func New(protocolAddr string, broker jocko.Broker, httpAddr string, logger *simp
httpAddr: httpAddr,
broker: broker,
logger: logger,
shutdownc: make(chan struct{}),
requestc: make(chan jocko.Request, 32),
responsec: make(chan jocko.Response, 32),
shutdownCh: make(chan struct{}),
requestCh: make(chan jocko.Request, 32),
responseCh: make(chan jocko.Response, 32),
}
s.metrics = newMetrics(prometheus.DefaultRegisterer)
return s
Expand Down Expand Up @@ -85,7 +83,7 @@ func (s *Server) Start(ctx context.Context) error {
select {
case <-ctx.Done():
break
case <-s.shutdownc:
case <-s.shutdownCh:
break
default:
conn, err := s.protocolLn.Accept()
Expand All @@ -104,17 +102,17 @@ func (s *Server) Start(ctx context.Context) error {
select {
case <-ctx.Done():
break
case <-s.shutdownc:
case <-s.shutdownCh:
break
case resp := <-s.responsec:
case resp := <-s.responseCh:
if err := s.write(resp); err != nil {
s.logger.Info("failed to write response: %v", err)
}
}
}
}()

go s.broker.Run(ctx, s.requestc, s.responsec)
go s.broker.Run(ctx, s.requestCh, s.responseCh)

go func() {
err := server.Serve(s.httpLn)
Expand All @@ -128,7 +126,7 @@ func (s *Server) Start(ctx context.Context) error {

// Close closes the service.
func (s *Server) Close() {
close(s.shutdownc)
close(s.shutdownCh)
s.protocolLn.Close()
return
}
Expand Down Expand Up @@ -203,7 +201,7 @@ func (s *Server) handleRequest(conn net.Conn) {
panic(err)
}

s.requestc <- jocko.Request{
s.requestCh <- jocko.Request{
Header: header,
Request: req,
Conn: conn,
Expand Down

0 comments on commit 02a1063

Please sign in to comment.