mirror of https://github.com/siddontang/go.git
add network for support unix socket domain
This commit is contained in:
parent
209f47d5ec
commit
a46d1de902
|
@ -10,6 +10,7 @@ import (
|
|||
type Client struct {
|
||||
sync.Mutex
|
||||
|
||||
network string
|
||||
addr string
|
||||
|
||||
maxIdleConns int
|
||||
|
@ -17,10 +18,11 @@ type Client struct {
|
|||
conns *list.List
|
||||
}
|
||||
|
||||
func NewClient(addr string, maxIdleConns int) *Client {
|
||||
func NewClient(network, addr string, maxIdleConns int) *Client {
|
||||
RegisterType(RpcError{})
|
||||
|
||||
c := new(Client)
|
||||
c.network = network
|
||||
c.addr = addr
|
||||
|
||||
c.maxIdleConns = maxIdleConns
|
||||
|
@ -162,7 +164,7 @@ func (c *Client) popConn() (*conn, error) {
|
|||
return v.Value.(*conn), nil
|
||||
}
|
||||
c.Unlock()
|
||||
return newConn(c.addr)
|
||||
return newConn(c.network, c.addr)
|
||||
}
|
||||
|
||||
func (c *Client) pushConn(co *conn) error {
|
||||
|
|
|
@ -11,8 +11,8 @@ type conn struct {
|
|||
co net.Conn
|
||||
}
|
||||
|
||||
func newConn(addr string) (*conn, error) {
|
||||
c, err := net.Dial("tcp", addr)
|
||||
func newConn(network, addr string) (*conn, error) {
|
||||
c, err := net.Dial(network, addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ var testClient *Client
|
|||
|
||||
func newTestServer() *Server {
|
||||
f := func() {
|
||||
testServer = NewServer("127.0.0.1:11182")
|
||||
testServer = NewServer("tcp", "127.0.0.1:11182")
|
||||
go testServer.Start()
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ func newTestServer() *Server {
|
|||
|
||||
func newTestClient() *Client {
|
||||
f := func() {
|
||||
testClient = NewClient("127.0.0.1:11182", 10)
|
||||
testClient = NewClient("tcp", "127.0.0.1:11182", 10)
|
||||
}
|
||||
|
||||
testClientOnce.Do(f)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
type Server struct {
|
||||
sync.Mutex
|
||||
|
||||
network string
|
||||
addr string
|
||||
funcs map[string]reflect.Value
|
||||
|
||||
|
@ -17,10 +18,11 @@ type Server struct {
|
|||
running bool
|
||||
}
|
||||
|
||||
func NewServer(addr string) *Server {
|
||||
func NewServer(network, addr string) *Server {
|
||||
RegisterType(RpcError{})
|
||||
|
||||
s := new(Server)
|
||||
s.network = network
|
||||
s.addr = addr
|
||||
|
||||
s.funcs = make(map[string]reflect.Value)
|
||||
|
@ -30,7 +32,7 @@ func NewServer(addr string) *Server {
|
|||
|
||||
func (s *Server) Start() error {
|
||||
var err error
|
||||
s.listener, err = net.Listen("tcp", s.addr)
|
||||
s.listener, err = net.Listen(s.network, s.addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue