Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ssh/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ type Seat struct {
}

type Seats struct {
mu *sync.Mutex
// counter count atomically seats of a session.
counter *atomic.Int32
// Items represents the individual seat of a session.
Expand All @@ -179,13 +180,17 @@ type Seats struct {
// NewSeats creates a new [Seats] defining initial values for internal properties.
func NewSeats() Seats {
return Seats{
mu: new(sync.Mutex),
counter: new(atomic.Int32),
Items: new(sync.Map),
}
}

// NewSeat creates a new seat inside seats.
func (s *Seats) NewSeat() (int, error) {
s.mu.Lock()
defer s.mu.Unlock()

id := int(s.counter.Load())
defer s.counter.Add(1)

Expand Down Expand Up @@ -213,6 +218,9 @@ func (s *Seats) Get(seat int) (*Seat, bool) {

// SetPty sets a pty status to a seat from their id.
func (s *Seats) SetPty(seat int, status bool) {
s.mu.Lock()
defer s.mu.Unlock()

item, ok := s.Get(seat)
if !ok {
log.Warn("failed to set pty because no seat was created before")
Expand Down
Loading