Search in sources :

Example 6 with Header

use of org.aion.p2p.Header in project aion by aionnetwork.

the class TaskWrite method run.

@Override
public void run() {
    /*
         * @warning header set len (body len) before header encode
         */
    try {
        byte[] bodyBytes = msg.encode();
        int bodyLen = bodyBytes == null ? 0 : bodyBytes.length;
        Header h = msg.getHeader();
        h.setLen(bodyLen);
        byte[] headerBytes = h.encode();
        // print route
        // System.out.println("write " + h.getVer() + "-" + h.getCtrl() + "-" +
        // h.getAction());
        ByteBuffer buf = ByteBuffer.allocate(headerBytes.length + bodyLen);
        buf.put(headerBytes);
        if (bodyBytes != null)
            buf.put(bodyBytes);
        buf.flip();
        // send outbound event to ioLoop for I/O
        this.ioLoop.write(buf, this.sc);
    } catch (Exception e) {
        System.out.println("<p2p-taskWrite-throw>" + e.toString());
    }
}
Also used : Header(org.aion.p2p.Header) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Header (org.aion.p2p.Header)6 IOException (java.io.IOException)4 ByteBuffer (java.nio.ByteBuffer)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 SocketException (java.net.SocketException)2 Handler (org.aion.p2p.Handler)2 INode (org.aion.p2p.INode)2 InetSocketAddress (java.net.InetSocketAddress)1 SelectionKey (java.nio.channels.SelectionKey)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 ArrayList (java.util.ArrayList)1 Msg (org.aion.p2p.Msg)1 TaskUPnPManager (org.aion.p2p.impl.TaskUPnPManager)1 ReqHandshake1 (org.aion.p2p.impl.zero.msg.ReqHandshake1)1