@@ -91,7 +91,7 @@ type Client struct {
91
91
conn NetworkConn
92
92
93
93
creds []authCreds
94
- watchers map [watchPathType ][]func (ev clientWatchEvent )
94
+ watchers map [watchPathType ][]func (ev Event )
95
95
// =================================
96
96
97
97
wg sync.WaitGroup
@@ -176,15 +176,9 @@ type handleEvent struct {
176
176
req clientRequest
177
177
}
178
178
179
- type clientWatchEvent struct {
180
- Type EventType
181
- State State
182
- Path string // For non-session events, the path of the watched node.
183
- }
184
-
185
179
type clientWatchRequest struct {
186
180
pathType watchPathType
187
- callback func (ev clientWatchEvent )
181
+ callback func (ev Event )
188
182
}
189
183
190
184
// NetworkConn for connections when connecting to zookeeper.
@@ -233,7 +227,7 @@ func newClientInternal(servers []string, sessionTimeout time.Duration, options .
233
227
234
228
recvMap : map [int32 ]clientRequest {},
235
229
236
- watchers : map [watchPathType ][]func (ev clientWatchEvent ){},
230
+ watchers : map [watchPathType ][]func (ev Event ){},
237
231
238
232
pingSignalChan : make (chan struct {}, 10 ),
239
233
pingCloseChan : make (chan struct {}),
@@ -596,7 +590,7 @@ func (c *Client) authenticate(conn NetworkConn) error {
596
590
c .appendHandleQueueGlobalEvent (c .sessExpiredCallback )
597
591
}
598
592
599
- c .watchers = map [watchPathType ][]func (ev clientWatchEvent ){}
593
+ c .watchers = map [watchPathType ][]func (ev Event ){}
600
594
601
595
c .mut .Unlock ()
602
596
@@ -1009,7 +1003,7 @@ func (c *Client) handleNormalResponse(res responseHeader, buf []byte, blen int)
1009
1003
}
1010
1004
1011
1005
output := connNormal ()
1012
- if res .Err == errSessionExpired {
1006
+ if res .Err == errSessionExpired || res . Err == errSessionMoved || res . Err == errClosing {
1013
1007
err = ErrConnectionClosed
1014
1008
output = connError (err )
1015
1009
}
@@ -1027,7 +1021,7 @@ func (c *Client) handleWatchEvent(buf []byte, blen int, res responseHeader) conn
1027
1021
log .Panicf ("Unable to decode watch event, err: %v" , err )
1028
1022
}
1029
1023
1030
- ev := clientWatchEvent {
1024
+ ev := Event {
1031
1025
Type : watchResp .Type ,
1032
1026
State : watchResp .State ,
1033
1027
Path : watchResp .Path ,
@@ -1037,7 +1031,7 @@ func (c *Client) handleWatchEvent(buf []byte, blen int, res responseHeader) conn
1037
1031
defer c .mut .Unlock ()
1038
1032
1039
1033
watchTypes := computeWatchTypes (watchResp .Type )
1040
- var callbacks []func (ev clientWatchEvent )
1034
+ var callbacks []func (ev Event )
1041
1035
for _ , wType := range watchTypes {
1042
1036
wpt := watchPathType {path : ev .Path , wType : wType }
1043
1037
callbacks = append (callbacks , c .watchers [wpt ]... )
@@ -1049,7 +1043,7 @@ func (c *Client) handleWatchEvent(buf []byte, blen int, res responseHeader) conn
1049
1043
opcode : opWatcherEvent ,
1050
1044
response : & ev ,
1051
1045
callback : func (res any , zxid int64 , err error ) {
1052
- ev := res .(* clientWatchEvent )
1046
+ ev := res .(* Event )
1053
1047
for _ , cb := range callbacks {
1054
1048
cb (* ev )
1055
1049
}
@@ -1184,12 +1178,8 @@ func (c *Client) Children(
1184
1178
path : path ,
1185
1179
wType : watchTypeChild ,
1186
1180
},
1187
- callback : func (ev clientWatchEvent ) {
1188
- opts .watchCallback (Event {
1189
- Type : ev .Type ,
1190
- State : ev .State ,
1191
- Path : ev .Path ,
1192
- })
1181
+ callback : func (ev Event ) {
1182
+ opts .watchCallback (ev )
1193
1183
},
1194
1184
}
1195
1185
}
@@ -1273,12 +1263,8 @@ func (c *Client) Get(
1273
1263
path : path ,
1274
1264
wType : watchTypeData ,
1275
1265
},
1276
- callback : func (ev clientWatchEvent ) {
1277
- opts .watchCallback (Event {
1278
- Type : ev .Type ,
1279
- State : ev .State ,
1280
- Path : ev .Path ,
1281
- })
1266
+ callback : func (ev Event ) {
1267
+ opts .watchCallback (ev )
1282
1268
},
1283
1269
}
1284
1270
}
@@ -1396,12 +1382,8 @@ func (c *Client) Exists(
1396
1382
path : path ,
1397
1383
wType : watchTypeExist ,
1398
1384
},
1399
- callback : func (ev clientWatchEvent ) {
1400
- opts .watchCallback (Event {
1401
- Type : ev .Type ,
1402
- State : ev .State ,
1403
- Path : ev .Path ,
1404
- })
1385
+ callback : func (ev Event ) {
1386
+ opts .watchCallback (ev )
1405
1387
},
1406
1388
}
1407
1389
}
0 commit comments