-
Notifications
You must be signed in to change notification settings - Fork 151
/
conn.go
777 lines (691 loc) · 19.1 KB
/
conn.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
package tao
import (
"context"
"crypto/tls"
"net"
"sync"
"time"
"github.com/leesper/holmes"
)
const (
// MessageTypeBytes is the length of type header.
MessageTypeBytes = 4
// MessageLenBytes is the length of length header.
MessageLenBytes = 4
// MessageMaxBytes is the maximum bytes allowed for application data.
MessageMaxBytes = 1 << 23 // 8M
)
// MessageHandler is a combination of message and its handler function.
type MessageHandler struct {
message Message
handler HandlerFunc
}
// WriteCloser is the interface that groups Write and Close methods.
type WriteCloser interface {
Write(Message) error
Close()
}
// ServerConn represents a server connection to a TCP server, it implments Conn.
type ServerConn struct {
netid int64
belong *Server
rawConn net.Conn
once *sync.Once
wg *sync.WaitGroup
sendCh chan []byte
handlerCh chan MessageHandler
timerCh chan *OnTimeOut
mu sync.Mutex // guards following
name string
heart int64
pending []int64
ctx context.Context
cancel context.CancelFunc
}
// NewServerConn returns a new server connection which has not started to
// serve requests yet.
func NewServerConn(id int64, s *Server, c net.Conn) *ServerConn {
sc := &ServerConn{
netid: id,
belong: s,
rawConn: c,
once: &sync.Once{},
wg: &sync.WaitGroup{},
sendCh: make(chan []byte, s.opts.bufferSize),
handlerCh: make(chan MessageHandler, s.opts.bufferSize),
timerCh: make(chan *OnTimeOut, s.opts.bufferSize),
heart: time.Now().UnixNano(),
}
sc.ctx, sc.cancel = context.WithCancel(context.WithValue(s.ctx, serverCtx, s))
sc.name = c.RemoteAddr().String()
sc.pending = []int64{}
return sc
}
// ServerFromContext returns the server within the context.
func ServerFromContext(ctx context.Context) (*Server, bool) {
server, ok := ctx.Value(serverCtx).(*Server)
return server, ok
}
// NetID returns net ID of server connection.
func (sc *ServerConn) NetID() int64 {
return sc.netid
}
// SetName sets name of server connection.
func (sc *ServerConn) SetName(name string) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.name = name
}
// Name returns the name of server connection.
func (sc *ServerConn) Name() string {
sc.mu.Lock()
defer sc.mu.Unlock()
name := sc.name
return name
}
// SetHeartBeat sets the heart beats of server connection.
func (sc *ServerConn) SetHeartBeat(heart int64) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.heart = heart
}
// HeartBeat returns the heart beats of server connection.
func (sc *ServerConn) HeartBeat() int64 {
sc.mu.Lock()
defer sc.mu.Unlock()
heart := sc.heart
return heart
}
// SetContextValue sets extra data to server connection.
func (sc *ServerConn) SetContextValue(k, v interface{}) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.ctx = context.WithValue(sc.ctx, k, v)
}
// ContextValue gets extra data from server connection.
func (sc *ServerConn) ContextValue(k interface{}) interface{} {
sc.mu.Lock()
defer sc.mu.Unlock()
return sc.ctx.Value(k)
}
// Start starts the server connection, creating go-routines for reading,
// writing and handlng.
func (sc *ServerConn) Start() {
holmes.Infof("conn start, <%v -> %v>\n", sc.rawConn.LocalAddr(), sc.rawConn.RemoteAddr())
onConnect := sc.belong.opts.onConnect
if onConnect != nil {
onConnect(sc)
}
loopers := []func(WriteCloser, *sync.WaitGroup){readLoop, writeLoop, handleLoop}
for _, l := range loopers {
looper := l
sc.wg.Add(1)
go looper(sc, sc.wg)
}
}
// Close gracefully closes the server connection. It blocked until all sub
// go-routines are completed and returned.
func (sc *ServerConn) Close() {
sc.once.Do(func() {
holmes.Infof("conn close gracefully, <%v -> %v>\n", sc.rawConn.LocalAddr(), sc.rawConn.RemoteAddr())
// callback on close
onClose := sc.belong.opts.onClose
if onClose != nil {
onClose(sc)
}
// remove connection from server
sc.belong.conns.Delete(sc.netid)
addTotalConn(-1)
// close net.Conn, any blocked read or write operation will be unblocked and
// return errors.
if tc, ok := sc.rawConn.(*net.TCPConn); ok {
// avoid time-wait state
tc.SetLinger(0)
}
sc.rawConn.Close()
// cancel readLoop, writeLoop and handleLoop go-routines.
sc.mu.Lock()
sc.cancel()
pending := sc.pending
sc.pending = nil
sc.mu.Unlock()
// clean up pending timers
for _, id := range pending {
sc.CancelTimer(id)
}
// wait until all go-routines exited.
sc.wg.Wait()
// close all channels and block until all go-routines exited.
close(sc.sendCh)
close(sc.handlerCh)
close(sc.timerCh)
// tell server I'm done :( .
sc.belong.wg.Done()
})
}
// AddPendingTimer adds a timer ID to server Connection.
func (sc *ServerConn) AddPendingTimer(timerID int64) {
sc.mu.Lock()
defer sc.mu.Unlock()
if sc.pending != nil {
sc.pending = append(sc.pending, timerID)
}
}
// Write writes a message to the client.
func (sc *ServerConn) Write(message Message) error {
return asyncWrite(sc, message)
}
// RunAt runs a callback at the specified timestamp.
func (sc *ServerConn) RunAt(timestamp time.Time, callback func(time.Time, WriteCloser)) int64 {
id := runAt(sc.ctx, sc.netid, sc.belong.timing, timestamp, callback)
if id >= 0 {
sc.AddPendingTimer(id)
}
return id
}
// RunAfter runs a callback right after the specified duration ellapsed.
func (sc *ServerConn) RunAfter(duration time.Duration, callback func(time.Time, WriteCloser)) int64 {
id := runAfter(sc.ctx, sc.netid, sc.belong.timing, duration, callback)
if id >= 0 {
sc.AddPendingTimer(id)
}
return id
}
// RunEvery runs a callback on every interval time.
func (sc *ServerConn) RunEvery(interval time.Duration, callback func(time.Time, WriteCloser)) int64 {
id := runEvery(sc.ctx, sc.netid, sc.belong.timing, interval, callback)
if id >= 0 {
sc.AddPendingTimer(id)
}
return id
}
// CancelTimer cancels a timer with the specified ID.
func (sc *ServerConn) CancelTimer(timerID int64) {
cancelTimer(sc.belong.timing, timerID)
}
func cancelTimer(timing *TimingWheel, timerID int64) {
if timing != nil {
timing.CancelTimer(timerID)
}
}
// RemoteAddr returns the remote address of server connection.
func (sc *ServerConn) RemoteAddr() net.Addr {
return sc.rawConn.RemoteAddr()
}
// LocalAddr returns the local address of server connection.
func (sc *ServerConn) LocalAddr() net.Addr {
return sc.rawConn.LocalAddr()
}
// ClientConn represents a client connection to a TCP server.
type ClientConn struct {
addr string
opts options
netid int64
rawConn net.Conn
once *sync.Once
wg *sync.WaitGroup
sendCh chan []byte
handlerCh chan MessageHandler
timing *TimingWheel
mu sync.Mutex // guards following
name string
heart int64
pending []int64
ctx context.Context
cancel context.CancelFunc
}
// NewClientConn returns a new client connection which has not started to
// serve requests yet.
func NewClientConn(netid int64, c net.Conn, opt ...ServerOption) *ClientConn {
var opts options
for _, o := range opt {
o(&opts)
}
if opts.codec == nil {
opts.codec = TypeLengthValueCodec{}
}
if opts.bufferSize <= 0 {
opts.bufferSize = BufferSize256
}
return newClientConnWithOptions(netid, c, opts)
}
func newClientConnWithOptions(netid int64, c net.Conn, opts options) *ClientConn {
cc := &ClientConn{
addr: c.RemoteAddr().String(),
opts: opts,
netid: netid,
rawConn: c,
once: &sync.Once{},
wg: &sync.WaitGroup{},
sendCh: make(chan []byte, opts.bufferSize),
handlerCh: make(chan MessageHandler, opts.bufferSize),
heart: time.Now().UnixNano(),
}
cc.ctx, cc.cancel = context.WithCancel(context.Background())
cc.timing = NewTimingWheel(cc.ctx)
cc.name = c.RemoteAddr().String()
cc.pending = []int64{}
return cc
}
// NetID returns the net ID of client connection.
func (cc *ClientConn) NetID() int64 {
return cc.netid
}
// SetName sets the name of client connection.
func (cc *ClientConn) SetName(name string) {
cc.mu.Lock()
cc.name = name
cc.mu.Unlock()
}
// Name gets the name of client connection.
func (cc *ClientConn) Name() string {
cc.mu.Lock()
name := cc.name
cc.mu.Unlock()
return name
}
// SetHeartBeat sets the heart beats of client connection.
func (cc *ClientConn) SetHeartBeat(heart int64) {
cc.mu.Lock()
cc.heart = heart
cc.mu.Unlock()
}
// HeartBeat gets the heart beats of client connection.
func (cc *ClientConn) HeartBeat() int64 {
cc.mu.Lock()
heart := cc.heart
cc.mu.Unlock()
return heart
}
// SetContextValue sets extra data to client connection.
func (cc *ClientConn) SetContextValue(k, v interface{}) {
cc.mu.Lock()
defer cc.mu.Unlock()
cc.ctx = context.WithValue(cc.ctx, k, v)
}
// ContextValue gets extra data from client connection.
func (cc *ClientConn) ContextValue(k interface{}) interface{} {
cc.mu.Lock()
defer cc.mu.Unlock()
return cc.ctx.Value(k)
}
// Start starts the client connection, creating go-routines for reading,
// writing and handlng.
func (cc *ClientConn) Start() {
holmes.Infof("conn start, <%v -> %v>\n", cc.rawConn.LocalAddr(), cc.rawConn.RemoteAddr())
onConnect := cc.opts.onConnect
if onConnect != nil {
onConnect(cc)
}
loopers := []func(WriteCloser, *sync.WaitGroup){readLoop, writeLoop, handleLoop}
for _, l := range loopers {
looper := l
cc.wg.Add(1)
go looper(cc, cc.wg)
}
}
// Close gracefully closes the client connection. It blocked until all sub
// go-routines are completed and returned.
func (cc *ClientConn) Close() {
cc.once.Do(func() {
holmes.Infof("conn close gracefully, <%v -> %v>\n", cc.rawConn.LocalAddr(), cc.rawConn.RemoteAddr())
// callback on close
onClose := cc.opts.onClose
if onClose != nil {
onClose(cc)
}
// close net.Conn, any blocked read or write operation will be unblocked and
// return errors.
cc.rawConn.Close()
// cancel readLoop, writeLoop and handleLoop go-routines.
cc.mu.Lock()
cc.cancel()
cc.pending = nil
cc.mu.Unlock()
// stop timer
cc.timing.Stop()
// wait until all go-routines exited.
cc.wg.Wait()
// close all channels.
close(cc.sendCh)
close(cc.handlerCh)
// cc.once is a *sync.Once. After reconnect() returned, cc.once will point
// to a newly-allocated one while other go-routines such as readLoop,
// writeLoop and handleLoop blocking on the old *sync.Once continue to
// execute Close() (and of course do nothing because of sync.Once).
// NOTE that it will cause an "unlock of unlocked mutex" error if cc.once is
// a sync.Once struct, because "defer o.m.Unlock()" in sync.Once.Do() will
// be performed on an unlocked mutex(the newly-allocated one noticed above)
if cc.opts.reconnect {
cc.reconnect()
}
})
}
// reconnect reconnects and returns a new *ClientConn.
func (cc *ClientConn) reconnect() {
var c net.Conn
var err error
if cc.opts.tlsCfg != nil {
c, err = tls.Dial("tcp", cc.addr, cc.opts.tlsCfg)
if err != nil {
holmes.Fatalln("tls dial error", err)
}
} else {
c, err = net.Dial("tcp", cc.addr)
if err != nil {
holmes.Fatalln("net dial error", err)
}
}
// copy the newly-created *ClientConn to cc, so after
// reconnect returned cc will be updated to new one.
*cc = *newClientConnWithOptions(cc.netid, c, cc.opts)
cc.Start()
}
// Write writes a message to the client.
func (cc *ClientConn) Write(message Message) error {
return asyncWrite(cc, message)
}
// RunAt runs a callback at the specified timestamp.
func (cc *ClientConn) RunAt(timestamp time.Time, callback func(time.Time, WriteCloser)) int64 {
id := runAt(cc.ctx, cc.netid, cc.timing, timestamp, callback)
if id >= 0 {
cc.AddPendingTimer(id)
}
return id
}
// RunAfter runs a callback right after the specified duration ellapsed.
func (cc *ClientConn) RunAfter(duration time.Duration, callback func(time.Time, WriteCloser)) int64 {
id := runAfter(cc.ctx, cc.netid, cc.timing, duration, callback)
if id >= 0 {
cc.AddPendingTimer(id)
}
return id
}
// RunEvery runs a callback on every interval time.
func (cc *ClientConn) RunEvery(interval time.Duration, callback func(time.Time, WriteCloser)) int64 {
id := runEvery(cc.ctx, cc.netid, cc.timing, interval, callback)
if id >= 0 {
cc.AddPendingTimer(id)
}
return id
}
// AddPendingTimer adds a new timer ID to client connection.
func (cc *ClientConn) AddPendingTimer(timerID int64) {
cc.mu.Lock()
defer cc.mu.Unlock()
if cc.pending != nil {
cc.pending = append(cc.pending, timerID)
}
}
// CancelTimer cancels a timer with the specified ID.
func (cc *ClientConn) CancelTimer(timerID int64) {
cancelTimer(cc.timing, timerID)
}
// RemoteAddr returns the remote address of server connection.
func (cc *ClientConn) RemoteAddr() net.Addr {
return cc.rawConn.RemoteAddr()
}
// LocalAddr returns the local address of server connection.
func (cc *ClientConn) LocalAddr() net.Addr {
return cc.rawConn.LocalAddr()
}
func runAt(ctx context.Context, netID int64, timing *TimingWheel, ts time.Time, cb func(time.Time, WriteCloser)) int64 {
timeout := NewOnTimeOut(NewContextWithNetID(ctx, netID), cb)
return timing.AddTimer(ts, 0, timeout)
}
func runAfter(ctx context.Context, netID int64, timing *TimingWheel, d time.Duration, cb func(time.Time, WriteCloser)) int64 {
delay := time.Now().Add(d)
return runAt(ctx, netID, timing, delay, cb)
}
func runEvery(ctx context.Context, netID int64, timing *TimingWheel, d time.Duration, cb func(time.Time, WriteCloser)) int64 {
delay := time.Now().Add(d)
timeout := NewOnTimeOut(NewContextWithNetID(ctx, netID), cb)
return timing.AddTimer(delay, d, timeout)
}
func asyncWrite(c interface{}, m Message) (err error) {
defer func() {
if p := recover(); p != nil {
err = ErrServerClosed
}
}()
var (
pkt []byte
sendCh chan []byte
)
switch c := c.(type) {
case *ServerConn:
pkt, err = c.belong.opts.codec.Encode(m)
sendCh = c.sendCh
case *ClientConn:
pkt, err = c.opts.codec.Encode(m)
sendCh = c.sendCh
}
if err != nil {
holmes.Errorf("asyncWrite error %v\n", err)
return
}
select {
case sendCh <- pkt:
err = nil
default:
err = ErrWouldBlock
}
return
}
/* readLoop() blocking read from connection, deserialize bytes into message,
then find corresponding handler, put it into channel */
func readLoop(c WriteCloser, wg *sync.WaitGroup) {
var (
rawConn net.Conn
codec Codec
cDone <-chan struct{}
sDone <-chan struct{}
setHeartBeatFunc func(int64)
onMessage onMessageFunc
handlerCh chan MessageHandler
msg Message
err error
)
switch c := c.(type) {
case *ServerConn:
rawConn = c.rawConn
codec = c.belong.opts.codec
cDone = c.ctx.Done()
sDone = c.belong.ctx.Done()
setHeartBeatFunc = c.SetHeartBeat
onMessage = c.belong.opts.onMessage
handlerCh = c.handlerCh
case *ClientConn:
rawConn = c.rawConn
codec = c.opts.codec
cDone = c.ctx.Done()
sDone = nil
setHeartBeatFunc = c.SetHeartBeat
onMessage = c.opts.onMessage
handlerCh = c.handlerCh
}
defer func() {
if p := recover(); p != nil {
holmes.Errorf("panics: %v\n", p)
}
wg.Done()
holmes.Debugln("readLoop go-routine exited")
c.Close()
}()
for {
select {
case <-cDone: // connection closed
holmes.Debugln("receiving cancel signal from conn")
return
case <-sDone: // server closed
holmes.Debugln("receiving cancel signal from server")
return
default:
msg, err = codec.Decode(rawConn)
if err != nil {
holmes.Errorf("error decoding message %v\n", err)
if _, ok := err.(ErrUndefined); ok {
// update heart beats
setHeartBeatFunc(time.Now().UnixNano())
continue
}
return
}
setHeartBeatFunc(time.Now().UnixNano())
handler := GetHandlerFunc(msg.MessageNumber())
if handler == nil {
if onMessage != nil {
holmes.Infof("message %d call onMessage()\n", msg.MessageNumber())
onMessage(msg, c.(WriteCloser))
} else {
holmes.Warnf("no handler or onMessage() found for message %d\n", msg.MessageNumber())
}
continue
}
handlerCh <- MessageHandler{msg, handler}
}
}
}
/* writeLoop() receive message from channel, serialize it into bytes,
then blocking write into connection */
func writeLoop(c WriteCloser, wg *sync.WaitGroup) {
var (
rawConn net.Conn
sendCh chan []byte
cDone <-chan struct{}
sDone <-chan struct{}
pkt []byte
err error
)
switch c := c.(type) {
case *ServerConn:
rawConn = c.rawConn
sendCh = c.sendCh
cDone = c.ctx.Done()
sDone = c.belong.ctx.Done()
case *ClientConn:
rawConn = c.rawConn
sendCh = c.sendCh
cDone = c.ctx.Done()
sDone = nil
}
defer func() {
if p := recover(); p != nil {
holmes.Errorf("panics: %v\n", p)
}
// drain all pending messages before exit
OuterFor:
for {
select {
case pkt = <-sendCh:
if pkt != nil {
if _, err = rawConn.Write(pkt); err != nil {
holmes.Errorf("error writing data %v\n", err)
}
}
default:
break OuterFor
}
}
wg.Done()
holmes.Debugln("writeLoop go-routine exited")
c.Close()
}()
for {
select {
case <-cDone: // connection closed
holmes.Debugln("receiving cancel signal from conn")
return
case <-sDone: // server closed
holmes.Debugln("receiving cancel signal from server")
return
case pkt = <-sendCh:
if pkt != nil {
if _, err = rawConn.Write(pkt); err != nil {
holmes.Errorf("error writing data %v\n", err)
return
}
}
}
}
}
// handleLoop() - put handler or timeout callback into worker go-routines
func handleLoop(c WriteCloser, wg *sync.WaitGroup) {
var (
cDone <-chan struct{}
sDone <-chan struct{}
timerCh chan *OnTimeOut
handlerCh chan MessageHandler
netID int64
ctx context.Context
askForWorker bool
err error
)
switch c := c.(type) {
case *ServerConn:
cDone = c.ctx.Done()
sDone = c.belong.ctx.Done()
timerCh = c.timerCh
handlerCh = c.handlerCh
netID = c.netid
ctx = c.ctx
askForWorker = true
case *ClientConn:
cDone = c.ctx.Done()
sDone = nil
timerCh = c.timing.timeOutChan
handlerCh = c.handlerCh
netID = c.netid
ctx = c.ctx
}
defer func() {
if p := recover(); p != nil {
holmes.Errorf("panics: %v\n", p)
}
wg.Done()
holmes.Debugln("handleLoop go-routine exited")
c.Close()
}()
for {
select {
case <-cDone: // connectin closed
holmes.Debugln("receiving cancel signal from conn")
return
case <-sDone: // server closed
holmes.Debugln("receiving cancel signal from server")
return
case msgHandler := <-handlerCh:
msg, handler := msgHandler.message, msgHandler.handler
if handler != nil {
if askForWorker {
err = WorkerPoolInstance().Put(netID, func() {
handler(NewContextWithNetID(NewContextWithMessage(ctx, msg), netID), c)
})
if err != nil {
holmes.Errorln(err)
}
addTotalHandle()
} else {
handler(NewContextWithNetID(NewContextWithMessage(ctx, msg), netID), c)
}
}
case timeout := <-timerCh:
if timeout != nil {
timeoutNetID := NetIDFromContext(timeout.Ctx)
if timeoutNetID != netID {
holmes.Errorf("timeout net %d, conn net %d, mismatched!\n", timeoutNetID, netID)
}
if askForWorker {
err = WorkerPoolInstance().Put(netID, func() {
timeout.Callback(time.Now(), c.(WriteCloser))
})
if err != nil {
holmes.Errorln(err)
}
} else {
timeout.Callback(time.Now(), c.(WriteCloser))
}
}
}
}
}