2
0

Store backend pid and secret key

This commit is contained in:
Jack Christensen
2013-04-08 20:15:34 -05:00
parent b04166bcf5
commit 98890b1a50
3 changed files with 16 additions and 15 deletions
+8 -6
View File
@@ -12,6 +12,8 @@ type conn struct {
conn net.Conn // the underlying TCP or unix domain socket connection conn net.Conn // the underlying TCP or unix domain socket connection
rowDesc rowDescription // current query rowDescription rowDesc rowDescription // current query rowDescription
buf []byte // work buffer to avoid constant alloc and dealloc buf []byte // work buffer to avoid constant alloc and dealloc
pid int32 // backend pid
secretKey int32 // key to use to send a cancel query message to the server
runtimeParams map[string]string // parameters that have been reported by the server runtimeParams map[string]string // parameters that have been reported by the server
} }
@@ -125,7 +127,8 @@ func (c *conn) processCommonMsg(t byte, body []byte) (err error) {
func (c *conn) parseMsg(t byte, body []byte) (msg interface{}, err error) { func (c *conn) parseMsg(t byte, body []byte) (msg interface{}, err error) {
switch t { switch t {
case 'K': case 'K':
return c.rxBackendKeyData(body), nil c.rxBackendKeyData(body)
return nil, nil
case 'R': case 'R':
return c.rxAuthenticationX(body) return c.rxAuthenticationX(body)
case 'Z': case 'Z':
@@ -190,11 +193,10 @@ func (c *conn) rxParameterStatus(buf []byte) {
c.runtimeParams[key] = value c.runtimeParams[key] = value
} }
func (c *conn) rxBackendKeyData(buf []byte) (msg *backendKeyData) { func (c *conn) rxBackendKeyData(buf []byte) {
msg = new(backendKeyData) r := newMessageReader(buf)
msg.pid = int32(binary.BigEndian.Uint32(buf[:4])) c.pid = r.readInt32()
msg.secretKey = int32(binary.BigEndian.Uint32(buf[4:8])) c.secretKey = r.readInt32()
return
} }
func (c *conn) rxReadyForQuery(buf []byte) (msg *readyForQuery) { func (c *conn) rxReadyForQuery(buf []byte) (msg *readyForQuery) {
+8
View File
@@ -14,6 +14,14 @@ func TestConnect(t *testing.T) {
t.Error("Runtime parameters not stored") t.Error("Runtime parameters not stored")
} }
if conn.pid == 0 {
t.Error("Backend PID not stored")
}
if conn.secretKey == 0 {
t.Error("Backend secret key not stored")
}
err = conn.Close() err = conn.Close()
if err != nil { if err != nil {
t.Fatal("Unable to close connection") t.Fatal("Unable to close connection")
-9
View File
@@ -38,15 +38,6 @@ func (self *authenticationOk) String() string {
return "AuthenticationOk" return "AuthenticationOk"
} }
type backendKeyData struct {
pid int32
secretKey int32
}
func (self *backendKeyData) String() string {
return fmt.Sprintf("BackendKeyData pid: %d, secretKey: %d", self.pid, self.secretKey)
}
type readyForQuery struct { type readyForQuery struct {
txStatus byte txStatus byte
} }