package pool // Pool tracks worker FDs and busy state for a single worker type. // Holds only the common management state; request/response types are // caller-specific and handled by the caller. type Pool struct { FDs []int32 Busy []bool Readers []FrameReader } // NewPool creates a Pool with capacity n. func NewPool(n int) Pool { return Pool{ FDs: []int32{:0:n}, Busy: []bool{:n}, Readers: []FrameReader{:n}, } } // FindByFD returns the index of the worker whose FD matches fd, or -1. func (p *Pool) FindByFD(fd int32) int { for i, wfd := range p.FDs { if wfd == fd { return i } } return -1 } // AddFD appends a new worker FD to the pool. func (p *Pool) AddFD(fd int32) { p.FDs = append(p.FDs, fd) } // Len returns the number of workers. func (p *Pool) Len() int { return len(p.FDs) } // IdleIndex returns the index of the first idle worker, or -1 if all busy. func (p *Pool) IdleIndex() int { for i, busy := range p.Busy { if !busy { return i } } return -1 }