From 1f2c1d07600b9612a1f92f42a3c8c893eafd922c Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 3 Jan 2016 06:20:18 -0800 Subject: [PATCH] Fix prioritization logic; Add Status() --- connection.go | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/connection.go b/connection.go index f0f992146..9fae4e510 100644 --- a/connection.go +++ b/connection.go @@ -454,27 +454,34 @@ FOR_LOOP: } } -func (c *MConnection) Status() interface{} { - status := make(map[string]interface{}) - status["sendMonitor"] = c.sendMonitor.Status() - status["recvMonitor"] = c.recvMonitor.Status() +type ConnectionStatus struct { + SendMonitor flow.Status + RecvMonitor flow.Status + Channels []ChannelStatus +} - type channelStatus struct { - SendQueueCapacity int - SendQueueSize int - Priority int - RecentlySent int64 - } +type ChannelStatus struct { + ID byte + SendQueueCapacity int + SendQueueSize int + Priority int + RecentlySent int64 +} - for _, channel := range c.channels { - status[Fmt("ch[%X]", channel.id)] = channelStatus{ +func (c *MConnection) Status() ConnectionStatus { + var status ConnectionStatus + status.SendMonitor = c.sendMonitor.Status() + status.RecvMonitor = c.recvMonitor.Status() + status.Channels = make([]ChannelStatus, len(c.channels)) + for i, channel := range c.channels { + status.Channels[i] = ChannelStatus{ + ID: channel.id, SendQueueCapacity: cap(channel.sendQueue), SendQueueSize: int(channel.sendQueueSize), // TODO use atomic Priority: channel.priority, RecentlySent: channel.recentlySent, } } - return status } @@ -605,7 +612,7 @@ func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int, err error) { log.Debug("Write Msg Packet", "conn", ch.conn, "packet", packet) wire.WriteByte(packetTypeMsg, w, &n, &err) wire.WriteBinary(packet, w, &n, &err) - if err != nil { + if err == nil { ch.recentlySent += int64(n) } return