File tree Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -25,16 +25,24 @@ import (
2525type ConnState uint32
2626
2727const (
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.
3338type 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.
3846func ListenConnState (conn net.Conn ) (ConnStater , error ) {
3947 pollInitOnce .Do (createPoller )
4048 sysConn , ok := conn .(syscall.Conn )
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
3333var pollcache pollCache
You can’t perform that action at this time.
0 commit comments