MCPcopy
hub / github.com/jackc/pgx / receiveMessage

Method receiveMessage

pgconn/pgconn.go:664–699  ·  view source on GitHub ↗

receiveMessage receives a message without setting up context cancellation

()

Source from the content-addressed store, hash-verified

662
663// receiveMessage receives a message without setting up context cancellation
664func (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.

Callers 14

rxGSSContinueMethod · 0.95
rxSASLContinueMethod · 0.95
rxSASLFinalMethod · 0.95
ReceiveMessageMethod · 0.95
PrepareMethod · 0.95
DeallocateMethod · 0.95
WaitForNotificationMethod · 0.95
CopyToMethod · 0.95
CopyFromMethod · 0.95
oauthAuthMethod · 0.95
connectOneFunction · 0.45
receiveMessageMethod · 0.45

Calls 4

peekMessageMethod · 0.95
ErrorResponseToPgErrorFunction · 0.85
noticeResponseToNoticeFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected