Skip to content

Commit 3ed6ff9

Browse files
committed
chore: export pipeDeadline
1 parent 34de62d commit 3ed6ff9

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

common/net/deadline/conn.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type connReadResult struct {
2020
type Conn struct {
2121
network.ExtendedConn
2222
deadline atomic.TypedValue[time.Time]
23-
pipeDeadline pipeDeadline
23+
pipeDeadline PipeDeadline
2424
disablePipe atomic.Bool
2525
inRead atomic.Bool
2626
resultCh chan *connReadResult
@@ -34,7 +34,7 @@ func IsConn(conn any) bool {
3434
func NewConn(conn net.Conn) *Conn {
3535
c := &Conn{
3636
ExtendedConn: bufio.NewExtendedConn(conn),
37-
pipeDeadline: makePipeDeadline(),
37+
pipeDeadline: MakePipeDeadline(),
3838
resultCh: make(chan *connReadResult, 1),
3939
}
4040
c.resultCh <- nil
@@ -58,7 +58,7 @@ func (c *Conn) Read(p []byte) (n int, err error) {
5858
c.resultCh <- nil
5959
break
6060
}
61-
case <-c.pipeDeadline.wait():
61+
case <-c.pipeDeadline.Wait():
6262
return 0, os.ErrDeadlineExceeded
6363
}
6464

@@ -104,7 +104,7 @@ func (c *Conn) ReadBuffer(buffer *buf.Buffer) (err error) {
104104
c.resultCh <- nil
105105
break
106106
}
107-
case <-c.pipeDeadline.wait():
107+
case <-c.pipeDeadline.Wait():
108108
return os.ErrDeadlineExceeded
109109
}
110110

@@ -130,7 +130,7 @@ func (c *Conn) SetReadDeadline(t time.Time) error {
130130
return c.ExtendedConn.SetReadDeadline(t)
131131
}
132132
c.deadline.Store(t)
133-
c.pipeDeadline.set(t)
133+
c.pipeDeadline.Set(t)
134134
return nil
135135
}
136136

common/net/deadline/packet.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type readResult struct {
1919
type NetPacketConn struct {
2020
net.PacketConn
2121
deadline atomic.TypedValue[time.Time]
22-
pipeDeadline pipeDeadline
22+
pipeDeadline PipeDeadline
2323
disablePipe atomic.Bool
2424
inRead atomic.Bool
2525
resultCh chan any
@@ -28,7 +28,7 @@ type NetPacketConn struct {
2828
func NewNetPacketConn(pc net.PacketConn) net.PacketConn {
2929
npc := &NetPacketConn{
3030
PacketConn: pc,
31-
pipeDeadline: makePipeDeadline(),
31+
pipeDeadline: MakePipeDeadline(),
3232
resultCh: make(chan any, 1),
3333
}
3434
npc.resultCh <- nil
@@ -83,7 +83,7 @@ FOR:
8383
c.resultCh <- nil
8484
break FOR
8585
}
86-
case <-c.pipeDeadline.wait():
86+
case <-c.pipeDeadline.Wait():
8787
return 0, nil, os.ErrDeadlineExceeded
8888
}
8989
}
@@ -122,7 +122,7 @@ func (c *NetPacketConn) SetReadDeadline(t time.Time) error {
122122
return c.PacketConn.SetReadDeadline(t)
123123
}
124124
c.deadline.Store(t)
125-
c.pipeDeadline.set(t)
125+
c.pipeDeadline.Set(t)
126126
return nil
127127
}
128128

common/net/deadline/packet_enhance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ FOR:
5252
c.netPacketConn.resultCh <- nil
5353
break FOR
5454
}
55-
case <-c.netPacketConn.pipeDeadline.wait():
55+
case <-c.netPacketConn.pipeDeadline.Wait():
5656
return nil, nil, nil, os.ErrDeadlineExceeded
5757
}
5858
}

common/net/deadline/packet_sing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ FOR:
6969
c.netPacketConn.resultCh <- nil
7070
break FOR
7171
}
72-
case <-c.netPacketConn.pipeDeadline.wait():
72+
case <-c.netPacketConn.pipeDeadline.Wait():
7373
return M.Socksaddr{}, os.ErrDeadlineExceeded
7474
}
7575
}
@@ -146,7 +146,7 @@ FOR:
146146
c.netPacketConn.resultCh <- nil
147147
break FOR
148148
}
149-
case <-c.netPacketConn.pipeDeadline.wait():
149+
case <-c.netPacketConn.pipeDeadline.Wait():
150150
return nil, M.Socksaddr{}, os.ErrDeadlineExceeded
151151
}
152152
}

common/net/deadline/pipe.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ import (
99
"time"
1010
)
1111

12-
// pipeDeadline is an abstraction for handling timeouts.
13-
type pipeDeadline struct {
12+
// PipeDeadline is an abstraction for handling timeouts.
13+
type PipeDeadline struct {
1414
mu sync.Mutex // Guards timer and cancel
1515
timer *time.Timer
1616
cancel chan struct{} // Must be non-nil
1717
}
1818

19-
func makePipeDeadline() pipeDeadline {
20-
return pipeDeadline{cancel: make(chan struct{})}
19+
func MakePipeDeadline() PipeDeadline {
20+
return PipeDeadline{cancel: make(chan struct{})}
2121
}
2222

23-
// set sets the point in time when the deadline will time out.
23+
// Set sets the point in time when the deadline will time out.
2424
// A timeout event is signaled by closing the channel returned by waiter.
2525
// Once a timeout has occurred, the deadline can be refreshed by specifying a
2626
// t value in the future.
2727
//
2828
// A zero value for t prevents timeout.
29-
func (d *pipeDeadline) set(t time.Time) {
29+
func (d *PipeDeadline) Set(t time.Time) {
3030
d.mu.Lock()
3131
defer d.mu.Unlock()
3232

@@ -61,8 +61,8 @@ func (d *pipeDeadline) set(t time.Time) {
6161
}
6262
}
6363

64-
// wait returns a channel that is closed when the deadline is exceeded.
65-
func (d *pipeDeadline) wait() chan struct{} {
64+
// Wait returns a channel that is closed when the deadline is exceeded.
65+
func (d *PipeDeadline) Wait() chan struct{} {
6666
d.mu.Lock()
6767
defer d.mu.Unlock()
6868
return d.cancel

common/net/deadline/pipe_sing.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ type pipe struct {
3333
localDone chan struct{}
3434
remoteDone <-chan struct{}
3535

36-
readDeadline pipeDeadline
37-
writeDeadline pipeDeadline
36+
readDeadline PipeDeadline
37+
writeDeadline PipeDeadline
3838

3939
readWaitOptions N.ReadWaitOptions
4040
}
@@ -56,15 +56,15 @@ func Pipe() (net.Conn, net.Conn) {
5656
rdRx: cb1, rdTx: cn1,
5757
wrTx: cb2, wrRx: cn2,
5858
localDone: done1, remoteDone: done2,
59-
readDeadline: makePipeDeadline(),
60-
writeDeadline: makePipeDeadline(),
59+
readDeadline: MakePipeDeadline(),
60+
writeDeadline: MakePipeDeadline(),
6161
}
6262
p2 := &pipe{
6363
rdRx: cb2, rdTx: cn2,
6464
wrTx: cb1, wrRx: cn1,
6565
localDone: done2, remoteDone: done1,
66-
readDeadline: makePipeDeadline(),
67-
writeDeadline: makePipeDeadline(),
66+
readDeadline: MakePipeDeadline(),
67+
writeDeadline: MakePipeDeadline(),
6868
}
6969
return p1, p2
7070
}
@@ -86,7 +86,7 @@ func (p *pipe) read(b []byte) (n int, err error) {
8686
return 0, io.ErrClosedPipe
8787
case isClosedChan(p.remoteDone):
8888
return 0, io.EOF
89-
case isClosedChan(p.readDeadline.wait()):
89+
case isClosedChan(p.readDeadline.Wait()):
9090
return 0, os.ErrDeadlineExceeded
9191
}
9292

@@ -99,7 +99,7 @@ func (p *pipe) read(b []byte) (n int, err error) {
9999
return 0, io.ErrClosedPipe
100100
case <-p.remoteDone:
101101
return 0, io.EOF
102-
case <-p.readDeadline.wait():
102+
case <-p.readDeadline.Wait():
103103
return 0, os.ErrDeadlineExceeded
104104
}
105105
}
@@ -118,7 +118,7 @@ func (p *pipe) write(b []byte) (n int, err error) {
118118
return 0, io.ErrClosedPipe
119119
case isClosedChan(p.remoteDone):
120120
return 0, io.ErrClosedPipe
121-
case isClosedChan(p.writeDeadline.wait()):
121+
case isClosedChan(p.writeDeadline.Wait()):
122122
return 0, os.ErrDeadlineExceeded
123123
}
124124

@@ -134,7 +134,7 @@ func (p *pipe) write(b []byte) (n int, err error) {
134134
return n, io.ErrClosedPipe
135135
case <-p.remoteDone:
136136
return n, io.ErrClosedPipe
137-
case <-p.writeDeadline.wait():
137+
case <-p.writeDeadline.Wait():
138138
return n, os.ErrDeadlineExceeded
139139
}
140140
}
@@ -145,24 +145,24 @@ func (p *pipe) SetDeadline(t time.Time) error {
145145
if isClosedChan(p.localDone) || isClosedChan(p.remoteDone) {
146146
return io.ErrClosedPipe
147147
}
148-
p.readDeadline.set(t)
149-
p.writeDeadline.set(t)
148+
p.readDeadline.Set(t)
149+
p.writeDeadline.Set(t)
150150
return nil
151151
}
152152

153153
func (p *pipe) SetReadDeadline(t time.Time) error {
154154
if isClosedChan(p.localDone) || isClosedChan(p.remoteDone) {
155155
return io.ErrClosedPipe
156156
}
157-
p.readDeadline.set(t)
157+
p.readDeadline.Set(t)
158158
return nil
159159
}
160160

161161
func (p *pipe) SetWriteDeadline(t time.Time) error {
162162
if isClosedChan(p.localDone) || isClosedChan(p.remoteDone) {
163163
return io.ErrClosedPipe
164164
}
165-
p.writeDeadline.set(t)
165+
p.writeDeadline.Set(t)
166166
return nil
167167
}
168168

@@ -192,7 +192,7 @@ func (p *pipe) waitReadBuffer() (buffer *buf.Buffer, err error) {
192192
return nil, io.ErrClosedPipe
193193
case isClosedChan(p.remoteDone):
194194
return nil, io.EOF
195-
case isClosedChan(p.readDeadline.wait()):
195+
case isClosedChan(p.readDeadline.Wait()):
196196
return nil, os.ErrDeadlineExceeded
197197
}
198198
select {
@@ -211,7 +211,7 @@ func (p *pipe) waitReadBuffer() (buffer *buf.Buffer, err error) {
211211
return nil, io.ErrClosedPipe
212212
case <-p.remoteDone:
213213
return nil, io.EOF
214-
case <-p.readDeadline.wait():
214+
case <-p.readDeadline.Wait():
215215
return nil, os.ErrDeadlineExceeded
216216
}
217217
}

0 commit comments

Comments
 (0)