Skip to content

jetlang/epoll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jetlang Epoll

optimized jni epoll wrapper

Features

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

Limitations

  • 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."));