@@ -15,6 +15,7 @@ const CLIENT_DEBUG = false
15
15
16
16
// Buffer up to this many messages going out
17
17
const OUTGOING_BUFFER = 100
18
+
18
19
// Buffer up to this many messages coming in
19
20
const INCOMING_BUFFER = 100
20
21
@@ -29,7 +30,7 @@ type client struct {
29
30
request * http.Request
30
31
permissions auth.Permissions
31
32
connected bool
32
- closing bool
33
+ closing bool
33
34
subscriptions []string
34
35
write permissionCache
35
36
outgoing chan []byte
@@ -51,23 +52,33 @@ func (c *client) Close() {
51
52
connectedClients --
52
53
53
54
// Close the incoming channel, throw away any extra messages that might be coming our way
54
- if CLIENT_DEBUG { log .Printf ("Closing incoming queue for %s" , c .GetRemoteAddr ()) }
55
+ if CLIENT_DEBUG {
56
+ log .Printf ("Closing incoming queue for %s" , c .GetRemoteAddr ())
57
+ }
55
58
close (c .incoming )
56
59
57
60
// Wait for the outgoing channel to empty
58
- if CLIENT_DEBUG { log .Printf ("Waiting for %s outgoing queue" , c .GetRemoteAddr ()) }
61
+ if CLIENT_DEBUG {
62
+ log .Printf ("Waiting for %s outgoing queue" , c .GetRemoteAddr ())
63
+ }
59
64
c .outgoingWG .Wait ()
60
65
61
- if CLIENT_DEBUG { log .Printf ("Closing outgoing queue for %s" , c .GetRemoteAddr ()) }
66
+ if CLIENT_DEBUG {
67
+ log .Printf ("Closing outgoing queue for %s" , c .GetRemoteAddr ())
68
+ }
62
69
close (c .outgoing )
63
70
64
- if CLIENT_DEBUG { log .Printf ("Unsubscribing %s" , c .GetRemoteAddr ()) }
71
+ if CLIENT_DEBUG {
72
+ log .Printf ("Unsubscribing %s" , c .GetRemoteAddr ())
73
+ }
65
74
66
75
for _ , channel := range c .subscriptions {
67
76
unsubscribe (channel , c )
68
77
}
69
78
70
- if CLIENT_DEBUG { log .Printf ("Closing %s" , c .GetRemoteAddr ()) }
79
+ if CLIENT_DEBUG {
80
+ log .Printf ("Closing %s" , c .GetRemoteAddr ())
81
+ }
71
82
72
83
c .connection .Close ()
73
84
}
@@ -309,9 +320,9 @@ func (c *client) Handle() {
309
320
} else {
310
321
select {
311
322
case c .incoming <- message :
312
- // Message was sent to incoming queue
323
+ // Message was sent to incoming queue
313
324
default :
314
- // Incoming queue was full
325
+ // Incoming queue was full
315
326
log .Printf ("Client from %s filled incoming message queue, disconnecting." , c .GetRemoteAddr ())
316
327
c .Close ()
317
328
return
0 commit comments