simplified some function inputs and returns

This commit is contained in:
tigerbot 2017-03-22 16:33:09 -06:00
parent 87a1d9c0ae
commit 92f951544b
10 changed files with 56 additions and 78 deletions

View File

@ -9,12 +9,12 @@ type TrafficAPI struct {
}
//NewTrafficStats -- Consttuctor
func NewTrafficAPI(requests int64, responses int64, bytes_in int64, bytes_out int64) (p *TrafficAPI) {
func NewTrafficAPI(requests, responses, bytesIn, bytesOut int64) (p *TrafficAPI) {
p = new(TrafficAPI)
p.Requests = requests
p.Responses = responses
p.BytesIn = bytes_in
p.BytesOut = bytes_out
p.BytesIn = bytesIn
p.BytesOut = bytesOut
return
}
}

View File

@ -79,17 +79,14 @@ func (p *Tracking) list() {
//Lookup --
// - get connection from key
func (p *Tracking) Lookup(key string) (c *Track, err error) {
func (p *Tracking) Lookup(key string) (*Track, error) {
defer func() {
p.mutex.Unlock()
}()
p.mutex.Lock()
if _, ok := p.connections[key]; ok {
c = p.connections[key]
} else {
err = fmt.Errorf("Lookup failed for %s", key)
c = nil
return p.connections[key], nil
}
return
return nil, fmt.Errorf("Lookup failed for %s", key)
}

View File

@ -28,7 +28,7 @@ func NewWedgeConnSize(c net.Conn, size int) (p *WedgeConn) {
}
//Discard - discard a number of bytes, perhaps after peeking at the
func (w *WedgeConn) Discard(n int) (discarded int, err error) {
func (w *WedgeConn) Discard(n int) (int, error) {
return w.reader.Discard(n)
}
@ -44,8 +44,7 @@ func (w *WedgeConn) ReadByte() (byte, error) {
//Read -- A normal reader.
func (w *WedgeConn) Read(p []byte) (int, error) {
cnt, err := w.reader.Read(p)
return cnt, err
return w.reader.Read(p)
}
//Buffered --
@ -56,13 +55,6 @@ func (w *WedgeConn) Buffered() int {
//PeekAll --
// - get all the chars available
// - pass then back
func (w *WedgeConn) PeekAll() (buf []byte, err error) {
_, err = w.Peek(1)
if err != nil {
return nil, err
}
buf, err = w.Peek(w.Buffered())
return
func (w *WedgeConn) PeekAll() ([]byte, error) {
return w.Peek(w.Buffered())
}

View File

@ -106,27 +106,23 @@ func (c *Connection) AddTrackedDomain(domain string) {
}
//InitialDomains -- Property
func (c *Connection) InitialDomains() (i []interface{}) {
i = c.initialDomains
return
func (c *Connection) InitialDomains() []interface{} {
return c.initialDomains
}
//ConnectTime -- Property
func (c *Connection) ConnectTime() (t time.Time) {
t = c.connectTime
return
func (c *Connection) ConnectTime() time.Time {
return c.connectTime
}
//BytesIn -- Property
func (c *Connection) BytesIn() (b int64) {
b = c.bytesIn
return
func (c *Connection) BytesIn() int64 {
return c.bytesIn
}
//BytesOut -- Property
func (c *Connection) BytesOut() (b int64) {
b = c.bytesOut
return
func (c *Connection) BytesOut() int64 {
return c.bytesOut
}
//SendCh -- property to sending channel
@ -156,9 +152,8 @@ func (c *Connection) addResponse() {
}
//ConnectionTable -- property
func (c *Connection) ConnectionTable() (table *Table) {
table = c.connectionTable
return
func (c *Connection) ConnectionTable() *Table {
return c.connectionTable
}
//GetState -- Get state of Socket...this is a high level state.
@ -203,21 +198,24 @@ func (c *Connection) ConnectionID() int64 {
//NextWriter -- Wrapper to allow a high level state check before offering NextWriter
//The libary failes if client abends during write-cycle. a fast moving write is not caught before socket state bubbles up
//A synchronised state is maintained
func (c Connection) NextWriter(wssMessageType int) (w io.WriteCloser, err error) {
func (c *Connection) NextWriter(wssMessageType int) (io.WriteCloser, error) {
if c.GetState() == true {
w, err = c.conn.NextWriter(wssMessageType)
} else {
loginfo.Println("NextWriter aborted, state is not true")
return c.conn.NextWriter(wssMessageType)
}
return
// Is returning a nil error actually the proper thing to do here?
loginfo.Println("NextWriter aborted, state is not true")
return nil, nil
}
//Write -- Wrapper to allow a high level state check before allowing a write to the socket.
func (c *Connection) Write(w io.WriteCloser, message []byte) (cnt int, err error) {
func (c *Connection) Write(w io.WriteCloser, message []byte) (int, error) {
if c.GetState() == true {
cnt, err = w.Write(message)
return w.Write(message)
}
return
// Is returning a nil error actually the proper thing to do here?
return 0, nil
}
//Reader -- export the reader function

View File

@ -24,7 +24,7 @@ type Table struct {
}
//NewTable -- consructor
func NewTable(dwell int, idle int) (p *Table) {
func NewTable(dwell, idle int) (p *Table) {
p = new(Table)
p.connections = make(map[*Connection][]string)
p.domains = make(map[string]*Connection)
@ -38,15 +38,14 @@ func NewTable(dwell int, idle int) (p *Table) {
}
//Connections Property
func (c *Table) Connections() (table map[*Connection][]string) {
table = c.connections
return
func (c *Table) Connections() map[*Connection][]string {
return c.connections
}
//ConnByDomain -- Obtains a connection from a domain announcement.
func (c *Table) ConnByDomain(domain string) (conn *Connection, ok bool) {
conn, ok = c.domains[domain]
return
func (c *Table) ConnByDomain(domain string) (*Connection, bool) {
conn, ok := c.domains[domain]
return conn, ok
}
//reaper --
@ -69,16 +68,14 @@ func (c *Table) reaper(delay int, idle int) {
}
//GetConnection -- find connection by server-id
func (c *Table) GetConnection(serverID int64) (conn *Connection, err error) {
func (c *Table) GetConnection(serverID int64) (*Connection, error) {
for conn := range c.connections {
if conn.ConnectionID() == serverID {
return conn, err
return conn, nil
}
}
err = fmt.Errorf("Server-id %d not found", serverID)
return nil, err
return nil, fmt.Errorf("Server-id %d not found", serverID)
}
//Run -- Execute
@ -144,7 +141,6 @@ func (c *Table) Run(ctx context.Context) {
}
//Register -- Property
func (c *Table) Register() (r chan *Registration) {
r = c.register
return
func (c *Table) Register() chan *Registration {
return c.register
}

View File

@ -21,15 +21,13 @@ func NewDomainTrack(domainName string) (p *DomainTrack) {
}
//BytesIn -- Property
func (c *DomainTrack) BytesIn() (b int64) {
b = c.bytesIn
return
func (c *DomainTrack) BytesIn() int64 {
return c.bytesIn
}
//BytesOut -- Property
func (c *DomainTrack) BytesOut() (b int64) {
b = c.bytesOut
return
func (c *DomainTrack) BytesOut() int64 {
return c.bytesOut
}
//AddIn - Property

View File

@ -271,7 +271,7 @@ func handleStream(ctx context.Context, wConn *WedgeConn) {
//handleExternalHTTPRequest -
// - get a wConn and start processing requests
func handleExternalHTTPRequest(ctx context.Context, extConn *WedgeConn, hostname string, service string) {
func handleExternalHTTPRequest(ctx context.Context, extConn *WedgeConn, hostname, service string) {
//connectionTracking := ctx.Value(ctxConnectionTrack).(*Tracking)
serverStatus := ctx.Value(ctxServerStatus).(*Status)

View File

@ -9,18 +9,16 @@ type oneConnListener struct {
conn net.Conn
}
func (l *oneConnListener) Accept() (c net.Conn, err error) {
c = l.conn
if c == nil {
err = io.EOF
loginfo.Println("Accept")
return
func (l *oneConnListener) Accept() (net.Conn, error) {
if l.conn == nil {
loginfo.Println("Accept EOF")
return nil, io.EOF
}
err = nil
c := l.conn
l.conn = nil
loginfo.Println("Accept", c.LocalAddr().String(), c.RemoteAddr().String())
return
return c, nil
}
func (l *oneConnListener) Close() error {

View File

@ -46,7 +46,6 @@ func (p *Status) WSSConnectionRegister(newRegistration *Registration) {
//unregisters a south facing connection
//intercept and update global statistics
func (p *Status) WSSConnectionUnregister() {
}
// External Facing Functions

View File

@ -8,7 +8,7 @@ type StatusDeadTime struct {
}
//NewStatusDeadTime -- constructor
func NewStatusDeadTime(dwell int, idle int, cancelcheck int) (p *StatusDeadTime) {
func NewStatusDeadTime(dwell, idle, cancelcheck int) (p *StatusDeadTime) {
p = new(StatusDeadTime)
p.dwell = dwell
p.idle = idle