changed GetState and State to State and SetState

https://golang.org/doc/effective_go.html#Getters
This commit is contained in:
tigerbot 2017-03-22 17:45:47 -06:00
parent 9acf50c2ff
commit c7b6a4a000
2 changed files with 9 additions and 9 deletions

View File

@ -92,7 +92,7 @@ func NewConnection(connectionTable *Table, conn *websocket.Conn, remoteAddress s
p.AddTrackedDomain(string(domain.(string))) p.AddTrackedDomain(string(domain.(string)))
} }
p.State(true) p.SetState(true)
p.connectionID = connectionID p.connectionID = connectionID
return return
} }
@ -155,16 +155,16 @@ func (c *Connection) ConnectionTable() *Table {
return c.connectionTable return c.connectionTable
} }
//GetState -- Get state of Socket...this is a high level state. //State -- Get state of Socket...this is a high level state.
func (c *Connection) GetState() bool { func (c *Connection) State() bool {
c.mutex.Lock() c.mutex.Lock()
defer c.mutex.Unlock() defer c.mutex.Unlock()
return c.wssState return c.wssState
} }
//State -- Set the set of the high level connection //SetState -- Set the set of the high level connection
func (c *Connection) State(state bool) { func (c *Connection) SetState(state bool) {
c.mutex.Lock() c.mutex.Lock()
defer c.mutex.Unlock() defer c.mutex.Unlock()
@ -193,7 +193,7 @@ func (c *Connection) ConnectionID() int64 {
//The libary failes if client abends during write-cycle. a fast moving write is not caught before socket state bubbles up //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 //A synchronised state is maintained
func (c *Connection) NextWriter(wssMessageType int) (io.WriteCloser, error) { func (c *Connection) NextWriter(wssMessageType int) (io.WriteCloser, error) {
if c.GetState() == true { if c.State() {
return c.conn.NextWriter(wssMessageType) return c.conn.NextWriter(wssMessageType)
} }
@ -204,7 +204,7 @@ func (c *Connection) NextWriter(wssMessageType int) (io.WriteCloser, error) {
//Write -- Wrapper to allow a high level state check before allowing a write to the socket. //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) (int, error) { func (c *Connection) Write(w io.WriteCloser, message []byte) (int, error) {
if c.GetState() == true { if c.State() {
return w.Write(message) return w.Write(message)
} }
@ -234,7 +234,7 @@ func (c *Connection) Reader(ctx context.Context) {
if err != nil { if err != nil {
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) { if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway) {
c.State(false) c.SetState(false)
loginfo.Printf("error: %v", err) loginfo.Printf("error: %v", err)
} }
break break

View File

@ -57,7 +57,7 @@ func (c *Table) reaper(delay int, idle int) {
loginfo.Println("Running scanning ", len(c.connections)) loginfo.Println("Running scanning ", len(c.connections))
for d := range c.connections { for d := range c.connections {
if d.GetState() == false { if !d.State() {
if time.Since(d.lastUpdate).Seconds() > float64(idle) { if time.Since(d.lastUpdate).Seconds() > float64(idle) {
loginfo.Println("reaper removing ", d.lastUpdate, time.Since(d.lastUpdate).Seconds()) loginfo.Println("reaper removing ", d.lastUpdate, time.Since(d.lastUpdate).Seconds())
delete(c.connections, d) delete(c.connections, d)