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());
}
}
Aggregations