don't use sigillum
This commit is contained in:
parent
503d523dbf
commit
c6c6c9cac2
@ -9,6 +9,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
DefaultTimeout time.Duration = 1000
|
||||||
|
)
|
||||||
|
|
||||||
// One client connect to one server.
|
// One client connect to one server.
|
||||||
// Use Pool for multi-connections.
|
// Use Pool for multi-connections.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@ -21,7 +25,7 @@ type Client struct {
|
|||||||
conn net.Conn
|
conn net.Conn
|
||||||
rw *bufio.ReadWriter
|
rw *bufio.ReadWriter
|
||||||
|
|
||||||
RespTimeout time.Duration // response timeout for do() in ms
|
ResponseTimeout time.Duration // response timeout for do() in ms
|
||||||
|
|
||||||
ErrorHandler ErrorHandler
|
ErrorHandler ErrorHandler
|
||||||
}
|
}
|
||||||
@ -29,12 +33,12 @@ type Client struct {
|
|||||||
// Return a client.
|
// Return a client.
|
||||||
func New(network, addr string) (client *Client, err error) {
|
func New(network, addr string) (client *Client, err error) {
|
||||||
client = &Client{
|
client = &Client{
|
||||||
net: network,
|
net: network,
|
||||||
addr: addr,
|
addr: addr,
|
||||||
respHandler: make(map[string]ResponseHandler, queueSize),
|
respHandler: make(map[string]ResponseHandler, queueSize),
|
||||||
innerHandler: make(map[string]ResponseHandler, queueSize),
|
innerHandler: make(map[string]ResponseHandler, queueSize),
|
||||||
in: make(chan *Response, queueSize),
|
in: make(chan *Response, queueSize),
|
||||||
RespTimeout: 1000,
|
ResponseTimeout: DefaultTimeout,
|
||||||
}
|
}
|
||||||
client.conn, err = net.Dial(client.net, client.addr)
|
client.conn, err = net.Dial(client.net, client.addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,7 +185,7 @@ func (client *Client) handleInner(key string, resp *Response) *Response {
|
|||||||
|
|
||||||
type handleOrError struct {
|
type handleOrError struct {
|
||||||
handle string
|
handle string
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) do(funcname string, data []byte,
|
func (client *Client) do(funcname string, data []byte,
|
||||||
@ -208,7 +212,7 @@ func (client *Client) do(funcname string, data []byte,
|
|||||||
client.lastcall = ""
|
client.lastcall = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var timer = time.After(client.RespTimeout * time.Millisecond)
|
var timer = time.After(client.ResponseTimeout * time.Millisecond)
|
||||||
select {
|
select {
|
||||||
case ret := <-result:
|
case ret := <-result:
|
||||||
return ret.handle, ret.err
|
return ret.handle, ret.err
|
||||||
|
Loading…
Reference in New Issue
Block a user