Package jnr.posix

Examples of jnr.posix.CmsgHdr


            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));
View Full Code Here


        MsgHdr message = posix.allocateMsgHdr();
        message.setIov(new ByteBuffer[]{nioBuf});

        if (fd >= 0) {
            CmsgHdr control = message.allocateControl(4);
            ByteBuffer fdBuf = ByteBuffer.allocateDirect(4);
            fdBuf.order(ByteOrder.nativeOrder());
            fdBuf.putInt(fd);
            fdBuf.flip();
            control.setData(fdBuf);
            control.setType(0x01);
            control.setLevel(SocketLevel.SOL_SOCKET.intValue());
        }

        int result = posix.sendmsg(this.fd, message, 0);
    }
View Full Code Here

TOP

Related Classes of jnr.posix.CmsgHdr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.