-
Notifications
You must be signed in to change notification settings - Fork 9
/
connection.go
67 lines (54 loc) · 1.21 KB
/
connection.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
60
61
62
63
64
65
66
67
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package grpcstdio
import (
"io"
"net"
"time"
)
func NewConnection(in io.Writer, out io.Reader) net.Conn {
return stdioConn{in, out}
}
type stdioConn struct {
in io.Writer
out io.Reader
}
func (s stdioConn) Read(b []byte) (int, error) {
return s.out.Read(b)
}
func (s stdioConn) Write(b []byte) (int, error) {
return s.in.Write(b)
}
func (s stdioConn) Close() error {
// close context.
return nil
}
func (s stdioConn) LocalAddr() net.Addr {
return stdioAddr{network: "stdio", str: "local"}
}
func (s stdioConn) RemoteAddr() net.Addr {
return stdioAddr{network: "stdio", str: "remote"}
}
func (s stdioConn) SetDeadline(t time.Time) error {
// Not supported.
return nil
}
func (s stdioConn) SetReadDeadline(t time.Time) error {
// Not supported.
return nil
}
func (s stdioConn) SetWriteDeadline(t time.Time) error {
// Not supported.
return nil
}
type stdioAddr struct {
network string
str string
}
func (d stdioAddr) Network() string {
return d.network
}
func (d stdioAddr) String() string {
return d.str
}