7 messages in net.java.dev.jna.usersRe: [jna-users] Mapping posix message...
FromSent OnAttachments
Patrick SchäferMay 8, 2009 3:53 am 
Timothy WallMay 8, 2009 4:02 am 
Patrick SchäferMay 8, 2009 4:50 am 
Daniel KaufmannMay 8, 2009 5:35 am 
Timothy WallMay 8, 2009 5:37 am 
Patrick SchäferMay 8, 2009 6:35 am 
Timothy WallMay 8, 2009 6:55 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Mapping posix message queue in C to JavaActions...
From:Daniel Kaufmann (dani@gmail.com)
Date:May 8, 2009 5:35:04 am
List:net.java.dev.jna.users

Please looke at man pages for msgsnd, (here is an online man for linux http://linux.die.net/man/2/msgsnd) It says that:

"The *msgp* argument is a pointer to caller-defined structure of the following general form:

struct msgbuf {

long mtype; /* message type, must be > 0 */ char mtext[1]; /* message data */ };"

So you should map it to a structure similar to this:

public static class Msgbuf extends *Structure* { public NativeLong mtype;

public byte[] mtext;

}

and you should set mtext to appropiate data. Make sure you set mtype to a value > 0. msgsz seem to be the size of mtext, and make sure that you are passing correct value to *msqid*, meaning that is really a message queue identifier. Finally make sure the msgflg you are passing are correct. They seem not to be correct according to the man page in the link above (they look like the ones for msgget that seem to be used for creating the queue but it might be different in your system).

-Daniel On Fri, May 8, 2009 at 7:51 AM, Patrick Schäfer <ps@ekse.de> wrote:

According to the man page, you need to look at the value of errno

(Native.getLastError()) to determine the reason for failure if the call returns -1.

thank you for your response. Native.getLastError results in error code 22 which is "Invalid argument". I guess this means the jna mapping is incorrect?

I suppose this is due to the second argument "void *msgp"? According to the documentation void* should map to Pointer like this: int msgsnd(int msqid,Pointer msgp, int msgsz, int msgflg);

But how to instantiate a pointer? all constructors seem to be package-private.

On May 8, 2009, at 6:53 AM, Patrick Schäfer wrote:

Hi,

I am sry, but I am new to JNA.

I am trying to make a mapping for posix message queues in C (sys/msg) to Java on my unix pc. but seem to be doing something completely wrong. Maybe anyone can help me with this?

Original C declaration int msgsnd(int msqid, const void *msgp, size_t msgsz,int msgflg); int msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp,int msgflg); int msgctl(int msqid, int cmd, struct msqid_ds *buf )

My equivalent JNA mapping int msgsnd(int msqid, byte[] msgp, int msgsz, int msgflg); int msgrcv(int msqid, byte[] msgp, int msgsz, NativeLong msgtyp, int msgflg); int msgctl(int msqid, int cmd, Structure buf );

Now I am not sure which library to load. Native.loadLibrary("sys/msg", CLibrary.class) fails with an error.

The library "c" seems to have the function msgsnd, which I tested by Function test = NativeLibrary.getInstance("c").getFunction("msgrcv");

Therefor the library file is loaded by CLibrary INSTANCE = (CLibrary) Native.loadLibrary("c", CLibrary.class);

But trying to receive oder submit messages by int rc = CLibrary.INSTANCE.msgsnd( 0x0a0001c2, "test".getBytes(), 4, IPC_CREAT | 0666);

always results in the return code -1 without any exception or any other failure. is there a way to get further debug information?

thank you very much for any help.