posix
Class MsgQ

java.lang.Object
  extended by posix.IPC
      extended by posix.MsgQ

public class MsgQ
extends IPC

Represent a posix message queue.


Nested Class Summary
static class MsgQ.msqid_ds
           
 
Nested classes/interfaces inherited from class posix.IPC
IPC.Perm
 
Field Summary
static int MSG_NOERROR
           
 
Fields inherited from class posix.IPC
egid, euid, id, IPC_ALLOC, IPC_CI, IPC_CREAT, IPC_EXCL, IPC_NOCLEAR, IPC_NOWAIT, IPC_PHYS, IPC_PRIVATE, owner, pid
 
Constructor Summary
MsgQ(int qid)
           
MsgQ(int key, int flag)
           
MsgQ(String path, int id)
          Attach to an existing message queue.
 
Method Summary
 MsgQ.msqid_ds getStatus()
          Return the permissions for this IPC data structure.
static int msgget(int key, int flag)
           
 int recv(CPtr msg, int type, int flag)
          Receive a message into a CPtr.
 int recv(int[] type, byte[] msg, int mtype, int flag)
          Receive a message in a byte array.
 void remove()
          Remove the message queue from the system.
 int send(CPtr msg, int size, int flag)
          Send a message contained in a CPtr.
 int send(int type, byte[] msg, int size, int flag)
          Send a message contained in a byte array.
 void setPerm(IPC.Perm st)
          Set the uid, gid, mode, qbytes for this IPC data structure.
 
Methods inherited from class posix.IPC
dispose, finalize, ftok, getId, getPerm, isPidValid, setPerm
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MSG_NOERROR

public static final int MSG_NOERROR
See Also:
Constant Field Values
Constructor Detail

MsgQ

public MsgQ(int key,
            int flag)
     throws IPCException
Throws:
IPCException

MsgQ

public MsgQ(int qid)

MsgQ

public MsgQ(String path,
            int id)
     throws IPCException
Attach to an existing message queue.

Throws:
IPCException
Method Detail

msgget

public static int msgget(int key,
                         int flag)

send

public int send(int type,
                byte[] msg,
                int size,
                int flag)
Send a message contained in a byte array.

Returns:
0 for success, -1 for failure

recv

public int recv(int[] type,
                byte[] msg,
                int mtype,
                int flag)
Receive a message in a byte array.

Parameters:
mtype - selects which messages to receive
type - returns the mtype of the message received
Returns:
-1 for failure, or the number of bytes stored in the byte array.

send

public int send(CPtr msg,
                int size,
                int flag)
         throws IPCException
Send a message contained in a CPtr. This can be convenient when it is necessary to build C data structures in the message to interface with C code. Unlike the posix system call, the size is the actual size of the message - including the required mtype field as the first element.

Parameters:
msg - The message to send in native format.
size - The message size including the type.
flag - Options.
Returns:
0 for success, Errno.EAGAIN if queue full and IPC_NOWAIT option specified.
Throws:
IPCException

recv

public int recv(CPtr msg,
                int type,
                int flag)
         throws IPCException
Receive a message into a CPtr. This can be convenient when the message contains C data structures. Unlike the posix system call, the size returned is the actual message size including the required mtype field as the first element. If this call fails, the posix error code can be retrieved with the Errno class before any further I/O takes place in this Thread.

Returns:
-1 for failure, or the received message size
Throws:
IPCException

remove

public void remove()
Remove the message queue from the system.

Specified by:
remove in class IPC

getStatus

public MsgQ.msqid_ds getStatus()
                        throws IPCException
Description copied from class: IPC
Return the permissions for this IPC data structure.

Specified by:
getStatus in class IPC
Throws:
IPCException

setPerm

public void setPerm(IPC.Perm st)
             throws IPCException
Set the uid, gid, mode, qbytes for this IPC data structure. Only a process with appropriate privileges can raise the value of msg_qbytes.

Specified by:
setPerm in class IPC
Parameters:
st - a current msqid_ds obtained from getStatus()
Throws:
IPCException