forked from andeya/erpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
790 lines (701 loc) · 19.9 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
// Copyright 2015-2017 HenryLee. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package tp
import (
"context"
"net/url"
"reflect"
"time"
"github.com/henrylee2cn/goutil"
"github.com/henrylee2cn/teleport/codec"
"github.com/henrylee2cn/teleport/socket"
"github.com/henrylee2cn/teleport/utils"
)
type (
// PreCtx context method set used before reading packet header.
PreCtx interface {
// Peer returns the peer.
Peer() Peer
// Session returns the session.
Session() Session
// Id returns the session id.
Id() string
// RealId returns the real remote id.
RealId() string
// Ip returns the remote addr.
Ip() string
// RealIp returns the the current real remote addr.
RealIp() string
// Public returns temporary public data of context.
Public() goutil.Map
// PublicLen returns the length of public data of context.
PublicLen() int
// Rerror returns the handle error.
Rerror() *Rerror
// Context carries a deadline, a cancelation signal, and other values across
// API boundaries.
Context() context.Context
}
// BaseCtx common context method set.
BaseCtx interface {
PreCtx
// Seq returns the input packet sequence.
Seq() uint64
// PeekMeta peeks the header metadata for the input packet.
PeekMeta(key string) []byte
// VisitMeta calls f for each existing metadata.
//
// f must not retain references to key and value after returning.
// Make key and/or value copies if you need storing them after returning.
VisitMeta(f func(key, value []byte))
// CopyMeta returns the input packet metadata copy.
CopyMeta() *utils.Args
// Uri returns the input packet uri.
Uri() string
// ChangeUri changes the input packet uri.
ChangeUri(string)
// Url returns the input packet uri object.
Url() *url.URL
// Path returns the input packet uri path.
Path() string
// Query returns the input packet uri query object.
Query() url.Values
}
// WriteCtx context method set for writing packet.
WriteCtx interface {
PreCtx
// Output returns writed packet.
Output() *socket.Packet
}
// ReadCtx context method set for reading packet.
ReadCtx interface {
BaseCtx
// Input returns readed packet.
Input() *socket.Packet
}
// PushCtx context method set for handling the pushed packet.
// For example:
// type HomePush struct{ PushCtx }
PushCtx interface {
BaseCtx
// GetBodyCodec gets the body codec type of the input packet.
GetBodyCodec() byte
}
// PullCtx context method set for handling the pulled packet.
// For example:
// type HomePull struct{ PullCtx }
PullCtx interface {
BaseCtx
// Input returns readed packet.
Input() *socket.Packet
// GetBodyCodec gets the body codec type of the input packet.
GetBodyCodec() byte
// Output returns writed packet.
Output() *socket.Packet
// SetBodyCodec sets the body codec for reply packet.
SetBodyCodec(byte)
// AddMeta adds the header metadata 'key=value' for reply packet.
// Multiple values for the same key may be added.
AddMeta(key, value string)
// SetMeta sets the header metadata 'key=value' for reply packet.
SetMeta(key, value string)
// AddXferPipe appends transfer filter pipe of reply packet.
AddXferPipe(filterId ...byte)
}
// UnknownPushCtx context method set for handling the unknown pushed packet.
UnknownPushCtx interface {
BaseCtx
// GetBodyCodec gets the body codec type of the input packet.
GetBodyCodec() byte
// InputBodyBytes if the input body binder is []byte type, returns it, else returns nil.
InputBodyBytes() []byte
// Bind when the raw body binder is []byte type, now binds the input body to v.
Bind(v interface{}) (bodyCodec byte, err error)
}
// UnknownPullCtx context method set for handling the unknown pulled packet.
UnknownPullCtx interface {
BaseCtx
// GetBodyCodec gets the body codec type of the input packet.
GetBodyCodec() byte
// InputBodyBytes if the input body binder is []byte type, returns it, else returns nil.
InputBodyBytes() []byte
// Bind when the raw body binder is []byte type, now binds the input body to v.
Bind(v interface{}) (bodyCodec byte, err error)
// SetBodyCodec sets the body codec for reply packet.
SetBodyCodec(byte)
// AddMeta adds the header metadata 'key=value' for reply packet.
// Multiple values for the same key may be added.
AddMeta(key, value string)
// SetMeta sets the header metadata 'key=value' for reply packet.
SetMeta(key, value string)
// AddXferPipe appends transfer filter pipe of reply packet.
AddXferPipe(filterId ...byte)
}
// readHandleCtx the underlying common instance of PullCtx and PushCtx.
readHandleCtx struct {
sess *session
input *socket.Packet
output *socket.Packet
handler *Handler
arg reflect.Value
pullCmd *pullCmd
public goutil.Map
start time.Time
cost time.Duration
pluginContainer *PluginContainer
handleErr *Rerror
context context.Context
next *readHandleCtx
}
)
var (
_ PreCtx = new(readHandleCtx)
_ BaseCtx = new(readHandleCtx)
_ WriteCtx = new(readHandleCtx)
_ ReadCtx = new(readHandleCtx)
_ PushCtx = new(readHandleCtx)
_ PullCtx = new(readHandleCtx)
_ UnknownPushCtx = new(readHandleCtx)
_ UnknownPullCtx = new(readHandleCtx)
)
var (
emptyValue = reflect.Value{}
emptyMethod = reflect.Method{}
)
// newReadHandleCtx creates a readHandleCtx for one request/response or push.
func newReadHandleCtx() *readHandleCtx {
c := new(readHandleCtx)
c.input = socket.NewPacket()
c.input.SetNewBody(c.binding)
c.output = socket.NewPacket()
return c
}
func (c *readHandleCtx) reInit(s *session) {
c.sess = s
count := s.socket.PublicLen()
c.public = goutil.RwMap(count)
if count > 0 {
s.socket.Public().Range(func(key, value interface{}) bool {
c.public.Store(key, value)
return true
})
}
}
func (c *readHandleCtx) clean() {
c.sess = nil
c.handler = nil
c.arg = emptyValue
c.pullCmd = nil
c.public = nil
c.cost = 0
c.pluginContainer = nil
c.handleErr = nil
c.context = nil
c.input.Reset(socket.WithNewBody(c.binding))
c.output.Reset()
}
// Peer returns the peer.
func (c *readHandleCtx) Peer() Peer {
return c.sess.peer
}
// Session returns the session.
func (c *readHandleCtx) Session() Session {
return c.sess
}
// Input returns readed packet.
func (c *readHandleCtx) Input() *socket.Packet {
return c.input
}
// Output returns writed packet.
func (c *readHandleCtx) Output() *socket.Packet {
return c.output
}
// Public returns temporary public data of context.
func (c *readHandleCtx) Public() goutil.Map {
return c.public
}
// PublicLen returns the length of public data of context.
func (c *readHandleCtx) PublicLen() int {
return c.public.Len()
}
// Seq returns the input packet sequence.
func (c *readHandleCtx) Seq() uint64 {
return c.input.Seq()
}
// Uri returns the input packet uri string.
func (c *readHandleCtx) Uri() string {
return c.input.Uri()
}
// ChangeUri changes the input packet uri.
func (c *readHandleCtx) ChangeUri(uri string) {
c.input.SetUri(uri)
}
// Url returns the input packet uri object.
func (c *readHandleCtx) Url() *url.URL {
return c.input.Url()
}
// Path returns the input packet uri path.
func (c *readHandleCtx) Path() string {
return c.input.Url().Path
}
// Query returns the input packet uri query object.
func (c *readHandleCtx) Query() url.Values {
return c.input.Url().Query()
}
// PeekMeta peeks the header metadata for the input packet.
func (c *readHandleCtx) PeekMeta(key string) []byte {
return c.input.Meta().Peek(key)
}
// VisitMeta calls f for each existing metadata.
//
// f must not retain references to key and value after returning.
// Make key and/or value copies if you need storing them after returning.
func (c *readHandleCtx) VisitMeta(f func(key, value []byte)) {
c.input.Meta().VisitAll(f)
}
// CopyMeta returns the input packet metadata copy.
func (c *readHandleCtx) CopyMeta() *utils.Args {
dst := utils.AcquireArgs()
c.input.Meta().CopyTo(dst)
return dst
}
// AddMeta adds the header metadata 'key=value' for reply packet.
// Multiple values for the same key may be added.
func (c *readHandleCtx) AddMeta(key, value string) {
c.output.Meta().Add(key, value)
}
// SetMeta sets the header metadata 'key=value' for reply packet.
func (c *readHandleCtx) SetMeta(key, value string) {
c.output.Meta().Set(key, value)
}
// GetBodyCodec gets the body codec type of the input packet.
func (c *readHandleCtx) GetBodyCodec() byte {
return c.input.BodyCodec()
}
// SetBodyCodec sets the body codec for reply packet.
func (c *readHandleCtx) SetBodyCodec(bodyCodec byte) {
c.output.SetBodyCodec(bodyCodec)
}
// AddXferPipe appends transfer filter pipe of reply packet.
func (c *readHandleCtx) AddXferPipe(filterId ...byte) {
c.output.XferPipe().Append(filterId...)
}
// Id returns the session id.
func (c *readHandleCtx) Id() string {
return c.sess.Id()
}
// RealId returns the current real remote id.
func (c *readHandleCtx) RealId() string {
realId := c.PeekMeta(MetaRealId)
if len(realId) > 0 {
return string(realId)
}
return c.sess.Id()
}
// Ip returns the remote addr.
func (c *readHandleCtx) Ip() string {
return c.sess.RemoteIp()
}
// RealIp returns the the current real remote addr.
func (c *readHandleCtx) RealIp() string {
realIp := c.PeekMeta(MetaRealIp)
if len(realIp) > 0 {
return string(realIp)
}
return c.sess.RemoteIp()
}
// Context carries a deadline, a cancelation signal, and other values across
// API boundaries.
func (c *readHandleCtx) Context() context.Context {
if c.context == nil {
return c.input.Context()
}
return c.context
}
// setContext sets the context for timeout.
func (c *readHandleCtx) setContext(ctx context.Context) {
c.context = ctx
}
// Be executed synchronously when reading packet
func (c *readHandleCtx) binding(header socket.Header) (body interface{}) {
c.start = c.sess.timeNow()
c.pluginContainer = c.sess.peer.pluginContainer
switch header.Ptype() {
case TypeReply:
return c.bindReply(header)
case TypePush:
return c.bindPush(header)
case TypePull:
return c.bindPull(header)
default:
c.handleErr = rerrCodeNotImplemented
return nil
}
}
// Be executed asynchronously after readed packet
func (c *readHandleCtx) handle() {
if c.handleErr != nil && c.handleErr.Code == CodeNotImplemented {
goto E
}
switch c.input.Ptype() {
case TypeReply:
// handles pull reply
c.handleReply()
return
case TypePush:
// handles push
c.handlePush()
return
case TypePull:
// handles and replies pull
c.handlePull()
return
default:
}
E:
// if unsupported, disconnected.
rerrCodeNotImplemented.SetToMeta(c.output.Meta())
if c.sess.peer.printBody {
logformat := "disconnect(%s) due to unsupported packet type: %d |\nseq: %d |uri: %-30s |\nRECV:\n size: %d\n body[-json]: %s\n"
Errorf(logformat, c.Ip(), c.input.Ptype(), c.input.Seq(), c.input.Uri(), c.input.Size(), bodyLogBytes(c.input))
} else {
logformat := "disconnect(%s) due to unsupported packet type: %d |\nseq: %d |uri: %-30s |\nRECV:\n size: %d\n"
Errorf(logformat, c.Ip(), c.input.Ptype(), c.input.Seq(), c.input.Uri(), c.input.Size())
}
go c.sess.Close()
}
func (c *readHandleCtx) bindPush(header socket.Header) interface{} {
c.handleErr = c.pluginContainer.PostReadPushHeader(c)
if c.handleErr != nil {
return nil
}
u := header.Url()
if len(u.Path) == 0 {
c.handleErr = rerrBadPacket.Copy()
c.handleErr.Detail = "invalid URI for packet"
return nil
}
var ok bool
c.handler, ok = c.sess.getPushHandler(u.Path)
if !ok {
c.handleErr = rerrNotFound
return nil
}
c.pluginContainer = c.handler.pluginContainer
c.arg = c.handler.NewArgValue()
c.input.SetBody(c.arg.Interface())
c.handleErr = c.pluginContainer.PreReadPushBody(c)
if c.handleErr != nil {
return nil
}
return c.input.Body()
}
// handlePush handles push.
func (c *readHandleCtx) handlePush() {
if age := c.sess.ContextAge(); age > 0 {
ctxTimout, _ := context.WithTimeout(context.Background(), age)
c.setContext(ctxTimout)
}
defer func() {
c.cost = c.sess.timeSince(c.start)
c.sess.runlog(c.cost, c.input, nil, typePushHandle)
}()
if c.handleErr == nil && c.handler != nil {
if c.pluginContainer.PostReadPushBody(c) == nil {
if c.handler.isUnknown {
c.handler.unknownHandleFunc(c)
} else {
c.handler.handleFunc(c, c.arg)
}
}
}
if c.handleErr != nil {
Warnf("%s", c.handleErr.String())
}
}
func (c *readHandleCtx) bindPull(header socket.Header) interface{} {
c.output.SetSeq(header.Seq())
c.output.SetUri(header.Uri())
c.handleErr = c.pluginContainer.PostReadPullHeader(c)
if c.handleErr != nil {
c.handleErr.SetToMeta(c.output.Meta())
return nil
}
u := header.Url()
if len(u.Path) == 0 {
c.handleErr = rerrBadPacket.Copy()
c.handleErr.Detail = "invalid URI for packet"
c.handleErr.SetToMeta(c.output.Meta())
return nil
}
var ok bool
c.handler, ok = c.sess.getPullHandler(u.Path)
if !ok {
c.handleErr = rerrNotFound
c.handleErr.SetToMeta(c.output.Meta())
return nil
}
c.pluginContainer = c.handler.pluginContainer
if c.handler.isUnknown {
c.input.SetBody(new([]byte))
} else {
c.arg = c.handler.NewArgValue()
c.input.SetBody(c.arg.Interface())
}
c.handleErr = c.pluginContainer.PreReadPullBody(c)
if c.handleErr != nil {
c.handleErr.SetToMeta(c.output.Meta())
return nil
}
return c.input.Body()
}
// handlePull handles and replies pull.
func (c *readHandleCtx) handlePull() {
if age := c.sess.ContextAge(); age > 0 {
ctxTimout, _ := context.WithTimeout(c.input.Context(), age)
c.setContext(ctxTimout)
socket.WithContext(ctxTimout)(c.output)
}
defer func() {
c.cost = c.sess.timeSince(c.start)
c.sess.runlog(c.cost, c.input, c.output, typePullHandle)
}()
// set packet type
c.output.SetPtype(TypeReply)
// copy transfer filter pipe
c.output.AppendXferPipeFrom(c.input)
if c.handleErr == nil {
c.handleErr = NewRerrorFromMeta(c.output.Meta())
}
// handle pull
if c.handleErr == nil {
c.handleErr = c.pluginContainer.PostReadPullBody(c)
if c.handleErr != nil {
c.handleErr.SetToMeta(c.output.Meta())
} else {
if c.handler.isUnknown {
c.handler.unknownHandleFunc(c)
} else {
c.handler.handleFunc(c, c.arg)
}
}
}
// reply pull
rerr := c.pluginContainer.PreWriteReply(c)
if rerr == nil {
c.handleErr = rerr
}
rerr = c.sess.write(c.output)
if rerr != nil {
if c.handleErr == nil {
c.handleErr = rerr
}
// rerr.SetToMeta(c.output.Meta())
return
}
rerr = c.pluginContainer.PostWriteReply(c)
if c.handleErr == nil {
c.handleErr = rerr
}
}
func (c *readHandleCtx) bindReply(header socket.Header) interface{} {
_pullCmd, ok := c.sess.pullCmdMap.Load(header.Seq())
if !ok {
Warnf("not found pull cmd: %v", c.input)
return nil
}
c.pullCmd = _pullCmd.(*pullCmd)
c.public = c.pullCmd.public
c.pullCmd.inputMeta = c.CopyMeta()
c.setContext(c.pullCmd.output.Context())
rerr := c.pluginContainer.PostReadReplyHeader(c)
if rerr != nil {
c.pullCmd.rerr = rerr
return nil
}
rerr = c.pluginContainer.PreReadReplyBody(c)
if rerr != nil {
c.pullCmd.rerr = rerr
return nil
}
return c.pullCmd.reply
}
// handleReply handles pull reply.
func (c *readHandleCtx) handleReply() {
if c.pullCmd == nil {
return
}
defer func() {
c.handleErr = c.pullCmd.rerr
c.pullCmd.done()
c.pullCmd.cost = c.sess.timeSince(c.pullCmd.start)
c.sess.runlog(c.pullCmd.cost, c.input, c.pullCmd.output, typePullLaunch)
}()
if c.pullCmd.rerr != nil {
return
}
rerr := NewRerrorFromMeta(c.input.Meta())
if rerr == nil {
rerr = c.pluginContainer.PostReadReplyBody(c)
}
c.pullCmd.rerr = rerr
}
// Rerror returns the handle error.
func (c *readHandleCtx) Rerror() *Rerror {
return c.handleErr
}
// InputBodyBytes if the input body binder is []byte type, returns it, else returns nil.
func (c *readHandleCtx) InputBodyBytes() []byte {
b, ok := c.input.Body().(*[]byte)
if !ok {
return nil
}
return *b
}
// Bind when the raw body binder is []byte type, now binds the input body to v.
func (c *readHandleCtx) Bind(v interface{}) (byte, error) {
b := c.InputBodyBytes()
if b == nil {
return codec.NilCodecId, nil
}
c.input.SetBody(v)
err := c.input.UnmarshalBody(b)
return c.input.BodyCodec(), err
}
type (
// PullCmd the command of the pulling operation's response.
PullCmd interface {
// Peer returns the peer.
Peer() Peer
// Session returns the session.
Session() Session
// Id returns the session id.
Id() string
// RealId returns the real remote id.
RealId() string
// Ip returns the remote addr.
Ip() string
// RealIp returns the the current real remote addr.
RealIp() string
// Public returns temporary public data of context.
Public() goutil.Map
// PublicLen returns the length of public data of context.
PublicLen() int
// Output returns writed packet.
Output() *socket.Packet
// Context carries a deadline, a cancelation signal, and other values across
// API boundaries.
Context() context.Context
// Result returns the pull result.
Result() (interface{}, *Rerror)
// Rerror returns the pull error.
Rerror() *Rerror
// InputMeta returns the header metadata of input packet.
InputMeta() *utils.Args
// CostTime returns the pulled cost time.
// If PeerConfig.CountTime=false, always returns 0.
CostTime() time.Duration
}
pullCmd struct {
sess *session
output *socket.Packet
reply interface{}
rerr *Rerror
inputMeta *utils.Args
doneChan chan PullCmd // Strobes when pull is complete.
start time.Time
cost time.Duration
public goutil.Map
}
)
var _ WriteCtx = PullCmd(nil)
// Peer returns the peer.
func (p *pullCmd) Peer() Peer {
return p.sess.peer
}
// Session returns the session.
func (p *pullCmd) Session() Session {
return p.sess
}
// Id returns the session id.
func (p *pullCmd) Id() string {
return p.sess.Id()
}
// RealId returns the current real remote id.
func (p *pullCmd) RealId() string {
realId := p.inputMeta.Peek(MetaRealId)
if len(realId) > 0 {
return string(realId)
}
return p.sess.Id()
}
// Ip returns the remote addr.
func (p *pullCmd) Ip() string {
return p.sess.RemoteIp()
}
// RealIp returns the the current real remote addr.
func (p *pullCmd) RealIp() string {
realIp := p.inputMeta.Peek(MetaRealIp)
if len(realIp) > 0 {
return string(realIp)
}
return p.sess.RemoteIp()
}
// Public returns temporary public data of context.
func (p *pullCmd) Public() goutil.Map {
return p.public
}
// PublicLen returns the length of public data of context.
func (p *pullCmd) PublicLen() int {
return p.public.Len()
}
// Output returns writed packet.
func (p *pullCmd) Output() *socket.Packet {
return p.output
}
// Context carries a deadline, a cancelation signal, and other values across
// API boundaries.
func (p *pullCmd) Context() context.Context {
return p.output.Context()
}
// Result returns the pull result.
func (p *pullCmd) Result() (interface{}, *Rerror) {
return p.reply, p.rerr
}
// Rerror returns the pull error.
func (p *pullCmd) Rerror() *Rerror {
return p.rerr
}
// InputMeta returns the header metadata of input packet.
func (p *pullCmd) InputMeta() *utils.Args {
return p.inputMeta
}
// CostTime returns the pulled cost time.
// If PeerConfig.CountTime=false, always returns 0.
func (p *pullCmd) CostTime() time.Duration {
return p.cost
}
func (p *pullCmd) cancel() {
p.sess.pullCmdMap.Delete(p.output.Seq())
p.rerr = rerrConnClosed
p.doneChan <- p
// free count pull-launch
p.sess.gracepullCmdWaitGroup.Done()
}
func (p *pullCmd) done() {
p.sess.pullCmdMap.Delete(p.output.Seq())
p.doneChan <- p
// free count pull-launch
p.sess.gracepullCmdWaitGroup.Done()
}