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
rowDesc rowDescription // current query rowDescription
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
}
@@ -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) {
switch t {
case 'K':
return c.rxBackendKeyData(body), nil
c.rxBackendKeyData(body)
return nil, nil
case 'R':
return c.rxAuthenticationX(body)
case 'Z':
@@ -190,11 +193,10 @@ func (c *conn) rxParameterStatus(buf []byte) {
c.runtimeParams[key] = value
}
func (c *conn) rxBackendKeyData(buf []byte) (msg *backendKeyData) {
msg = new(backendKeyData)
msg.pid = int32(binary.BigEndian.Uint32(buf[:4]))
msg.secretKey = int32(binary.BigEndian.Uint32(buf[4:8]))
return
func (c *conn) rxBackendKeyData(buf []byte) {
r := newMessageReader(buf)
c.pid = r.readInt32()
c.secretKey = r.readInt32()
}
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")
}
if conn.pid == 0 {
t.Error("Backend PID not stored")
}
if conn.secretKey == 0 {
t.Error("Backend secret key not stored")
}
err = conn.Close()
if err != nil {
t.Fatal("Unable to close connection")
-9
View File
@@ -38,15 +38,6 @@ func (self *authenticationOk) String() string {
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 {
txStatus byte
}