mirror of https://github.com/ceph/go-ceph
rados: add a connected flag to the conn obj
Signed-off-by: Noah Watkins <nwatkins@redhat.com>
This commit is contained in:
parent
3b687cfa99
commit
c14a3857fa
|
@ -19,6 +19,7 @@ type ClusterStat struct {
|
||||||
// Conn is a connection handle to a Ceph cluster.
|
// Conn is a connection handle to a Ceph cluster.
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
cluster C.rados_t
|
cluster C.rados_t
|
||||||
|
connected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// PingMonitor sends a ping to a monitor and returns the reply.
|
// PingMonitor sends a ping to a monitor and returns the reply.
|
||||||
|
|
|
@ -37,11 +37,13 @@ func Version() (int, int, int) {
|
||||||
return int(c_major), int(c_minor), int(c_patch)
|
return int(c_major), int(c_minor), int(c_patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConn creates a new connection object. It returns the connection and an
|
func makeConn() *Conn {
|
||||||
// error, if any.
|
return &Conn{connected: false}
|
||||||
func NewConn() (*Conn, error) {
|
}
|
||||||
conn := &Conn{}
|
|
||||||
ret := C.rados_create(&conn.cluster, nil)
|
func newConn(user *C.char) (*Conn, error) {
|
||||||
|
conn := makeConn()
|
||||||
|
ret := C.rados_create(&conn.cluster, user)
|
||||||
|
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
return conn, nil
|
return conn, nil
|
||||||
|
@ -50,20 +52,18 @@ func NewConn() (*Conn, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewConn creates a new connection object. It returns the connection and an
|
||||||
|
// error, if any.
|
||||||
|
func NewConn() (*Conn, error) {
|
||||||
|
return newConn(nil)
|
||||||
|
}
|
||||||
|
|
||||||
// NewConnWithUser creates a new connection object with a custom username.
|
// NewConnWithUser creates a new connection object with a custom username.
|
||||||
// It returns the connection and an error, if any.
|
// It returns the connection and an error, if any.
|
||||||
func NewConnWithUser(user string) (*Conn, error) {
|
func NewConnWithUser(user string) (*Conn, error) {
|
||||||
c_user := C.CString(user)
|
c_user := C.CString(user)
|
||||||
defer C.free(unsafe.Pointer(c_user))
|
defer C.free(unsafe.Pointer(c_user))
|
||||||
|
return newConn(c_user)
|
||||||
conn := &Conn{}
|
|
||||||
ret := C.rados_create(&conn.cluster, c_user)
|
|
||||||
|
|
||||||
if ret == 0 {
|
|
||||||
return conn, nil
|
|
||||||
} else {
|
|
||||||
return nil, RadosError(int(ret))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConnWithClusterAndUser creates a new connection object for a specific cluster and username.
|
// NewConnWithClusterAndUser creates a new connection object for a specific cluster and username.
|
||||||
|
@ -75,7 +75,7 @@ func NewConnWithClusterAndUser(clusterName string, userName string) (*Conn, erro
|
||||||
c_name := C.CString(userName)
|
c_name := C.CString(userName)
|
||||||
defer C.free(unsafe.Pointer(c_name))
|
defer C.free(unsafe.Pointer(c_name))
|
||||||
|
|
||||||
conn := &Conn{}
|
conn := makeConn()
|
||||||
ret := C.rados_create2(&conn.cluster, c_cluster_name, c_name, 0)
|
ret := C.rados_create2(&conn.cluster, c_cluster_name, c_name, 0)
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
return conn, nil
|
return conn, nil
|
||||||
|
|
Loading…
Reference in New Issue