Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / msg.cc
blob373973eacd20bbc3375dff2eade9ad9a52b1eb77
1 /* msg.cc: XSI IPC interface for Cygwin.
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
9 #include "winsup.h"
10 #include <unistd.h>
12 #include "sigproc.h"
13 #include "cygtls.h"
15 #include "cygserver_msg.h"
18 * client_request_msg Constructors
21 client_request_msg::client_request_msg (int msqid,
22 int cmd,
23 struct msqid_ds *buf)
24 : client_request (CYGSERVER_REQUEST_MSG, &_parameters, sizeof (_parameters))
26 _parameters.in.msgop = MSGOP_msgctl;
27 ipc_set_proc_info (_parameters.in.ipcblk);
29 _parameters.in.ctlargs.msqid = msqid;
30 _parameters.in.ctlargs.cmd = cmd;
31 _parameters.in.ctlargs.buf = buf;
33 msglen (sizeof (_parameters.in));
36 client_request_msg::client_request_msg (key_t key,
37 int msgflg)
38 : client_request (CYGSERVER_REQUEST_MSG, &_parameters, sizeof (_parameters))
40 _parameters.in.msgop = MSGOP_msgget;
41 ipc_set_proc_info (_parameters.in.ipcblk);
43 _parameters.in.getargs.key = key;
44 _parameters.in.getargs.msgflg = msgflg;
46 msglen (sizeof (_parameters.in));
49 client_request_msg::client_request_msg (int msqid,
50 void *msgp,
51 size_t msgsz,
52 long msgtyp,
53 int msgflg)
54 : client_request (CYGSERVER_REQUEST_MSG, &_parameters, sizeof (_parameters))
56 _parameters.in.msgop = MSGOP_msgrcv;
57 ipc_set_proc_info (_parameters.in.ipcblk);
59 _parameters.in.rcvargs.msqid = msqid;
60 _parameters.in.rcvargs.msgp = msgp;
61 _parameters.in.rcvargs.msgsz = msgsz;
62 _parameters.in.rcvargs.msgtyp = msgtyp;
63 _parameters.in.rcvargs.msgflg = msgflg;
65 msglen (sizeof (_parameters.in));
68 client_request_msg::client_request_msg (int msqid,
69 const void *msgp,
70 size_t msgsz,
71 int msgflg)
72 : client_request (CYGSERVER_REQUEST_MSG, &_parameters, sizeof (_parameters))
74 _parameters.in.msgop = MSGOP_msgsnd;
75 ipc_set_proc_info (_parameters.in.ipcblk);
77 _parameters.in.sndargs.msqid = msqid;
78 _parameters.in.sndargs.msgp = msgp;
79 _parameters.in.sndargs.msgsz = msgsz;
80 _parameters.in.sndargs.msgflg = msgflg;
82 msglen (sizeof (_parameters.in));
86 * XSI message queue API. These are exported by the DLL.
89 extern "C" int
90 msgctl (int msqid, int cmd, struct msqid_ds *buf)
92 syscall_printf ("msgctl (msqid = %d, cmd = %y, buf = %p)", msqid, cmd, buf);
93 __try
95 switch (cmd)
97 case IPC_STAT:
98 break;
99 case IPC_SET:
100 break;
101 case IPC_RMID:
102 break;
103 case IPC_INFO:
104 break;
105 case MSG_INFO:
106 break;
107 default:
108 syscall_printf ("-1 [%d] = msgctl ()", EINVAL);
109 set_errno (EINVAL);
110 __leave;
112 client_request_msg request (msqid, cmd, buf);
113 if (request.make_request () == -1 || request.retval () == -1)
115 syscall_printf ("-1 [%d] = msgctl ()", request.error_code ());
116 set_errno (request.error_code ());
117 __leave;
119 return request.retval ();
121 __except (EFAULT) {}
122 __endtry
123 return -1;
126 extern "C" int
127 msgget (key_t key, int msgflg)
129 syscall_printf ("msgget (key = %U, msgflg = %y)", key, msgflg);
130 client_request_msg request (key, msgflg);
131 if (request.make_request () == -1 || request.retval () == -1)
133 syscall_printf ("-1 [%d] = msgget ()", request.error_code ());
134 set_errno (request.error_code ());
135 return -1;
137 return request.retval ();
140 extern "C" ssize_t
141 msgrcv (int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
143 syscall_printf ("msgrcv (msqid = %d, msgp = %p, msgsz = %ld, "
144 "msgtyp = %d, msgflg = %y)",
145 msqid, msgp, msgsz, msgtyp, msgflg);
146 __try
148 client_request_msg request (msqid, msgp, msgsz, msgtyp, msgflg);
149 if (request.make_request () == -1 || request.rcvval () == -1)
151 syscall_printf ("-1 [%d] = msgrcv ()", request.error_code ());
152 set_errno (request.error_code ());
153 __leave;
155 return request.rcvval ();
157 __except (EFAULT) {}
158 __endtry
159 return -1;
162 extern "C" int
163 msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg)
165 syscall_printf ("msgsnd (msqid = %d, msgp = %p, msgsz = %ld, msgflg = %y)",
166 msqid, msgp, msgsz, msgflg);
167 __try
169 client_request_msg request (msqid, msgp, msgsz, msgflg);
170 if (request.make_request () == -1 || request.retval () == -1)
172 syscall_printf ("-1 [%d] = msgsnd ()", request.error_code ());
173 set_errno (request.error_code ());
174 __leave;
176 return request.retval ();
178 __except (EFAULT) {}
179 __endtry
180 return -1;