Skip to content
optimized jni epoll wrapper
Java C++ C Makefile Shell
Branch: master
Clone or download
Latest commit 33fa70d Aug 10, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Run script and git ignore Aug 6, 2019
src make compatible with jdk8+ Aug 9, 2019
.gitignore Run script and git ignore Aug 6, 2019
Makefile make compatible with jdk8+ Aug 9, 2019
README.md update Aug 10, 2019
epoll.iml add jar target. Aug 8, 2019
latency.sh simplify Aug 7, 2019
package.fig cleanup options. Aug 8, 2019
run.sh Run script and git ignore Aug 6, 2019

README.md

Jetlang Epoll

optimized jni epoll wrapper

Features

  • Zero Allocations
  • Zero Copies
  • Multi-message receive using recvmmsg
  • Easier to use Api compared to Nio

Limitations

  • UDP only (unicast & multicast). Tcp support is in development.
  • Linux Only
  • JDK 8+

Building

make all JAVA_HOME=/path/to/your/jdk1.8

Example

DatagramChannel rcv = DatagramChannel.open();
rcv.socket().bind(new InetSocketAddress(9999));
rcv.configureBlocking(false);
EPoll e = new EPoll("epoll", 5, 16, 1024 * 2, new PollStrategy.Wait(), EventBatch.NO_OP);
e.start();
e.register(rcv, new DatagramReader() {
    @Override
    public EventResult readPackets(int numRecv, EPoll.Packet[] pkts) {
        for (int i = 0; i < numRecv; i++) {
            EPoll.Packet pkt = pkts[i];
            System.out.println(i + "/" + numRecv +" packet length " + pkt.getLength());
            System.out.println("first byte of msg: " + pkt.unsafe.getByte(pkt.bufferAddress));
        }
        return EventResult.Continue;
    }

    @Override
    public void onRemove() {
        try {
            rcv.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
});  

//The Epoll instance is also an executor
e.execute(()-> System.out.println("Hello on epoll thread."));
You can’t perform that action at this time.