예제 #1
0
func (a *DnetAddr) HostString() string {
	var tmp *C.struct_dnet_addr = C.dnet_addr_alloc()
	defer C.dnet_addr_free(tmp)

	a.CAddr(tmp)
	return C.GoString(C.dnet_addr_host_string(tmp))
}
예제 #2
0
func (a *DnetAddr) String() string {
	var tmp *C.struct_dnet_addr = C.dnet_addr_alloc()
	defer C.dnet_addr_free(tmp)

	a.CAddr(tmp)
	return fmt.Sprintf("%s:%d", C.GoString(C.dnet_addr_string(tmp)), a.Family)
}
예제 #3
0
func (s *Session) LookupBackend(key string, group_id uint32) (addr *DnetAddr, backend_id int32, err error) {
	var caddr *C.struct_dnet_addr = C.dnet_addr_alloc()
	defer C.dnet_addr_free(caddr)
	var cbackend_id C.int

	ckey := C.CString(key)
	defer C.free(unsafe.Pointer(ckey))

	addr = nil
	backend_id = -1

	cerr := C.session_lookup_addr(s.session, ckey, C.int(len(key)), C.int(group_id), caddr, &cbackend_id)
	if cerr < 0 {
		err = &DnetError{
			Code:  int(cerr),
			Flags: 0,
			Message: fmt.Sprintf("could not lookup backend: key '%s', group: %d: %d",
				key, group_id, int(cerr)),
		}

		return
	}

	new_addr := NewDnetAddr(caddr)

	addr = &new_addr
	backend_id = int32(cbackend_id)

	return
}
예제 #4
0
func NewDnetAddrStr(addr_str string) (DnetAddr, error) {
	var caddr *C.struct_dnet_addr = C.dnet_addr_alloc()
	defer C.dnet_addr_free(caddr)

	caddr_str := C.CString(addr_str)
	defer C.free(unsafe.Pointer(caddr_str))

	err := int(C.dnet_create_addr_str(caddr, caddr_str, C.int(len(addr_str))))
	if err < 0 {
		return DnetAddr{}, fmt.Errorf("could not create addr '%s': %d", addr_str, err)
	}

	return NewDnetAddr(caddr), nil
}
예제 #5
0
func (s *Session) BackendSetDelay(addr *DnetAddr, backend_id int32, delay uint32) *DChannel {
	responseCh := NewDChannel()
	context := NextContext()

	onFinish := func(tmp *DnetBackendsStatus) {
		responseCh.In <- tmp
		close(responseCh.In)
		Pool.Delete(context)
	}
	Pool.Store(context, onFinish)

	var tmp *C.struct_dnet_addr = C.dnet_addr_alloc()
	defer C.dnet_addr_free(tmp)
	addr.CAddr(tmp)
	C.session_backend_set_delay(s.session, tmp, C.uint32_t(backend_id), C.uint32_t(delay), C.context_t(context))

	return responseCh
}
예제 #6
0
func (s *Session) BackendMakeReadOnly(addr *DnetAddr, backend_id int32) <-chan *DnetBackendsStatus {
	responseCh := make(chan *DnetBackendsStatus, defaultVOLUME)
	context := NextContext()

	onFinish := func(tmp *DnetBackendsStatus) {
		responseCh <- tmp
		close(responseCh)
		Pool.Delete(context)
	}
	Pool.Store(context, onFinish)

	var tmp *C.struct_dnet_addr = C.dnet_addr_alloc()
	defer C.dnet_addr_free(tmp)
	addr.CAddr(tmp)
	C.session_backend_make_readonly(s.session, tmp, C.uint32_t(backend_id), C.context_t(context))

	return responseCh
}