2024-06-18 05:36:36 +00:00
|
|
|
package splithttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type splitConn struct {
|
|
|
|
writer io.WriteCloser
|
|
|
|
reader io.ReadCloser
|
|
|
|
remoteAddr net.Addr
|
|
|
|
localAddr net.Addr
|
2024-09-16 12:42:01 +00:00
|
|
|
onClose func()
|
2024-06-18 05:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) Write(b []byte) (int, error) {
|
|
|
|
return c.writer.Write(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) Read(b []byte) (int, error) {
|
|
|
|
return c.reader.Read(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) Close() error {
|
2024-09-16 12:42:01 +00:00
|
|
|
if c.onClose != nil {
|
|
|
|
c.onClose()
|
|
|
|
}
|
|
|
|
|
2024-06-18 05:36:36 +00:00
|
|
|
err := c.writer.Close()
|
|
|
|
err2 := c.reader.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err2 != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) LocalAddr() net.Addr {
|
|
|
|
return c.localAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) RemoteAddr() net.Addr {
|
|
|
|
return c.remoteAddr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) SetDeadline(t time.Time) error {
|
|
|
|
// TODO cannot do anything useful
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) SetReadDeadline(t time.Time) error {
|
|
|
|
// TODO cannot do anything useful
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *splitConn) SetWriteDeadline(t time.Time) error {
|
|
|
|
// TODO cannot do anything useful
|
|
|
|
return nil
|
|
|
|
}
|