@@ -37,14 +37,19 @@ type ProtocolListener interface {
3737}
3838
3939// ProtocolListenerFunc returns a ProtocolListener based on the configuration it was given.
40- type ProtocolListenerFunc func (cfg mysql.ListenerConfig , sel ServerEventListener ) (ProtocolListener , error )
41-
42- // DefaultProtocolListenerFunc is the protocol listener, which defaults to Vitess' protocol listener. Changing
43- // this function will change the protocol listener used when creating all servers. If multiple servers are needed
44- // with different protocols, then create each server after changing this function. Servers retain the protocol that
45- // they were created with.
46- var DefaultProtocolListenerFunc ProtocolListenerFunc = func (cfg mysql.ListenerConfig , sel ServerEventListener ) (ProtocolListener , error ) {
47- return mysql .NewListenerWithConfig (cfg )
40+ type ProtocolListenerFunc func (cfg Config , listenerCfg mysql.ListenerConfig , sel ServerEventListener ) (ProtocolListener , error )
41+
42+ func MySQLProtocolListenerFactory (cfg Config , listenerCfg mysql.ListenerConfig , sel ServerEventListener ) (ProtocolListener , error ) {
43+ vtListener , err := mysql .NewListenerWithConfig (listenerCfg )
44+ if err != nil {
45+ return nil , err
46+ }
47+ if cfg .Version != "" {
48+ vtListener .ServerVersion = cfg .Version
49+ }
50+ vtListener .TLSConfig = cfg .TLSConfig
51+ vtListener .RequireSecureTransport = cfg .RequireSecureTransport
52+ return vtListener , nil
4853}
4954
5055type ServerEventListener interface {
@@ -114,10 +119,6 @@ func portInUse(hostPort string) bool {
114119}
115120
116121func newServerFromHandler (cfg Config , e * sqle.Engine , sm * SessionManager , handler mysql.Handler , sel ServerEventListener ) (* Server , error ) {
117- for _ , option := range cfg .Options {
118- option (e , sm , handler )
119- }
120-
121122 if cfg .ConnReadTimeout < 0 {
122123 cfg .ConnReadTimeout = 0
123124 }
@@ -156,19 +157,15 @@ func newServerFromHandler(cfg Config, e *sqle.Engine, sm *SessionManager, handle
156157 ConnReadBufferSize : mysql .DefaultConnBufferSize ,
157158 AllowClearTextWithoutTLS : cfg .AllowClearTextWithoutTLS ,
158159 }
159- protocolListener , err := DefaultProtocolListenerFunc (listenerCfg , sel )
160+ plf := cfg .ProtocolListenerFactory
161+ if plf == nil {
162+ plf = MySQLProtocolListenerFactory
163+ }
164+ protocolListener , err := plf (cfg , listenerCfg , sel )
160165 if err != nil {
161166 return nil , err
162167 }
163168
164- if vtListener , ok := protocolListener .(* mysql.Listener ); ok {
165- if cfg .Version != "" {
166- vtListener .ServerVersion = cfg .Version
167- }
168- vtListener .TLSConfig = cfg .TLSConfig
169- vtListener .RequireSecureTransport = cfg .RequireSecureTransport
170- }
171-
172169 return & Server {
173170 Listener : protocolListener ,
174171 handler : handler ,
0 commit comments