-
Notifications
You must be signed in to change notification settings - Fork 16
C library wrapper #71
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||
# Compiling the C Library | ||||||||
|
||||||||
## Creating the .h and the .so files: | ||||||||
|
||||||||
|
||||||||
garyloug marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
```go build -o lib_udsclient.so -buildmode=c-shared cclient.go``` | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
- this creates .h and .so files from the cclient.go file. | ||||||||
|
||||||||
|
||||||||
## Creating the .h and the .a files: | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
```go build -o lib_udsclient.a -buildmode=c-archive ./cclient.go``` | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
- this creates .h and .a files | ||||||||
|
||||||||
|
||||||||
|
||||||||
## Usage | ||||||||
|
||||||||
After creating the .h and/or the .a and the .o files as described in the previous steps, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
this is how to use the functions generated by cgo | ||||||||
|
||||||||
``` char* GetUdsClientVersion()``` | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
This returns the version of our handshake on your local machine/client. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
```char* GetUdsServerVersion()``` | ||||||||
This returns the version of our handshake on the server/host. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
```int RequestXskMapFd(char* device)``` | ||||||||
This requests an Xsk map Fd for a specifed device. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
```int RequestBusyPoll(int busyTimeout, int busyBudget, int fd)``` | ||||||||
This requests a busy poll for a specific device by using it's fd, and specifying a timeout and a budget. | ||||||||
|
||||||||
```void CleanUpConnection()``` | ||||||||
After all the other functions are called, this needs to be called after all the work you need to do is done, | ||||||||
so that the connection to the Uds can be cleaned up. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,87 @@ | ||||||
package main | ||||||
|
||||||
import ( | ||||||
"C" | ||||||
"fmt" | ||||||
"os" | ||||||
|
||||||
"github.com/intel/afxdp-plugins-for-kubernetes/internal/uds" | ||||||
"github.com/intel/afxdp-plugins-for-kubernetes/pkg/goclient" | ||||||
) | ||||||
garyloug marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
func main() { | ||||||
// Needed for cgo to generate the .h | ||||||
} | ||||||
|
||||||
var cleaner uds.CleanupFunc | ||||||
|
||||||
/* | ||||||
GetClientVersion is an exported version for c of goclient's GetClientVersion() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
same throughout the file... I don't think |
||||||
*/ | ||||||
//export GetUdsClientVersion | ||||||
func GetUdsClientVersion() *C.char { | ||||||
return C.CString(goclient.GetClientVersion()) | ||||||
} | ||||||
|
||||||
/* | ||||||
ServerVersion is an exported version for c of goclient's GetServerVersion() | ||||||
*/ | ||||||
//export GetUdsServerVersion | ||||||
func GetUdsServerVersion() *C.char { | ||||||
response, function, err := goclient.GetServerVersion() | ||||||
if err != nil { | ||||||
fmt.Fprintln(os.Stderr, err.Error()) | ||||||
function() | ||||||
return C.CString("-1") | ||||||
} | ||||||
|
||||||
cleaner = function | ||||||
|
||||||
return C.CString(response) | ||||||
} | ||||||
|
||||||
/* | ||||||
GetXskMapFd is an exported version for c of goclient's XskMapFd() | ||||||
*/ | ||||||
//export RequestXskMapFd | ||||||
func RequestXskMapFd(device *C.char) (fd C.int) { | ||||||
fdVal, function, err := goclient.RequestXSKmapFD(C.GoString(device)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should you check device isn't Nil before passing it along to RequestXSKmapFD |
||||||
fd = C.int(fdVal) | ||||||
if err != nil { | ||||||
fmt.Fprintln(os.Stderr, err.Error()) | ||||||
function() | ||||||
return -1 | ||||||
} | ||||||
|
||||||
cleaner = function | ||||||
|
||||||
return fd | ||||||
} | ||||||
|
||||||
/* | ||||||
RequestBusyPoll is an exported version for c of goclient's RequestBusyPoll() | ||||||
*/ | ||||||
//export RequestBusyPoll | ||||||
func RequestBusyPoll(busyTimeout, busyBudget, fd C.int) C.int { | ||||||
function, err := goclient.RequestBusyPoll(int(busyTimeout), int(busyBudget), int(fd)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably do some param error checking before calling RequestBusyPoll |
||||||
if err != nil { | ||||||
fmt.Fprintln(os.Stderr, err.Error()) | ||||||
function() | ||||||
return -1 | ||||||
} | ||||||
cleaner = function | ||||||
return 0 | ||||||
} | ||||||
|
||||||
/* | ||||||
CleanUpConnection an explicit exported cgo function to cleanup a connection after calling any of the other functions. | ||||||
Pass in one of the available function names to clean up the connection after use. | ||||||
*/ | ||||||
//export CleanUpConnection | ||||||
func CleanUpConnection() { | ||||||
if cleaner == nil { | ||||||
fmt.Println("No cleanup function available to call") | ||||||
} else { | ||||||
cleaner() | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.