MCPcopy Create free account
hub / github.com/cloudwego/netpoll / Run

Method Run

poll_manager.go:79–118  ·  view source on GitHub ↗

Run all pollers.

()

Source from the content-addressed store, hash-verified

77
78// Run all pollers.
79func (m *manager) Run() (err error) {
80 defer func() {
81 if err != nil {
82 _ = m.Close()
83 }
84 }()
85
86 numLoops := int(atomic.LoadInt32(&m.numLoops))
87 if numLoops == len(m.polls) {
88 return nil
89 }
90 polls := make([]Poll, numLoops)
91 if numLoops < len(m.polls) {
92 // shrink polls
93 copy(polls, m.polls[:numLoops])
94 for idx := numLoops; idx < len(m.polls); idx++ {
95 // close redundant polls
96 if err = m.polls[idx].Close(); err != nil {
97 logger.Printf("NETPOLL: poller close failed: %v\n", err)
98 }
99 }
100 } else {
101 // growth polls
102 copy(polls, m.polls)
103 for idx := len(m.polls); idx < numLoops; idx++ {
104 var poll Poll
105 poll, err = openPoll()
106 if err != nil {
107 return err
108 }
109 polls[idx] = poll
110 go poll.Wait()
111 }
112 }
113 m.polls = polls
114
115 // LoadBalance must be set before calling Run, otherwise it will panic.
116 m.balance.Rebalance(m.polls)
117 return nil
118}
119
120// Reset pollers, this operation is very dangerous, please make sure to do this when calling !
121func (m *manager) Reset() error {

Callers 6

ResetMethod · 0.95
PickMethod · 0.95
TestConnectionTimeoutFunction · 0.45
TestWriterAfterCloseFunction · 0.45
ServeMethod · 0.45
TestLinkBufferReadCopyFunction · 0.45

Calls 5

CloseMethod · 0.95
WaitMethod · 0.95
openPollFunction · 0.70
CloseMethod · 0.65
RebalanceMethod · 0.65

Tested by 3

TestConnectionTimeoutFunction · 0.36
TestWriterAfterCloseFunction · 0.36
TestLinkBufferReadCopyFunction · 0.36