14 Star 50 Fork 12

Hprose/hprose-go

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
unix_client.go 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
Hprose 提交于 2017-01-07 01:10 +08:00 . Fixed #26
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* rpc/unix_client.go *
* *
* hprose unx client for Go. *
* *
* LastModified: Jan 7, 2017 *
* Author: Ma Bingyao <andot@hprose.com> *
* *
\**********************************************************/
package rpc
import (
"crypto/tls"
"net"
"net/url"
)
// UnixClient is hprose unix client
type UnixClient struct {
SocketClient
}
// NewUnixClient is the constructor of UnixClient
func NewUnixClient(uri ...string) (client *UnixClient) {
client = new(UnixClient)
client.initSocketClient()
client.setCreateConn(client.createUnixConn)
client.SetURIList(uri)
return
}
func newUnixClient(uri ...string) Client {
return NewUnixClient(uri...)
}
// SetURIList set a list of server addresses
func (client *UnixClient) SetURIList(uriList []string) {
CheckAddresses(uriList, unixSchemes)
client.BaseClient.SetURIList(uriList)
}
func (client *UnixClient) createUnixConn() (net.Conn, error) {
u, err := url.Parse(client.uri)
if err != nil {
return nil, err
}
unixaddr, err := net.ResolveUnixAddr(u.Scheme, u.Path)
if err != nil {
return nil, err
}
conn, err := net.DialUnix(u.Scheme, nil, unixaddr)
if err != nil {
return nil, err
}
if client.ReadBuffer > 0 {
err = conn.SetReadBuffer(client.ReadBuffer)
if err != nil {
return nil, err
}
}
if client.WriteBuffer > 0 {
err = conn.SetWriteBuffer(client.WriteBuffer)
if err != nil {
return nil, err
}
}
if client.TLSConfig != nil {
return tls.Client(conn, client.TLSConfig), nil
}
return conn, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/andot/hprose-go.git
git@gitee.com:andot/hprose-go.git
andot
hprose-go
hprose-go
v2.0.4

搜索帮助