Commit 8cf6ad33 authored by Kamil Kisiel's avatar Kamil Kisiel

Documented console.go

parent 899d1553
...@@ -6,13 +6,17 @@ import ( ...@@ -6,13 +6,17 @@ import (
"strings" "strings"
) )
// DefaultConsoleAddr is the default address on which a ConsoleServer will listen
const DefaultConsoleAddr = ":8126" const DefaultConsoleAddr = ":8126"
// ConsoleServer is an object that listens for telnet connection on a TCP address Addr
// and provides a console interface to a manage a MetricsAggregator
type ConsoleServer struct { type ConsoleServer struct {
Addr string Addr string
Aggregator *MetricAggregator Aggregator *MetricAggregator
} }
// ListenAndServe listens on the ConsoleServer's TCP network address and then calls Serve
func (s *ConsoleServer) ListenAndServe() error { func (s *ConsoleServer) ListenAndServe() error {
addr := s.Addr addr := s.Addr
if addr == "" { if addr == "" {
...@@ -25,6 +29,8 @@ func (s *ConsoleServer) ListenAndServe() error { ...@@ -25,6 +29,8 @@ func (s *ConsoleServer) ListenAndServe() error {
return s.Serve(l) return s.Serve(l)
} }
// Serve accepts incoming connections on the listener and serves them a console interface to
// the MetricAggregator
func (s *ConsoleServer) Serve(l net.Listener) error { func (s *ConsoleServer) Serve(l net.Listener) error {
defer l.Close() defer l.Close()
for { for {
...@@ -38,11 +44,13 @@ func (s *ConsoleServer) Serve(l net.Listener) error { ...@@ -38,11 +44,13 @@ func (s *ConsoleServer) Serve(l net.Listener) error {
panic("not reached") panic("not reached")
} }
// consoleConn represents a single ConsoleServer connection
type consoleConn struct { type consoleConn struct {
conn net.Conn conn net.Conn
server *ConsoleServer server *ConsoleServer
} }
// serve reads from the consoleConn and responds to incoming requests
func (c *consoleConn) serve() { func (c *consoleConn) serve() {
defer c.conn.Close() defer c.conn.Close()
buf := make([]byte, 1024) buf := make([]byte, 1024)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment