Server for Information Technologies ������ ��������������
������� �������������� ����������
(095) 932-9212, 932-9213, 939-0783
E-mail: [email protected]
������ �������� ����(!) ������������� ���������� CIT Forum CD-ROM

MSGOP(2)

��������
msgop - �������� ��� �������� ���������

���������

        #include <sys/types.h>
        #include <sys/ipc.h>
        #include <sys/msg.h>

        int msgsnd (msqid, msgp, msgsz, msgflg)
        int msqid;
        struct msgbuf *msgp;
        int msgsz, msgflg;

        int msgrcv (msqid, msgp, msgsz, msgtyp, msgflg)
        int msqid;
        struct msgbuf *msgp;
        long msgtyp;
        int msgsz, msgflg;

��������
������� ���������
��������� ����� msgsnd ������������ ��� ����, ����� ��������� ��������� � �������, ��������������� � ��������������� ������� msqid. {��������� ����� �� ������.} �������� msgp �������� ���������� �� ���������, ���������� ���������. ��������� �������� ��������� ����:

     long mtype;     /* ��� ��������� */
     char mtext [];  /* ����� ��������� */

���� mtype �������� ������������� ����� �����, ������� ����� �������������� ���������-����������� ��� ������ ��������� (��. ���� �������� ���������� ������ msgrcv). ���� mtext �������� ����� ������ msgsz ����. �������� msgsz ����� ��������� �������� �� 0 �� �������������� �������� ������.

�������� msgflg ������������� ��������, ���������������, ���� ��������� ���� �� ���� �� ��������� �������:

  1. ������� ���������� ���� � ������� ��� ����� �������� ���� msg_qbytes ��������������� ��������� ������ [��. intro(2)].
  2. ����� ���������� ��������� �� ���� �������� ������� ����� ����������� ����������� ��������.
��������, ��������������� ���������� msgflg, ���������:
  1. ���� ��������� (msgflg & IPC_NOWAIT) �������, �� ��������� �� ���������� � ����������� �������� ����� �� ������������ ����������.
  2. ���� ��������� (msgflg & IPC_NOWAIT) �����, �� ���������� ����������� �������� ������������� �� ��� ���, ���� �� ���������� ���� �� ��������� �������:

��������� ����� msgsnd ����������� �������� � ��������� �� ����������, ���� ��������� ���� �� ���� �� ��������� �������:

[EINVAL]
������������� ������� ��������� msqid �� �������� ����������.
[EACCES]
� ����������� �������� ��� ���� �� ���������� �������� [��. intro(2)].
[EINVAL]
�������� ���� mtype ������ 1.
[EAGAIN]
��������� �� ����� ���� ������� �� ����� ���� �� ��������� ���� ������, � ��������� (msgflg & IPC_NOWAIT) �������.
[EINVAL]
�������� ��������� msgsz ������ 0 ��� ������ ����������� ����������� � �������.
[EFAULT]
�������� msgp ��������� �� ������� ����������� �������� ��������� ������������.

��� �������� ���������� ������ ��� ���������� ������, ��������������� � ��������������� msqid, ������������ ��������� �������� [��. intro(2)]:

  1. �������� ���� msg_qnum ������������� �� 1.
  2. �������� ���� msg_lspid ��������������� ������ �������������� (������) ����������� ��������.
  3. �������� ���� msg_stime ��������������� ������ �������� �������.

����� ���������
��������� ����� msgrcv �������� ��������� �� �������, ��������������� � ��������������� ������� msqid, � �������� ��� � ���������, �� ������� ��������� �������� msgp. {��������� ����� �� ������.} ��� ��������� ������� �� ��������� �����:

    long mtype;    /* ��� ��������� */
    char mtext []; /* ����� ��������� */

���� mtype �������� ��� ����������� ���������, ������� ��������������� ���������� ���������. ���� mtext �������� ����� ���������. �������� ��������� msgsz ���������� ������ ������ � ������. ���������� ��������� ���������� �� msgsz ����, ���� ��� ����� ��������� msgsz � ��������� (msgflg & MSG_NOERROR) �������. ����������� ����� ��������� ��������� � ���������� ������� �� �������� �������� ����������� �� ���������.

�������� msgtyp ������������� ��� �������������� ��������� � ������������ �� ���������� ������������:

  1. ���� �������� msgtyp ����� 0, ��������� ������ ��������� � �������.
  2. ���� �������� msgtyp ������ 0, ��������� ������ ��������� ���� msgtyp.
  3. ���� �������� msgtyp ������ 0, ��������� ������ ��������� ����������� �� �����, ������� ������ ��� ����� ���������� �������� ��������� msgtyp.

�������� msgflg ������������� ��������, ��������������� � ��� ������, ���� � ������� ��� ��������� ������� ����. ��� �������� ���������:

  1. ���� ��������� (msgflg & IPC_NOWAIT) �������, �� ���������� ������� ����� �� �������� ����������, ��� ������������ -1 � errno ������������� �������� ENOMSG.
  2. ���� ��������� (msgflg & IPC_NOWAIT) �����, �� ���������� ����������� �������� ������������������ �� ��� ���, ���� �� ���������� ���� �� ��������� �������:

��������� ����� msgrcv ����������� �������� � ��������� �� �����������, ���� ��������� ���� �� ���� �� ��������� �������:

[EINVAL]
�������� ��������� msgid �� �������� ���������� ��������������� ������� ���������.
[EACCES]
� ����������� �������� ��� ���� �� ���������� ��������.
[EINVAL]
�������� ��������� msgsz ������ 0.
[E2BIG]
������ ��������� ������ msgsz � ��������� (msgflg & MSG_NOERROR) �����.
[ENOMSG]
������� �� �������� ��������� ������� ���� � ��������� (msgflg & IPC_NOWAIT) �������.
[EFAULT]
�������� msgp ��������� �� ������� ����������� �������� ��������� ������������.

��� �������� ���������� ������ ��� ���������� ������, ��������������� � ��������������� msqid, ������������ ��������� �������� [��. intro(2)]:

  1. �������� ���� msg_qnum ����������� �� 1.
  2. �������� ���� msg_lrpid ��������������� ������ �������������� (������) ����������� ��������.
  3. �������� ���� msg_rtime ��������������� ������ �������� �������.

��. �����
intro(2), msgctl(2), msget(2), signal(2).

�����������
���� ��������� ���� ��������� ������ ����������� �������� ��-�� ��������� �������, �� ����������� �������� ������������ -1, � ���������� errno ������������� �������� EINTR. ���� ��������� ������ ����������� �������� ��-�� �������� �� ������� �������������� ������� msqid, �� ������������ -1 � errno ������������� �������� EIDRM.

��� �������� ���������� ��������� ������� ������������ ��������� ��������:

  1. Msgsnd ���������� 0.
  2. Msgrcv ���������� ��������, ������ ���������� ����, ������������� ���������� � ���� mtext.

� ���� ������� ������������ -1, � ���������� errno ������������� ��� ������.
Comments: [email protected]
Designed by Andrey Novikov
Copyright © CIT