func (s *Socket) readMessagesSync(ctx context.Context, wg *sync.WaitGroup, out chan<- message.Message) {
	defer wg.Done()
	defer s.closeConn() // will cause writeMessages() to fail, but not stop until the in channel is closed.
	defer s.sendClose(ctx, out)
	pongHandler := func(appData string) error {
		if err := s.refreshDeadline(s.Conn.SetReadDeadline, s.ReadWait); err != nil {
			err = fmt.Errorf("setting read deadline: %w", err)
			s.writeClose(err)
			return err
		}
		return nil
	}
	if err := pongHandler(""); err != nil {
		return
	}
	s.Conn.SetPongHandler(pongHandler)
	for { // BLOCKING
		m, err := s.readMessage() // BLOCKING
		select {
		case <-ctx.Done():
			return
		default:
		}
		if err != nil {
			var err2 error
			if err != errSocketClosed {
				err2 = fmt.Errorf("reading socket messages stopped for player %v: %v", s, err)
			}
			s.writeClose(err2)
			return
		}
		message.Send(*m, out, s.Debug, s.log)
	}
}
// readMessagesSync receives messages from the connected socket and writes the to the messages channel.
// messages are not sent if the reading is cancelled from the done channel or an error is encountered and sent to the error channel.
readMessagesSync receives messages from the connected socket and writes the to the messages channel.
messages are not sent if the reading is cancelled from the done channel or an error is encountered and sent to the error channel.
// readMessagesSync receives messages from the connected socket and writes the to the messages channel . // messages are not sent if the reading is cancelled from the done channel or an error is encountered and sent to the error channel .
func (s *Socket) readMessagesSync(ctx context.Context, wg *sync.WaitGroup, out chan<- message.Message) {
	defer wg.Done()
	defer s.closeConn() 
	defer s.sendClose(ctx, out)
	pongHandler := func(appData string) error {
		if err := s.refreshDeadline(s.Conn.SetReadDeadline, s.ReadWait); err != nil {
			err = fmt.Errorf("setting read deadline: %w", err)
			s.writeClose(err)
			return err
		}
		return nil
	}
	if err := pongHandler(""); err != nil {
		return
	}
	s.Conn.SetPongHandler(pongHandler)
	for { 
		m, err := s.readMessage() 
		select {
		case <-ctx.Done():
			return
		default:
		}
		if err != nil {
			var err2 error
			if err != errSocketClosed {
				err2 = fmt.Errorf("reading socket messages stopped for player %v: %v", s, err)
			}
			s.writeClose(err2)
			return
		}
		message.Send(*m, out, s.Debug, s.log)
	}
}
func ( s * Socket ) readMessagesSync ( ctx context . Context , wg * sync . WaitGroup , out chan <- message . Message ) { defer wg . Done ( ) defer s . closeConn ( ) defer s . sendClose ( ctx , out ) pongHandler := func ( appData string ) error { if err := s . refreshDeadline ( s . Conn . SetReadDeadline , s . ReadWait ) ; err != nil { err = fmt . Errorf ( " " , err ) s . writeClose ( err ) return err } return nil } if err := pongHandler ( " " ) ; err != nil { return } s . Conn . SetPongHandler ( pongHandler ) for { m , err := s . readMessage ( ) select { case <- ctx . Done ( ) : return default : } if err != nil { var err2 error if err != errSocketClosed { err2 = fmt . Errorf ( " " , s , err ) } s . writeClose ( err2 ) return } message . Send ( * m , out , s . Debug , s . log ) } }
readMessagesSync receives messages from the connected socket and writes the to the messages channel.
readMessagesSync receives messages from the connected socket and writes the to the messages channel .
// will cause writeMessages() to fail, but not stop until the in channel is closed. // BLOCKING // BLOCKING