Skip to content

Commit

Permalink
Have FD writing working
Browse files Browse the repository at this point in the history
  • Loading branch information
rm5248 committed Dec 29, 2019
1 parent 09d4111 commit 0c92fc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.util.List;
import jnr.ffi.Pointer;
import jnr.posix.CmsgHdr;
import jnr.posix.MsgHdr;
import jnr.posix.POSIXFactory;
Expand Down Expand Up @@ -63,9 +62,15 @@ public void writeMessage(Message m) throws IOException {
cmsghdr.setType(jnr.constants.platform.SocketLevel.SOL_SOCKET.intValue());
cmsghdr.setLevel(SCM_RIGHTS);
ByteBuffer bb = ByteBuffer.allocateDirect(fds.size() * 4);
if( m.getEndianess() == Message.Endian.BIG ){
bb.order( ByteOrder.BIG_ENDIAN );
}else{
bb.order( ByteOrder.LITTLE_ENDIAN );
}
for( FileDescriptor fd : fds ){
bb.putInt( fd.getIntFileDescriptor() );
}
bb.flip();
cmsghdr.setData(bb);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ private int appendone(byte[] sigb, int sigofs, Object data) throws DBusException
case ArgumentType.FILEDESCRIPTOR:
filedescriptors.add((FileDescriptor)data);
appendint(filedescriptors.size() - 1, 4);
headers.put(HeaderField.UNIX_FDS, filedescriptors.size() - 1);
logger.debug( "Just inserted {} as filedescriptor", filedescriptors.size() - 1 );
break;
case ArgumentType.STRING:
case ArgumentType.OBJECT_PATH:
Expand Down Expand Up @@ -1311,6 +1311,10 @@ public void setSource(String source) throws DBusException {
public byte getType() {
return type;
}

public byte getEndianess() {
return big ? Endian.BIG : Endian.LITTLE;
}

/** Defines constants representing the flags which can be set on a message. */
public interface Flags {
Expand Down

0 comments on commit 0c92fc9

Please sign in to comment.