File tree Expand file tree Collapse file tree 3 files changed +51
-25
lines changed
Expand file tree Collapse file tree 3 files changed +51
-25
lines changed Original file line number Diff line number Diff line change @@ -173,31 +173,6 @@ func (env *Env) SetStrictThreadMode(mode bool) {
173173
174174var errNotOpen = errors .New ("enivornment is not open" )
175175
176- // FD returns the open file descriptor (or Windows file handle) for the given
177- // environment. An error is returned if the environment has not been
178- // successfully Opened (where C API just retruns an invalid handle).
179- //
180- // See mdbx_env_get_fd.
181- func (env * Env ) FD () (uintptr , error ) {
182- // fdInvalid is the value -1 as a uintptr, which is used by MDBX in the
183- // case that env has not been opened yet. the strange construction is done
184- // to avoid constant value overflow errors at compile time.
185- const fdInvalid = ^ uintptr (0 )
186-
187- mf := new (C.mdbx_filehandle_t )
188- ret := C .mdbx_env_get_fd (env ._env , mf )
189- err := operrno ("mdbx_env_get_fd" , ret )
190- if err != nil {
191- return 0 , err
192- }
193- fd := uintptr (* mf )
194-
195- if fd == fdInvalid {
196- return 0 , errNotOpen
197- }
198- return fd , nil
199- }
200-
201176// ReaderList dumps the contents of the reader lock table as text. Readers
202177// start on the second line as space-delimited fields described by the first
203178// line.
Original file line number Diff line number Diff line change @@ -24,3 +24,28 @@ import "C"
2424// }
2525// return C.GoString(cpath), nil
2626//}
27+
28+ // FD returns the open file descriptor (or Windows file handle) for the given
29+ // environment. An error is returned if the environment has not been
30+ // successfully Opened (where C API just retruns an invalid handle).
31+ //
32+ // See mdbx_env_get_fd.
33+ func (env * Env ) FD () (uintptr , error ) {
34+ // fdInvalid is the value -1 as a uintptr, which is used by MDBX in the
35+ // case that env has not been opened yet. the strange construction is done
36+ // to avoid constant value overflow errors at compile time.
37+ const fdInvalid = ^ uintptr (0 )
38+
39+ mf := new (C.mdbx_filehandle_t )
40+ ret := C .mdbx_env_get_fd (env ._env , mf )
41+ err := operrno ("mdbx_env_get_fd" , ret )
42+ if err != nil {
43+ return 0 , err
44+ }
45+ fd := uintptr (* mf )
46+
47+ if fd == fdInvalid {
48+ return 0 , errNotOpen
49+ }
50+ return fd , nil
51+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ package mdbx
44#include "mdbxgo.h"
55*/
66import "C"
7+ import "unsafe"
78
89// TODO: fix me please
910//func (env *Env) Path() (string, error) {
@@ -17,3 +18,28 @@ import "C"
1718// }
1819// return C.GoString(cpath), nil
1920//}
21+
22+ // FD returns the open file descriptor (or Windows file handle) for the given
23+ // environment. An error is returned if the environment has not been
24+ // successfully Opened (where C API just retruns an invalid handle).
25+ //
26+ // See mdbx_env_get_fd.
27+ func (env * Env ) FD () (uintptr , error ) {
28+ // fdInvalid is the value -1 as a uintptr, which is used by MDBX in the
29+ // case that env has not been opened yet. the strange construction is done
30+ // to avoid constant value overflow errors at compile time.
31+ const fdInvalid = ^ uintptr (0 )
32+
33+ mf := new (C.mdbx_filehandle_t )
34+ ret := C .mdbx_env_get_fd (env ._env , mf )
35+ err := operrno ("mdbx_env_get_fd" , ret )
36+ if err != nil {
37+ return 0 , err
38+ }
39+ fd := uintptr (unsafe .Pointer (fh ))
40+
41+ if fd == fdInvalid {
42+ return 0 , errNotOpen
43+ }
44+ return fd , nil
45+ }
You can’t perform that action at this time.
0 commit comments