-
Notifications
You must be signed in to change notification settings - Fork 1
/
pipe_client_other.go
59 lines (49 loc) · 1.1 KB
/
pipe_client_other.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build darwin || linux
// +build darwin linux
package pipe
import (
"net"
"time"
)
func newPipeConn(address PipeAddr) (*pipeConn, error) {
conn, err := net.DialUnix("unix", nil, &net.UnixAddr{Name: address.String(), Net: "unix"})
if err != nil {
return nil, err
}
return &pipeConn{
conn: conn,
}, nil
}
// PipeConn是命名管道连接的net.Conne接口的实现。
type pipeConn struct {
addr PipeAddr
conn *net.UnixConn
}
// 读取内容上锁
func (c *pipeConn) Read(b []byte) (int, error) {
return c.conn.Read(b)
}
// 写入文件上锁
func (c *pipeConn) Write(b []byte) (int, error) {
return c.conn.Write(b)
}
func (c *pipeConn) Close() (err error) {
return c.conn.Close()
}
func (c *pipeConn) LocalAddr() net.Addr {
return c.addr
}
func (c *pipeConn) RemoteAddr() net.Addr {
return c.addr
}
func (c *pipeConn) SetDeadline(t time.Time) error {
c.SetReadDeadline(t)
c.SetWriteDeadline(t)
return nil
}
func (c *pipeConn) SetReadDeadline(t time.Time) error {
return c.conn.SetReadDeadline(t)
}
func (c *pipeConn) SetWriteDeadline(t time.Time) error {
return c.conn.SetWriteDeadline(t)
}