Pop the current server and put onto the end of the list. Select head of list as long as number of reconnect attempts under MaxReconnect.
()
| 1944 | // Pop the current server and put onto the end of the list. Select head of list as long |
| 1945 | // as number of reconnect attempts under MaxReconnect. |
| 1946 | func (nc *Conn) selectNextServer() (*Server, error) { |
| 1947 | i, s := nc.currentServer() |
| 1948 | if i < 0 { |
| 1949 | return nil, ErrNoServers |
| 1950 | } |
| 1951 | sp := nc.srvPool |
| 1952 | num := len(sp) |
| 1953 | copy(sp[i:num-1], sp[i+1:num]) |
| 1954 | maxReconnect := nc.Opts.MaxReconnect |
| 1955 | if maxReconnect < 0 || s.Reconnects < maxReconnect { |
| 1956 | nc.srvPool[num-1] = s |
| 1957 | } else { |
| 1958 | nc.srvPool = sp[0 : num-1] |
| 1959 | } |
| 1960 | if len(nc.srvPool) <= 0 { |
| 1961 | nc.current = nil |
| 1962 | return nil, ErrNoServers |
| 1963 | } |
| 1964 | nc.current = nc.srvPool[0] |
| 1965 | return nc.srvPool[0], nil |
| 1966 | } |
| 1967 | |
| 1968 | // Will assign the correct server to nc.current |
| 1969 | func (nc *Conn) pickServer() error { |