Fix prioritization logic; Add Status()

This commit is contained in:
Jae Kwon
2016-01-03 06:20:18 -08:00
parent 3abc18d7ba
commit 1f2c1d0760

View File

@ -454,27 +454,34 @@ FOR_LOOP:
} }
} }
func (c *MConnection) Status() interface{} { type ConnectionStatus struct {
status := make(map[string]interface{}) SendMonitor flow.Status
status["sendMonitor"] = c.sendMonitor.Status() RecvMonitor flow.Status
status["recvMonitor"] = c.recvMonitor.Status() Channels []ChannelStatus
}
type channelStatus struct { type ChannelStatus struct {
SendQueueCapacity int ID byte
SendQueueSize int SendQueueCapacity int
Priority int SendQueueSize int
RecentlySent int64 Priority int
} RecentlySent int64
}
for _, channel := range c.channels { func (c *MConnection) Status() ConnectionStatus {
status[Fmt("ch[%X]", channel.id)] = channelStatus{ 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), SendQueueCapacity: cap(channel.sendQueue),
SendQueueSize: int(channel.sendQueueSize), // TODO use atomic SendQueueSize: int(channel.sendQueueSize), // TODO use atomic
Priority: channel.priority, Priority: channel.priority,
RecentlySent: channel.recentlySent, RecentlySent: channel.recentlySent,
} }
} }
return status 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) log.Debug("Write Msg Packet", "conn", ch.conn, "packet", packet)
wire.WriteByte(packetTypeMsg, w, &n, &err) wire.WriteByte(packetTypeMsg, w, &n, &err)
wire.WriteBinary(packet, w, &n, &err) wire.WriteBinary(packet, w, &n, &err)
if err != nil { if err == nil {
ch.recentlySent += int64(n) ch.recentlySent += int64(n)
} }
return return