Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
孙飞 authored and 孙飞 committed Apr 3, 2019
1 parent 58f0cc5 commit 37f457b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions broker/broker.go
Expand Up @@ -34,6 +34,8 @@ type Broker struct {

cluster *cluster.Cluster

gid uint64

sync.RWMutex
}

Expand All @@ -47,6 +49,9 @@ func New(path string) *Broker {

wg: &sync.WaitGroup{},
clients: make(map[uint64]*client),

// init gid
gid: config.Conf.Broker.ID * 1e9,
}
// init base config
config.Init(path)
Expand Down Expand Up @@ -93,8 +98,6 @@ func (b *Broker) Shutdown() {
b.wg.Wait()
}

var uid uint64

func (b *Broker) onRequest(w http.ResponseWriter, r *http.Request) {
if conn, ok := websocket.TryUpgrade(w, r); ok {
c := newClient(conn, b)
Expand Down
2 changes: 1 addition & 1 deletion broker/client.go
Expand Up @@ -35,7 +35,7 @@ type client struct {
}

func newClient(conn net.Conn, b *Broker) *client {
id := atomic.AddUint64(&uid, 1)
id := atomic.AddUint64(&b.gid, 1)
c := &client{
id: id,
conn: conn,
Expand Down
3 changes: 2 additions & 1 deletion flap.conf
Expand Up @@ -5,8 +5,9 @@ common:
loglevel: debug

broker:
id: 1
listen: ':9091'


storage:
provider: fdb
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Expand Up @@ -15,6 +15,7 @@ type Config struct {
LogLevel string
}
Broker struct {
ID uint64
Listen string
}
Storage struct {
Expand Down

0 comments on commit 37f457b

Please sign in to comment.