Access PID and SecretKey via method
This commit is contained in:
@@ -59,8 +59,8 @@ var ErrTLSRefused = errors.New("server refused TLS connection")
|
|||||||
// PgConn is a low-level PostgreSQL connection handle. It is not safe for concurrent usage.
|
// PgConn is a low-level PostgreSQL connection handle. It is not safe for concurrent usage.
|
||||||
type PgConn struct {
|
type PgConn struct {
|
||||||
conn net.Conn // the underlying TCP or unix domain socket connection
|
conn net.Conn // the underlying TCP or unix domain socket connection
|
||||||
PID uint32 // backend pid
|
pid uint32 // backend pid
|
||||||
SecretKey uint32 // key to use to send a cancel query message to the server
|
secretKey uint32 // key to use to send a cancel query message to the server
|
||||||
parameterStatuses map[string]string // parameters that have been reported by the server
|
parameterStatuses map[string]string // parameters that have been reported by the server
|
||||||
TxStatus byte
|
TxStatus byte
|
||||||
Frontend *pgproto3.Frontend
|
Frontend *pgproto3.Frontend
|
||||||
@@ -179,8 +179,8 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
|
|||||||
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case *pgproto3.BackendKeyData:
|
case *pgproto3.BackendKeyData:
|
||||||
pgConn.PID = msg.ProcessID
|
pgConn.pid = msg.ProcessID
|
||||||
pgConn.SecretKey = msg.SecretKey
|
pgConn.secretKey = msg.SecretKey
|
||||||
case *pgproto3.Authentication:
|
case *pgproto3.Authentication:
|
||||||
if err = pgConn.rxAuthenticationX(msg); err != nil {
|
if err = pgConn.rxAuthenticationX(msg); err != nil {
|
||||||
pgConn.conn.Close()
|
pgConn.conn.Close()
|
||||||
@@ -304,6 +304,16 @@ func (pgConn *PgConn) Conn() net.Conn {
|
|||||||
return pgConn.conn
|
return pgConn.conn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PID returns the backend PID.
|
||||||
|
func (pgConn *PgConn) PID() uint32 {
|
||||||
|
return pgConn.pid
|
||||||
|
}
|
||||||
|
|
||||||
|
// SecretKey returns the backend secret key used to send a cancel query message to the server.
|
||||||
|
func (pgConn *PgConn) SecretKey() uint32 {
|
||||||
|
return pgConn.secretKey
|
||||||
|
}
|
||||||
|
|
||||||
// Close closes a connection. It is safe to call Close on a already closed connection. Close attempts a clean close by
|
// Close closes a connection. It is safe to call Close on a already closed connection. Close attempts a clean close by
|
||||||
// sending the exit message to PostgreSQL. However, this could block so ctx is available to limit the time to wait. The
|
// sending the exit message to PostgreSQL. However, this could block so ctx is available to limit the time to wait. The
|
||||||
// underlying net.Conn.Close() will always be called regardless of any other errors.
|
// underlying net.Conn.Close() will always be called regardless of any other errors.
|
||||||
@@ -701,8 +711,8 @@ func (pgConn *PgConn) CancelRequest(ctx context.Context) error {
|
|||||||
buf := make([]byte, 16)
|
buf := make([]byte, 16)
|
||||||
binary.BigEndian.PutUint32(buf[0:4], 16)
|
binary.BigEndian.PutUint32(buf[0:4], 16)
|
||||||
binary.BigEndian.PutUint32(buf[4:8], 80877102)
|
binary.BigEndian.PutUint32(buf[4:8], 80877102)
|
||||||
binary.BigEndian.PutUint32(buf[8:12], uint32(pgConn.PID))
|
binary.BigEndian.PutUint32(buf[8:12], uint32(pgConn.pid))
|
||||||
binary.BigEndian.PutUint32(buf[12:16], uint32(pgConn.SecretKey))
|
binary.BigEndian.PutUint32(buf[12:16], uint32(pgConn.secretKey))
|
||||||
_, err = cancelConn.Write(buf)
|
_, err = cancelConn.Write(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return preferContextOverNetTimeoutError(ctx, err)
|
return preferContextOverNetTimeoutError(ctx, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user