ing
This commit is contained in:
parent
b4b379c891
commit
78c2f69893
|
@ -2,8 +2,8 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -31,7 +31,7 @@ type Client interface {
|
||||||
type client struct {
|
type client struct {
|
||||||
ch ClientHandler
|
ch ClientHandler
|
||||||
|
|
||||||
rwc io.ReadWriteCloser
|
conn net.Conn
|
||||||
|
|
||||||
pendingRequestsCount uint32
|
pendingRequestsCount uint32
|
||||||
pendingRequests map[interface{}]*CallState
|
pendingRequests map[interface{}]*CallState
|
||||||
|
@ -51,7 +51,7 @@ func (c *client) Connect() error {
|
||||||
panic("RPC Client: the given client is already started. Call Client.Stop() before calling Client.Start() again!")
|
panic("RPC Client: the given client is already started. Call Client.Stop() before calling Client.Start() again!")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.rwc, err = c.ch.Connect(); nil != err {
|
if c.conn, err = c.ch.Connect(); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.stopChan = make(chan struct{})
|
c.stopChan = make(chan struct{})
|
||||||
|
@ -187,7 +187,7 @@ func (c *client) handleRPC() {
|
||||||
<-writerDone
|
<-writerDone
|
||||||
}
|
}
|
||||||
|
|
||||||
c.rwc.Close()
|
c.conn.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//c.LogError("%s", err)
|
//c.LogError("%s", err)
|
||||||
|
@ -258,7 +258,7 @@ func (c *client) rpcWriter(stopChan <-chan struct{}, writerDone chan<- error) {
|
||||||
releaseCallState(cs)
|
releaseCallState(cs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = c.ch.GetCodec().Write(c.rwc, cs.Method, cs.Args, cs.ID); nil != err {
|
if err = c.ch.GetCodec().Write(c.conn, cs.Method, cs.Args, cs.ID); nil != err {
|
||||||
err = fmt.Errorf("Client: Cannot send request to wire: [%s]", err)
|
err = fmt.Errorf("Client: Cannot send request to wire: [%s]", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ func (c *client) rpcReader(readerDone chan<- error) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
crn, err := c.ch.GetCodec().NewResponseOrNotify(c.rwc)
|
crn, err := c.ch.GetCodec().NewResponseOrNotify(c.conn)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
err = fmt.Errorf("Client: Cannot decode response or notify: [%s]", err)
|
err = fmt.Errorf("Client: Cannot decode response or notify: [%s]", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.loafle.net/commons_go/rpc"
|
"git.loafle.net/commons_go/rpc"
|
||||||
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClientHandler interface {
|
type ClientHandler interface {
|
||||||
Connect() (io.ReadWriteCloser, error)
|
Connect() (net.Conn, error)
|
||||||
GetCodec() protocol.ClientCodec
|
GetCodec() protocol.ClientCodec
|
||||||
|
|
||||||
GetRPCRegistry() rpc.Registry
|
GetRPCRegistry() rpc.Registry
|
||||||
|
|
|
@ -2,7 +2,7 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ type ClientHandlers struct {
|
||||||
requestIDMtx sync.Mutex
|
requestIDMtx sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *ClientHandlers) Connect() (io.ReadWriteCloser, error) {
|
func (ch *ClientHandlers) Connect() (net.Conn, error) {
|
||||||
return nil, errors.New("RPC Client: ClientHandlers method[Connect] is not implement")
|
return nil, errors.New("RPC Client: ClientHandlers method[Connect] is not implement")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user