Skip to content

Commit b50142b

Browse files
committed
chore:
1 parent d6c452d commit b50142b

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

conn.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ func newConn(fd int, safeConns *core.SafeConns[Conn],
6666
func (c *Conn) Close() {
6767
c.mu.Lock()
6868
defer c.mu.Unlock()
69-
c.close()
69+
c.closeNoLock()
7070
}
7171

72-
func (c *Conn) close() {
72+
func (c *Conn) closeNoLock() {
7373
if atomic.LoadInt64(&c.fd) == -1 {
7474
return
7575
}
@@ -220,14 +220,14 @@ func (c *Conn) Write(data []byte) (int, error) {
220220
}
221221
// 把剩余数据放到缓冲区
222222
if err := c.handlePartialWrite(&data, n, true); err != nil {
223-
c.close()
223+
c.closeNoLock()
224224
return 0, err
225225
}
226226
return len(data), nil
227227
}
228228

229229
// 发生严重错误
230-
c.close()
230+
c.closeNoLock()
231231
return n, err
232232
}
233233

@@ -248,7 +248,7 @@ func (c *Conn) Write(data []byte) (int, error) {
248248
}
249249
// 移动剩余数据到缓冲区开始位置
250250
if err := c.handlePartialWrite(wbuf, n, false); err != nil {
251-
c.close()
251+
c.closeNoLock()
252252
return 0, err
253253
}
254254

@@ -258,7 +258,7 @@ func (c *Conn) Write(data []byte) (int, error) {
258258
return len(data), nil
259259
}
260260

261-
c.close()
261+
c.closeNoLock()
262262
return n, err
263263
}
264264

@@ -372,15 +372,15 @@ func (c *Conn) setReadDeadlineCore(t time.Time) error {
372372
// Create new timer
373373
duration := time.Until(t)
374374
if duration <= 0 {
375-
c.close()
375+
c.closeNoLock()
376376
return nil
377377
}
378378

379379
c.readTimer = time.AfterFunc(duration, func() {
380380
c.mu.Lock()
381381
defer c.mu.Unlock()
382382
if atomic.LoadInt64(&c.fd) != -1 {
383-
c.close()
383+
c.closeNoLock()
384384
}
385385
})
386386

@@ -413,15 +413,15 @@ func (c *Conn) setWriteDeadlineCore(t time.Time) error {
413413
// Create new timer
414414
duration := time.Until(t)
415415
if duration <= 0 {
416-
c.close()
416+
c.closeNoLock()
417417
return nil
418418
}
419419

420420
c.writeTimer = time.AfterFunc(duration, func() {
421421
c.mu.Lock()
422422
defer c.mu.Unlock()
423423
if atomic.LoadInt64(&c.fd) != -1 {
424-
c.close()
424+
c.closeNoLock()
425425
}
426426
})
427427

conn_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestConn_SetDeadline(t *testing.T) {
157157
readBufferSize: 4096,
158158
safeConns: &core.SafeConns[Conn]{},
159159
}
160-
conn.close()
160+
conn.closeNoLock()
161161
err = conn.SetDeadline(time.Now().Add(time.Second))
162162
if err == nil {
163163
t.Error("SetDeadline() should return error when connection is closed")
@@ -250,7 +250,7 @@ func TestConn_SetReadDeadline(t *testing.T) {
250250
readBufferSize: 4096,
251251
safeConns: &core.SafeConns[Conn]{},
252252
}
253-
conn.close()
253+
conn.closeNoLock()
254254
err = conn.SetReadDeadline(time.Now().Add(time.Second))
255255
if err == nil {
256256
t.Error("SetReadDeadline() should return error when connection is closed")
@@ -343,7 +343,7 @@ func TestConn_SetWriteDeadline(t *testing.T) {
343343
readBufferSize: 4096,
344344
safeConns: &core.SafeConns[Conn]{},
345345
}
346-
conn.close()
346+
conn.closeNoLock()
347347
err = conn.SetWriteDeadline(time.Now().Add(time.Second))
348348
if err == nil {
349349
t.Error("SetWriteDeadline() should return error when connection is closed")

0 commit comments

Comments
 (0)