Skip to content

Commit 487a4f7

Browse files
committed
fix: bugs
1 parent c4afa26 commit 487a4f7

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

connstate/conn.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,24 @@ import (
2525
type ConnState uint32
2626

2727
const (
28+
// StateOK means the connection is normal.
2829
StateOK ConnState = iota
30+
// StateRemoteClosed means the remote side has closed the connection.
2931
StateRemoteClosed
32+
// StateClosed means the connection has been closed by local side.
3033
StateClosed
3134
)
3235

36+
// ConnStater is the interface to get the ConnState of a connection.
37+
// Must call Close to release it if you're going to close the connection.
3338
type ConnStater interface {
3439
Close() error
3540
State() ConnState
3641
}
3742

43+
// ListenConnState returns a ConnStater for the given connection.
44+
// It's generally used for availability checks when obtaining connections from a connection pool.
45+
// Conn must be a syscall.Conn.
3846
func ListenConnState(conn net.Conn) (ConnStater, error) {
3947
pollInitOnce.Do(createPoller)
4048
sysConn, ok := conn.(syscall.Conn)

connstate/conn_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2025 CloudWeGo Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package connstate

connstate/poll.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ func createPoller() {
4242
if err != nil {
4343
panic(fmt.Sprintf("gopkg.connstate openpoll failed, err: %v", err))
4444
}
45-
go poll.wait()
45+
go func() {
46+
err := poll.wait()
47+
fmt.Printf("gopkg.connstate epoll wait exit, err: %v\n", err)
48+
}()
4649
}

connstate/poll_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type fdOperator struct {
2727
index int32
2828

2929
fd int
30-
conn unsafe.Pointer // *connWithState
30+
conn unsafe.Pointer // *connStater
3131
}
3232

3333
var pollcache pollCache

0 commit comments

Comments
 (0)