Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions mdbx/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,34 +173,6 @@ func (env *Env) SetStrictThreadMode(mode bool) {

var errNotOpen = errors.New("enivornment is not open")

/* TODO: fix error: cannot convert *mf (variable of type _Ctype_HANDLE) to type uintptr

// FD returns the open file descriptor (or Windows file handle) for the given
// environment. An error is returned if the environment has not been
// successfully Opened (where C API just retruns an invalid handle).
//
// See mdbx_env_get_fd.
func (env *Env) FD() (uintptr, error) {
// fdInvalid is the value -1 as a uintptr, which is used by MDBX in the
// case that env has not been opened yet. the strange construction is done
// to avoid constant value overflow errors at compile time.
const fdInvalid = ^uintptr(0)

mf := new(C.mdbx_filehandle_t)
ret := C.mdbx_env_get_fd(env._env, mf)
err := operrno("mdbx_env_get_fd", ret)
if err != nil {
return 0, err
}
fd := uintptr(*mf)

if fd == fdInvalid {
return 0, errNotOpen
}
return fd, nil
}
*/

// ReaderList dumps the contents of the reader lock table as text. Readers
// start on the second line as space-delimited fields described by the first
// line.
Expand Down
25 changes: 25 additions & 0 deletions mdbx/env_not_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,28 @@ import "C"
// }
// return C.GoString(cpath), nil
//}

// FD returns the open file descriptor (or Windows file handle) for the given
// environment. An error is returned if the environment has not been
// successfully Opened (where C API just retruns an invalid handle).
//
// See mdbx_env_get_fd.
func (env *Env) FD() (uintptr, error) {
// fdInvalid is the value -1 as a uintptr, which is used by MDBX in the
// case that env has not been opened yet. the strange construction is done
// to avoid constant value overflow errors at compile time.
const fdInvalid = ^uintptr(0)

mf := new(C.mdbx_filehandle_t)
ret := C.mdbx_env_get_fd(env._env, mf)
err := operrno("mdbx_env_get_fd", ret)
if err != nil {
return 0, err
}
fd := uintptr(*mf)

if fd == fdInvalid {
return 0, errNotOpen
}
return fd, nil
}
6 changes: 3 additions & 3 deletions mdbx/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package mdbx

import (
"fmt"
"runtime"
"strings"
"testing"
)

Expand Down Expand Up @@ -99,12 +101,11 @@ func TestEnv_PreOpen(t *testing.T) {

}

/*
func TestEnv_FD(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("FD funcs not supported on windows")
}
env, err1 := NewEnv()
env, err1 := NewEnv(Default)
if err1 != nil {
t.Error(err1)
return
Expand All @@ -131,7 +132,6 @@ func TestEnv_FD(t *testing.T) {
t.Errorf("fd: %x", fd)
}
}
*/

func TestEnv_Flags(t *testing.T) {
env, _ := setup(t)
Expand Down
26 changes: 26 additions & 0 deletions mdbx/env_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package mdbx
#include "mdbxgo.h"
*/
import "C"
import "unsafe"

// TODO: fix me please
//func (env *Env) Path() (string, error) {
Expand All @@ -17,3 +18,28 @@ import "C"
// }
// return C.GoString(cpath), nil
//}

// FD returns the open file descriptor (or Windows file handle) for the given
// environment. An error is returned if the environment has not been
// successfully Opened (where C API just retruns an invalid handle).
//
// See mdbx_env_get_fd.
func (env *Env) FD() (uintptr, error) {
// fdInvalid is the value -1 as a uintptr, which is used by MDBX in the
// case that env has not been opened yet. the strange construction is done
// to avoid constant value overflow errors at compile time.
const fdInvalid = ^uintptr(0)

var fh C.mdbx_filehandle_t
ret := C.mdbx_env_get_fd(env._env, &fh)
err := operrno("mdbx_env_get_fd", ret)
if err != nil {
return 0, err
}
fd := uintptr(unsafe.Pointer(fh))

if fd == fdInvalid {
return 0, errNotOpen
}
return fd, nil
}
Loading