ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
MsgHdr message = posix.allocateMsgHdr();
message.allocateControl(4);
message.setIov(new ByteBuffer[]{buffer});
CmsgHdr control = message.getControls()[0];
int numRead = posix.recvmsg(this.fd, message, 0);
if (numRead < 0) {
if (!this.closed) {
writeInbound(new IPCRecord(null, -1));
}
break;
}
if (numRead > 0) {
if ( numRead == 1 ) {
int position = buffer.position();
if( buffer.get() == 0 ) {
writeInbound(new IPCRecord(null, -1));
break;
}
buffer.position( position );
}
int fd = -1;
buffer.limit(numRead);
ByteBuf nettyBuf = alloc().buffer(numRead);
nettyBuf.writeBytes(buffer);
if (control.getType() == 0x01 && control.getLevel() == SocketLevel.SOL_SOCKET.intValue()) {
fd = control.getData().order(ByteOrder.nativeOrder()).getInt();
}
IPCRecord record = new IPCRecord(nettyBuf, fd);
writeInbound(record);
} else {
writeInbound(new IPCRecord(null, -1));