use correct connections
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m48s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m48s
This commit is contained in:
29
rpc-pool.go
29
rpc-pool.go
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@@ -30,31 +29,18 @@ type RemoteGrain struct {
|
||||
}
|
||||
|
||||
func NewRemoteGrain(id CartId, address string) *RemoteGrain {
|
||||
client, err := CartDial(address)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &RemoteGrain{
|
||||
Id: id,
|
||||
Address: address,
|
||||
CartClient: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *RemoteGrain) Connect() error {
|
||||
if g == nil {
|
||||
return fmt.Errorf("grain is deleted")
|
||||
}
|
||||
if g.connection == nil {
|
||||
addr := g.Address
|
||||
if !strings.Contains(addr, ":") {
|
||||
addr = fmt.Sprintf("%s:1337", addr)
|
||||
}
|
||||
client, err := net.Dial("tcp", addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
g.Conn = client
|
||||
g.PacketQueue = NewPacketQueue(client)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *RemoteGrain) HandleMessage(message *Message, isReplay bool) ([]byte, error) {
|
||||
|
||||
data, err := GetData(message.Write)
|
||||
@@ -92,7 +78,6 @@ func (p *RemoteGrainPool) findRemoteGrain(id CartId) *RemoteGrain {
|
||||
if !ok || grain == nil {
|
||||
return nil
|
||||
}
|
||||
grain.Connect()
|
||||
return grain
|
||||
}
|
||||
|
||||
@@ -100,10 +85,10 @@ func (p *RemoteGrainPool) findOrCreateGrain(id CartId) *RemoteGrain {
|
||||
grain := p.findRemoteGrain(id)
|
||||
if grain == nil {
|
||||
grain = NewRemoteGrain(id, p.Host)
|
||||
|
||||
p.mu.Lock()
|
||||
p.grains[id] = grain
|
||||
p.mu.Unlock()
|
||||
grain.Connect()
|
||||
}
|
||||
return grain
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user