Esempio n. 1
0
// poolMan is run in a go routine by new.  It moves clients from the inPool
// back to the outPool as long as the version string matches the current.  It
// also clears out the outPool when a new version string is recieved on the
// version channel.
func poolMan(pool *Pool, versionStr string) {
	for {
		// TODO: Do I need to break? I think I do
		select {
		case str := <-pool.versionChan:
			if str != versionStr {
				gslog.Debug("POOL: flushing pool because versionStr changed")
				versionStr = str
				flushPool(pool.outPool)
			}
			continue
		case client := <-pool.inPool:
			if client.versionStr == versionStr {
				gslog.Debug("POOL: poolMan added client back to pool")
				select {
				case pool.outPool <- client:
					continue
				default:
					gslog.Warn("POOL: out pool is full")
				}
				continue
			}
			client.Close()
			gslog.Debug("POOL: poolMan discarded client")
			continue
		}
	}
}
Esempio n. 2
0
// Put a *Client back into the pool.  Clients that return errors should not be
// returned to the pool.
// Please don't give back clients that return errors :)
// Returns false on failure
func (p *Pool) Put(client *Client) error {
	select {
	case p.inPool <- client:
		return nil
	default:
		gslog.Warn("POOL: in pool is full")
		return errors.New("in pool is full")
	}
}