asavie / xdp

Package xdp allows one to use XDP sockets from the Go programming language.
BSD 3-Clause "New" or "Revised" License
298 stars 64 forks source link

Q: what is the correct way to use this for RX and TX at the same time? #11

Open hujun-open opened 3 years ago

hujun-open commented 3 years ago

Hi, I am trying to figure out a correct way to use this pkg for sending & receiving packets over same AF_XDP socket simultaneously, all the AF_XDP socket example I could find is either TX only or RX only or like a server (e.g. receive a packet first, do sth, then send a packet out in one run); but I want to do sending and receiving at the same time; this package doesn't seem to be routine safe, so I can't put RX and TX into two different go routines, however by having both RX and TX in one routine doesn't seem to provide expected performance, sometime it is even slower than using AF_PACKET socket;

so I wonder what is correct way to do this? is there any example that does this sort of thing?

hujun-open commented 3 years ago

I created a PR #12 that allows TX and RX of same socket could be in separate go routine; it addressed the above use case with expected performance

slavc commented 3 years ago

Had the same problem myself recently, thanks for submitting a diff to address this!

yvanu commented 11 months ago

Could you show an example to use it?please.

hujun-open commented 11 months ago

Could you show an example to use it?please.

you could take a look some use of it in etherconn, check the xdpSock.send() and xdpSock.recv()