func (s *SocketServer) handleRequests(closeConn chan error, conn net.Conn, responses chan<- *types.Response) {
	var count int
	var bufReader = bufio.NewReader(conn)

	defer func() {
		// make sure to recover from any app-related panics to allow proper socket cleanup
		r := recover()
		if r != nil {
			closeConn <- fmt.Errorf("recovered from panic: %v", r)
			s.appMtx.Unlock()
		}
	}()

	for {

		var req = &types.Request{}
		err := types.ReadMessage(bufReader, req)
		if err != nil {
			if err == io.EOF {
				closeConn <- err
			} else {
				closeConn <- fmt.Errorf("error reading message: %v", err)
			}
			return
		}
		s.appMtx.Lock()
		count++
		s.handleRequest(req, responses)
		s.appMtx.Unlock()
	}
}
// Read requests from conn and deal with them
Read requests from conn and deal with them
// Read requests from conn and deal with them
func (s *SocketServer) handleRequests(closeConn chan error, conn net.Conn, responses chan<- *types.Response) {
	var count int
	var bufReader = bufio.NewReader(conn)
	defer func() {
		r := recover()
		if r != nil {
			closeConn <- fmt.Errorf("recovered from panic: %v", r)
			s.appMtx.Unlock()
		}
	}()
	for {
		var req = &types.Request{}
		err := types.ReadMessage(bufReader, req)
		if err != nil {
			if err == io.EOF {
				closeConn <- err
			} else {
				closeConn <- fmt.Errorf("error reading message: %v", err)
			}
			return
		}
		s.appMtx.Lock()
		count++
		s.handleRequest(req, responses)
		s.appMtx.Unlock()
	}
}
func ( s * SocketServer ) handleRequests ( closeConn chan error , conn net . Conn , responses chan <- * types . Response ) { var count int var bufReader = bufio . NewReader ( conn ) defer func ( ) { r := recover ( ) if r != nil { closeConn <- fmt . Errorf ( " " , r ) s . appMtx . Unlock ( ) } } ( ) for { var req = & types . Request { } err := types . ReadMessage ( bufReader , req ) if err != nil { if err == io . EOF { closeConn <- err } else { closeConn <- fmt . Errorf ( " " , err ) } return } s . appMtx . Lock ( ) count ++ s . handleRequest ( req , responses ) s . appMtx . Unlock ( ) } }
Read requests from conn and deal with them
Read requests from conn and deal with them
// make sure to recover from any app-related panics to allow proper socket cleanup