-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用 server.WithMuxTransport() 时报错 #1105
Comments
这是代码bug gonet.bufioConn (定义在github.com/cloudwego/kitex/pkg/remote/trans/gonet/trans_server.go)没有实现 AddCloseCallback gonet.bufioConn 的定义: // bufioConn implements the net.Conn interface.
type bufioConn struct {
conn net.Conn
r netpoll.Reader
}
func newBufioConn(c net.Conn) *bufioConn {
return &bufioConn{
conn: c,
r: netpoll.NewReader(c),
}
}
func (bc *bufioConn) RawConn() net.Conn {
return bc.conn
}
func (bc *bufioConn) Read(b []byte) (int, error) {
buf, err := bc.r.Next(len(b))
if err != nil {
return 0, err
}
copy(b, buf)
return len(b), nil
}
func (bc *bufioConn) Write(b []byte) (int, error) {
return bc.conn.Write(b)
}
func (bc *bufioConn) Close() error {
bc.r.Release()
return bc.conn.Close()
}
func (bc *bufioConn) LocalAddr() net.Addr {
return bc.conn.LocalAddr()
}
func (bc *bufioConn) RemoteAddr() net.Addr {
return bc.conn.RemoteAddr()
}
func (bc *bufioConn) SetDeadline(t time.Time) error {
return bc.conn.SetDeadline(t)
}
func (bc *bufioConn) SetReadDeadline(t time.Time) error {
return bc.conn.SetReadDeadline(t)
}
func (bc *bufioConn) SetWriteDeadline(t time.Time) error {
return bc.conn.SetWriteDeadline(t)
}
func (bc *bufioConn) Reader() netpoll.Reader {
return bc.r
} 而 netpoll.Connection 的声明为: // CloseCallback will be called when the connection is closed.
// Return: error is unused which will be ignored directly.
type CloseCallback func(connection Connection) error
// Connection supports reading and writing simultaneously,
// but does not support simultaneous reading or writing by multiple goroutines.
// It maintains its own input/output buffer, and provides nocopy API for reading and writing.
type Connection interface {
// Connection extends net.Conn, just for interface compatibility.
// It's not recommended to use net.Conn API except for io.Closer.
net.Conn
// The recommended API for nocopy reading and writing.
// Reader will return nocopy buffer data, or error after timeout which set by SetReadTimeout.
Reader() Reader
// Writer will write data to the connection by NIO mode,
// so it will return an error only when the connection isn't Active.
Writer() Writer
// IsActive checks whether the connection is active or not.
IsActive() bool
// SetReadTimeout sets the timeout for future Read calls wait.
// A zero value for timeout means Reader will not timeout.
SetReadTimeout(timeout time.Duration) error
// SetWriteTimeout sets the timeout for future Write calls wait.
// A zero value for timeout means Writer will not timeout.
SetWriteTimeout(timeout time.Duration) error
// SetIdleTimeout sets the idle timeout of connections.
// Idle connections that exceed the set timeout are no longer guaranteed to be active,
// but can be checked by calling IsActive.
SetIdleTimeout(timeout time.Duration) error
// SetOnRequest can set or replace the OnRequest method for a connection, but can't be set to nil.
// Although SetOnRequest avoids data race, it should still be used before transmitting data.
// Replacing OnRequest while processing data may cause unexpected behavior and results.
// Generally, the server side should uniformly set the OnRequest method for each connection via NewEventLoop,
// which is set when the connection is initialized.
// On the client side, if necessary, make sure that OnRequest is set before sending data.
SetOnRequest(on OnRequest) error
// AddCloseCallback can add hangup callback for a connection, which will be called when connection closing.
// This is very useful for cleaning up idle connections. For instance, you can use callbacks to clean up
// the local resources, which bound to the idle connection, when hangup by the peer. No need another goroutine
// to polling check connection status.
AddCloseCallback(callback CloseCallback) error
} |
windows 不支持WithMuxTransport() |
@zhangsilly 是的,windows 下目前是 fallback 到 go net,对 mux 不支持 |
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NewService() 启用 server.WithMuxTransport() 后第一次调用时报错
To Reproduce
Steps to reproduce the behavior:
服务端代码:
客户端代码:
Expected behavior
代码正常运行
Screenshots
Kitex version:
Kitex v0.7.1
Environment:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: