From c14a3857fa7daca77246fc4db7938157abd5dd9b Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Sat, 28 Jul 2018 14:23:18 -0700 Subject: [PATCH] rados: add a connected flag to the conn obj Signed-off-by: Noah Watkins --- rados/conn.go | 3 ++- rados/rados.go | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/rados/conn.go b/rados/conn.go index 381fa4c..390c589 100644 --- a/rados/conn.go +++ b/rados/conn.go @@ -18,7 +18,8 @@ type ClusterStat struct { // Conn is a connection handle to a Ceph cluster. type Conn struct { - cluster C.rados_t + cluster C.rados_t + connected bool } // PingMonitor sends a ping to a monitor and returns the reply. diff --git a/rados/rados.go b/rados/rados.go index 4538628..1924032 100644 --- a/rados/rados.go +++ b/rados/rados.go @@ -37,11 +37,13 @@ func Version() (int, int, int) { return int(c_major), int(c_minor), int(c_patch) } -// NewConn creates a new connection object. It returns the connection and an -// error, if any. -func NewConn() (*Conn, error) { - conn := &Conn{} - ret := C.rados_create(&conn.cluster, nil) +func makeConn() *Conn { + return &Conn{connected: false} +} + +func newConn(user *C.char) (*Conn, error) { + conn := makeConn() + ret := C.rados_create(&conn.cluster, user) if ret == 0 { 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. // It returns the connection and an error, if any. func NewConnWithUser(user string) (*Conn, error) { c_user := C.CString(user) defer C.free(unsafe.Pointer(c_user)) - - conn := &Conn{} - ret := C.rados_create(&conn.cluster, c_user) - - if ret == 0 { - return conn, nil - } else { - return nil, RadosError(int(ret)) - } + return newConn(c_user) } // 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) defer C.free(unsafe.Pointer(c_name)) - conn := &Conn{} + conn := makeConn() ret := C.rados_create2(&conn.cluster, c_cluster_name, c_name, 0) if ret == 0 { return conn, nil