Skip to content

Commit

Permalink
gee-rpc client move call.Seq = seq to registerCall
Browse files Browse the repository at this point in the history
  • Loading branch information
geektutu committed Oct 7, 2020
1 parent e094f10 commit 3c89baa
Show file tree
Hide file tree
Showing 16 changed files with 863 additions and 25 deletions.
1 change: 1 addition & 0 deletions gee-rpc/day1-codec/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func startServer(addr chan string) {
}

func main() {
log.SetFlags(0)
addr := make(chan string)
go startServer(addr)

Expand Down
7 changes: 3 additions & 4 deletions gee-rpc/day2-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (client *Client) registerCall(call *Call) (uint64, error) {
if client.closing || client.shutdown {
return 0, ErrShutdown
}
seq := client.seq
client.pending[seq] = call
call.Seq = client.seq
client.pending[call.Seq] = call
client.seq++
return seq, nil
return call.Seq, nil
}

func (client *Client) removeCall(seq uint64) *Call {
Expand Down Expand Up @@ -106,7 +106,6 @@ func (client *Client) send(call *Call) {

// register this call.
seq, err := client.registerCall(call)
call.Seq = seq
if err != nil {
call.Error = err
call.done()
Expand Down
1 change: 1 addition & 0 deletions gee-rpc/day2-client/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func startServer(addr chan string) {
}

func main() {
log.SetFlags(0)
addr := make(chan string)
go startServer(addr)
client, _ := geerpc.Dial("tcp", <-addr)
Expand Down
7 changes: 3 additions & 4 deletions gee-rpc/day3-service/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (client *Client) registerCall(call *Call) (uint64, error) {
if client.closing || client.shutdown {
return 0, ErrShutdown
}
seq := client.seq
client.pending[seq] = call
call.Seq = client.seq
client.pending[call.Seq] = call
client.seq++
return seq, nil
return call.Seq, nil
}

func (client *Client) removeCall(seq uint64) *Call {
Expand Down Expand Up @@ -106,7 +106,6 @@ func (client *Client) send(call *Call) {

// register this call.
seq, err := client.registerCall(call)
call.Seq = seq
if err != nil {
call.Error = err
call.done()
Expand Down
1 change: 1 addition & 0 deletions gee-rpc/day3-service/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func startServer(addr chan string) {
}

func main() {
log.SetFlags(0)
addr := make(chan string)
go startServer(addr)
client, _ := geerpc.Dial("tcp", <-addr)
Expand Down
7 changes: 3 additions & 4 deletions gee-rpc/day4-timeout/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ func (client *Client) registerCall(call *Call) (uint64, error) {
if client.closing || client.shutdown {
return 0, ErrShutdown
}
seq := client.seq
client.pending[seq] = call
call.Seq = client.seq
client.pending[call.Seq] = call
client.seq++
return seq, nil
return call.Seq, nil
}

func (client *Client) removeCall(seq uint64) *Call {
Expand Down Expand Up @@ -108,7 +108,6 @@ func (client *Client) send(call *Call) {

// register this call.
seq, err := client.registerCall(call)
call.Seq = seq
if err != nil {
call.Error = err
call.done()
Expand Down
1 change: 1 addition & 0 deletions gee-rpc/day4-timeout/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func startServer(addr chan string) {
}

func main() {
log.SetFlags(0)
addr := make(chan string)
go startServer(addr)
client, _ := geerpc.Dial("tcp", <-addr)
Expand Down
7 changes: 3 additions & 4 deletions gee-rpc/day5-http-debug/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (client *Client) registerCall(call *Call) (uint64, error) {
if client.closing || client.shutdown {
return 0, ErrShutdown
}
seq := client.seq
client.pending[seq] = call
call.Seq = client.seq
client.pending[call.Seq] = call
client.seq++
return seq, nil
return call.Seq, nil
}

func (client *Client) removeCall(seq uint64) *Call {
Expand Down Expand Up @@ -111,7 +111,6 @@ func (client *Client) send(call *Call) {

// register this call.
seq, err := client.registerCall(call)
call.Seq = seq
if err != nil {
call.Error = err
call.done()
Expand Down
1 change: 1 addition & 0 deletions gee-rpc/day5-http-debug/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func call(addrCh chan string) {
}

func main() {
log.SetFlags(0)
ch := make(chan string)
go call(ch)
startServer(ch)
Expand Down
7 changes: 3 additions & 4 deletions gee-rpc/day6-load-balance/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (client *Client) registerCall(call *Call) (uint64, error) {
if client.closing || client.shutdown {
return 0, ErrShutdown
}
seq := client.seq
client.pending[seq] = call
call.Seq = client.seq
client.pending[call.Seq] = call
client.seq++
return seq, nil
return call.Seq, nil
}

func (client *Client) removeCall(seq uint64) *Call {
Expand Down Expand Up @@ -111,7 +111,6 @@ func (client *Client) send(call *Call) {

// register this call.
seq, err := client.registerCall(call)
call.Seq = seq
if err != nil {
call.Error = err
call.done()
Expand Down
1 change: 1 addition & 0 deletions gee-rpc/day6-load-balance/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func broadcast(addr1, addr2 string) {
}

func main() {
log.SetFlags(0)
ch1 := make(chan string)
ch2 := make(chan string)
// start two servers
Expand Down
7 changes: 3 additions & 4 deletions gee-rpc/day7-registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ func (client *Client) registerCall(call *Call) (uint64, error) {
if client.closing || client.shutdown {
return 0, ErrShutdown
}
seq := client.seq
client.pending[seq] = call
call.Seq = client.seq
client.pending[call.Seq] = call
client.seq++
return seq, nil
return call.Seq, nil
}

func (client *Client) removeCall(seq uint64) *Call {
Expand Down Expand Up @@ -111,7 +111,6 @@ func (client *Client) send(call *Call) {

// register this call.
seq, err := client.registerCall(call)
call.Seq = seq
if err != nil {
call.Error = err
call.done()
Expand Down
1 change: 1 addition & 0 deletions gee-rpc/day7-registry/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func broadcast(registry string) {
}

func main() {
log.SetFlags(0)
registryAddr := "http://localhost:9999/_geerpc_/registry"
var wg sync.WaitGroup
wg.Add(1)
Expand Down
Loading

0 comments on commit 3c89baa

Please sign in to comment.