Run all pollers.
()
| 77 | |
| 78 | // Run all pollers. |
| 79 | func (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 ! |
| 121 | func (m *manager) Reset() error { |