receiveMessage receives a message without setting up context cancellation
()
| 662 | |
| 663 | // receiveMessage receives a message without setting up context cancellation |
| 664 | func (pgConn *PgConn) receiveMessage() (pgproto3.BackendMessage, error) { |
| 665 | if pgConn.status == connStatusClosed { |
| 666 | return nil, &connLockError{status: "conn closed"} |
| 667 | } |
| 668 | |
| 669 | msg, err := pgConn.peekMessage() |
| 670 | if err != nil { |
| 671 | return nil, err |
| 672 | } |
| 673 | pgConn.peekedMsg = nil |
| 674 | |
| 675 | switch msg := msg.(type) { |
| 676 | case *pgproto3.ReadyForQuery: |
| 677 | pgConn.txStatus = msg.TxStatus |
| 678 | case *pgproto3.ParameterStatus: |
| 679 | pgConn.parameterStatuses[msg.Name] = msg.Value |
| 680 | case *pgproto3.ErrorResponse: |
| 681 | err := ErrorResponseToPgError(msg) |
| 682 | if pgConn.config.OnPgError != nil && !pgConn.config.OnPgError(pgConn, err) { |
| 683 | pgConn.status = connStatusClosed |
| 684 | pgConn.conn.Close() // Ignore error as the connection is already broken and there is already an error to return. |
| 685 | close(pgConn.cleanupDone) |
| 686 | return nil, err |
| 687 | } |
| 688 | case *pgproto3.NoticeResponse: |
| 689 | if pgConn.config.OnNotice != nil { |
| 690 | pgConn.config.OnNotice(pgConn, noticeResponseToNotice(msg)) |
| 691 | } |
| 692 | case *pgproto3.NotificationResponse: |
| 693 | if pgConn.config.OnNotification != nil { |
| 694 | pgConn.config.OnNotification(pgConn, &Notification{PID: msg.PID, Channel: msg.Channel, Payload: msg.Payload}) |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | return msg, nil |
| 699 | } |
| 700 | |
| 701 | // Conn returns the underlying net.Conn. This rarely necessary. If the connection will be directly used for reading or |
| 702 | // writing then SyncConn should usually be called before Conn. |
no test coverage detected