Skip to content

Commit

Permalink
init server and clients
Browse files Browse the repository at this point in the history
  • Loading branch information
name5566 committed Oct 13, 2015
1 parent a1b28b2 commit 921a9c9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
56 changes: 56 additions & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,65 @@
package cluster

import (
"github.com/name5566/leaf/conf"
"github.com/name5566/leaf/network"
"math"
"time"
)

var (
server *network.TCPServer
clients []*network.TCPClient
)

func Init() {
if conf.ListenAddr != "" {
server = new(network.TCPServer)
server.Addr = conf.ListenAddr
server.MaxConnNum = int(math.MaxInt32)
server.PendingWriteNum = conf.PendingWriteNum
server.LenMsgLen = 4
server.MaxMsgLen = math.MaxUint32
server.NewAgent = newAgent

server.Start()
}

for _, addr := range conf.ConnAddrs {
client := new(network.TCPClient)
client.Addr = addr
client.ConnNum = 1
client.ConnectInterval = 3 * time.Second
client.PendingWriteNum = conf.PendingWriteNum
client.LenMsgLen = 4
client.MaxMsgLen = math.MaxUint32
client.NewAgent = newAgent

client.Start()
clients = append(clients, client)
}
}

func Destroy() {
if server != nil {
server.Close()
}

for _, client := range clients {
client.Close()
}
}

type Agent struct {
conn *network.TCPConn
}

func newAgent(conn *network.TCPConn) network.Agent {
a := new(Agent)
a.conn = conn
return a
}

func (a *Agent) Run() {}

func (a *Agent) OnClose() {}
5 changes: 3 additions & 2 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
ProfilePath string

// cluster
ListenAddr string
ConnAddrs []string
ListenAddr string
ConnAddrs []string
PendingWriteNum int
)

0 comments on commit 921a9c9

Please sign in to comment.