summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 36ea1e0)
raw | patch | inline | side by side (parent: 36ea1e0)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 22 Feb 2015 18:24:53 +0000 (19:24 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 22 Feb 2015 18:24:53 +0000 (19:24 +0100) |
client/client.go | patch | blob | history | |
proto/proto.go | patch | blob | history |
diff --git a/client/client.go b/client/client.go
index fcb5d8de2f6c2d88fec581d868550c0c84e2d684..c42c7173793bacbd53a3a08eef1ddd108de97b6e 100644 (file)
--- a/client/client.go
+++ b/client/client.go
package client
import (
+ "encoding/binary"
"fmt"
"net"
"strings"
return nil, err
}
+// ServerVersion queries and returns the version of the remote server.
+func (c *Conn) ServerVersion() (major, minor, patch int, extra string, err error) {
+ m := &proto.Message{Type: proto.ConnectionServerVersion}
+ if err = c.Send(m); err != nil {
+ return 0, 0, 0, "", err
+ }
+
+ m, err = c.Receive()
+ if err != nil || m.Type != proto.ConnectionOK {
+ if err == nil {
+ err = fmt.Errorf("SERVER_VERSION command failed with status %d", m.Type)
+ }
+ return 0, 0, 0, "", err
+ }
+ if len(m.Raw) < 4 {
+ return 0, 0, 0, "", fmt.Errorf("SERVER_VERSION reply is too short")
+ }
+ version := int(binary.BigEndian.Uint32(m.Raw[:4]))
+ major = version / 10000
+ minor = version/100 - 100*major
+ patch = version - 10000*major - 100*minor
+ if len(m.Raw) > 4 {
+ extra = string(m.Raw[4:])
+ }
+ return major, minor, patch, extra, nil
+}
+
// vim: set tw=78 sw=4 sw=4 noexpandtab :
diff --git a/proto/proto.go b/proto/proto.go
index 5e93e472adbdb53c50c9bb0b10061dfeabec2419..a58725d6f81a6c7ad451390974e311b63a08b0f7 100644 (file)
--- a/proto/proto.go
+++ b/proto/proto.go
ConnectionMatcher = Status(100)
// ConnectionExpr is the internal state for parsing expressions.
ConnectionExpr = Status(101)
+
+ // ConnectionServerVersion is the state requesting the server version.
+ ConnectionServerVersion = Status(1000)
)
// The DataType describes the type of data in a ConnectionData message.