Skip to content

Commit 5fc5d88

Browse files
committed
Merge branch 'master' of github.com:tomochain/tomox-sdk
2 parents 36f4bda + 0b7649f commit 5fc5d88

File tree

9 files changed

+66
-26
lines changed

9 files changed

+66
-26
lines changed

ws/connection.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
)
1212

1313
const (
14-
writeWait = 60 * time.Second
15-
pongWait = 60 * time.Second
14+
writeWait = 30 * time.Second
15+
pongWait = 30 * time.Second
1616
pingPeriod = (pongWait * 9) / 10
1717
)
1818

ws/lending_markets.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,16 @@ func (s *LendingMarketsSocket) Unsubscribe(c *Client) {
9898
}
9999
}
100100

101-
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
102-
func (s *LendingMarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
101+
func (s *LendingMarketsSocket) getSubscriptions() map[string]map[*Client]bool {
103102
s.subsMutex.RLock()
104103
defer s.subsMutex.RUnlock()
105-
for c, status := range s.subscriptions[channelID] {
104+
return s.subscriptions
105+
}
106+
107+
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
108+
func (s *LendingMarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
109+
subs := s.getSubscriptions()
110+
for c, status := range subs[channelID] {
106111
if status {
107112
s.SendUpdateMessage(c, p)
108113
}

ws/lending_orderbook.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,16 @@ func (s *LendingOrderBookSocket) Unsubscribe(c *Client) {
101101
}
102102
}
103103

104-
// BroadcastMessage streams message to all the subscribtions subscribed to the pair
105-
func (s *LendingOrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
104+
func (s *LendingOrderBookSocket) getSubscriptions() map[string]map[*Client]bool {
106105
s.subsMutex.RLock()
107106
defer s.subsMutex.RUnlock()
108-
for c, status := range s.subscriptions[channelID] {
107+
return s.subscriptions
108+
}
109+
110+
// BroadcastMessage streams message to all the subscribtions subscribed to the pair
111+
func (s *LendingOrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
112+
subs := s.getSubscriptions()
113+
for c, status := range subs[channelID] {
109114
if status {
110115
s.SendUpdateMessage(c, p)
111116
}

ws/lending_priceboard.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,16 @@ func (s *LendingPriceBoardSocket) Unsubscribe(c *Client) {
9494
}
9595
}
9696

97-
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
98-
func (s *LendingPriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
97+
func (s *LendingPriceBoardSocket) getSubscriptions() map[string]map[*Client]bool {
9998
s.subsMutex.RLock()
10099
defer s.subsMutex.RUnlock()
101-
for c, status := range s.subscriptions[channelID] {
100+
return s.subscriptions
101+
}
102+
103+
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
104+
func (s *LendingPriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
105+
subs := s.getSubscriptions()
106+
for c, status := range subs[channelID] {
102107
if status {
103108
s.SendUpdateMessage(c, p)
104109
}

ws/lending_trade.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,17 @@ func (s *LendingTradeSocket) Unsubscribe(c *Client) {
9797
}
9898
}
9999

100+
func (s *LendingTradeSocket) getSubscriptions() map[string]map[*Client]bool {
101+
s.subsMutex.RLock()
102+
defer s.subsMutex.RUnlock()
103+
return lendingTradeSocket.subscriptions
104+
}
105+
100106
// BroadcastMessage broadcasts trade message to all subscribed sockets
101107
func (s *LendingTradeSocket) BroadcastMessage(channelID string, p interface{}) {
102108
go func() {
103-
s.subsMutex.RLock()
104-
defer s.subsMutex.RUnlock()
105-
for conn, active := range lendingTradeSocket.subscriptions[channelID] {
109+
subs := s.getSubscriptions()
110+
for conn, active := range subs[channelID] {
106111
if active {
107112
s.SendUpdateMessage(conn, p)
108113
}

ws/markets.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ func (s *MarketsSocket) Unsubscribe(c *Client) {
9696
}
9797
}
9898

99-
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
100-
func (s *MarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
99+
func (s *MarketsSocket) getSubscriptions() map[string]map[*Client]bool {
101100
s.subsMutex.RLock()
102101
defer s.subsMutex.RUnlock()
103-
for c, status := range s.subscriptions[channelID] {
102+
return s.subscriptions
103+
}
104+
105+
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
106+
func (s *MarketsSocket) BroadcastMessage(channelID string, p interface{}) error {
107+
subs := s.getSubscriptions()
108+
for c, status := range subs[channelID] {
104109
if status {
105110
s.SendUpdateMessage(c, p)
106111
}

ws/orderbook.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,16 @@ func (s *OrderBookSocket) Unsubscribe(c *Client) {
9898
}
9999
}
100100

101-
// BroadcastMessage streams message to all the subscribtions subscribed to the pair
102-
func (s *OrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
101+
func (s *OrderBookSocket) getSubscriptions() map[string]map[*Client]bool {
103102
s.subsMutex.RLock()
104103
defer s.subsMutex.RUnlock()
105-
for c, status := range s.subscriptions[channelID] {
104+
return s.subscriptions
105+
}
106+
107+
// BroadcastMessage streams message to all the subscribtions subscribed to the pair
108+
func (s *OrderBookSocket) BroadcastMessage(channelID string, p interface{}) error {
109+
subs := s.getSubscriptions()
110+
for c, status := range subs[channelID] {
106111
if status {
107112
s.SendUpdateMessage(c, p)
108113
}

ws/price_board.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ func (s *PriceBoardSocket) Unsubscribe(c *Client) {
9595
}
9696
}
9797

98-
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
99-
func (s *PriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
98+
func (s *PriceBoardSocket) getSubscriptions() map[string]map[*Client]bool {
10099
s.subsMutex.RLock()
101100
defer s.subsMutex.RUnlock()
102-
for c, status := range s.subscriptions[channelID] {
101+
return s.subscriptions
102+
}
103+
104+
// BroadcastMessage streams message to all the subscriptions subscribed to the pair
105+
func (s *PriceBoardSocket) BroadcastMessage(channelID string, p interface{}) error {
106+
subs := s.getSubscriptions()
107+
for c, status := range subs[channelID] {
103108
if status {
104109
s.SendUpdateMessage(c, p)
105110
}

ws/trades.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,17 @@ func (s *TradeSocket) Unsubscribe(c *Client) {
9393
}
9494
}
9595

96+
func (s *TradeSocket) getSubscriptions() map[string]map[*Client]bool {
97+
s.subsMutex.RLock()
98+
defer s.subsMutex.RUnlock()
99+
return tradeSocket.subscriptions
100+
}
101+
96102
// BroadcastMessage broadcasts trade message to all subscribed sockets
97103
func (s *TradeSocket) BroadcastMessage(channelID string, p interface{}) {
98104
go func() {
99-
s.subsMutex.RLock()
100-
defer s.subsMutex.RUnlock()
101-
for conn, active := range tradeSocket.subscriptions[channelID] {
105+
subs := s.getSubscriptions()
106+
for conn, active := range subs[channelID] {
102107
if active {
103108
s.SendUpdateMessage(conn, p)
104109
}

0 commit comments

Comments
 (0)