2 ucspi -- UCSPI-related utilities
3 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 var aLongTimeAgo = time.Unix(1, 0)
34 func (addr *Addr) Network() string { return "tcp" }
36 func (addr *Addr) String() string { return addr.ip + ":" + addr.port }
43 func NewConn(r, w *os.File) (*Conn, error) {
45 return nil, errors.New("no R file descriptor")
48 return nil, errors.New("no W file descriptor")
50 return &Conn{R: r, W: w}, nil
53 func (conn *Conn) Read(b []byte) (int, error) {
57 func (conn *Conn) Write(b []byte) (int, error) { return conn.W.Write(b) }
59 func (conn *Conn) Close() error {
60 errR := conn.R.Close()
61 errW := conn.W.Close()
68 func (conn *Conn) LocalAddr() net.Addr {
69 return &Addr{ip: os.Getenv("TCPLOCALIP"), port: os.Getenv("TCPLOCALPORT")}
72 func (conn *Conn) RemoteAddr() net.Addr {
73 return &Addr{ip: os.Getenv("TCPREMOTEIP"), port: os.Getenv("TCPREMOTEPORT")}
76 func (conn *Conn) SetDeadline(t time.Time) error {
77 if err := conn.R.SetReadDeadline(t); err != nil {
80 return conn.W.SetWriteDeadline(t)
83 func (conn *Conn) SetReadDeadline(t time.Time) error {
84 return conn.R.SetReadDeadline(t)
87 func (conn *Conn) SetWriteDeadline(t time.Time) error {
88 return conn.W.SetWriteDeadline(t)