-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix typo issue and some bugs in looger
- Loading branch information
1 parent
b5062f9
commit 552c75f
Showing
9 changed files
with
73 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package transport | ||
|
||
import ( | ||
|
||
//"log" | ||
|
||
"github.com/asavie/xdp" | ||
"github.com/kerwenwwer/eGossip/pkg/logger" | ||
) | ||
|
||
func XdpListen(xsk *xdp.Socket, mq chan []byte) { | ||
for { | ||
// If there are any free slots on the Fill queue... | ||
if n := xsk.NumFreeFillSlots(); n > 0 { | ||
// ...then fetch up to that number of not-in-use | ||
// descriptors and push them onto the Fill ring queue | ||
// for the kernel to fill them with the received | ||
// frames. | ||
xsk.Fill(xsk.GetDescs(n)) | ||
} | ||
|
||
// Wait for receive - meaning the kernel has | ||
// produced one or more descriptors filled with a received | ||
// frame onto the Rx ring queue. | ||
numRx, _, err := xsk.Poll(-1) | ||
if err != nil { | ||
logger.NewNopLogger().Sugar().Panicln("error: %v\n", err) | ||
return | ||
} | ||
|
||
if numRx > 0 { | ||
// Consume the descriptors filled with received frames | ||
// from the Rx ring queue. | ||
rxDescs := xsk.Receive(numRx) | ||
// Print the received frames and also modify them | ||
// in-place replacing the destination MAC address with | ||
// broadcast address. | ||
for i := 0; i < len(rxDescs); i++ { | ||
pktData := xsk.GetFrame(rxDescs[i]) | ||
mq <- pktData | ||
} | ||
} | ||
} | ||
} |