Hi Cygwin,
May I ask if there will be an implementation of msgget() on Cygwin for
Windows?
$ gcc -o sender sender.c
$ ./sender
key is 62720123
qid is -1
couldn't get queue id: Function not implemented
I googled the above error and it seems like this issue was raised in 2017.
It was meant to be fixed but I seem to have the same problem.
May I ask what I should do?
I've attached the files that I used.
Thank you.
Kind Regards,
YEO Kai Wei
#include <stdio.h>
#include <sys/ipc.h> //ftok(). File-to-key?
#include <sys/msg.h> //msgget
#include <stdlib.h>
#include <string.h>
#include "queue.h"
void report_and_exit(const char* msg)
{
perror(msg);
exit(-1);
}
int main()
{
key_t key = ftok(PATHNAME, PROJECTID);
if(key<0)
report_and_exit("couldn't get key...");
printf("key is %i\n", key);
//msgget() creates message queue
//Returns System V message qid associated with value of key argument.
int qid = msgget(key, 0666 | IPC_CREAT);
printf("qid is %i\n", qid);
//Ran into error here
if(qid<0)
report_and_exit("couldn't get queue id");
char* payloads[] = {"msg1","msg2","msg3","msg4","msg5","msg6"};
int types[] = {1,1,2,2,3,3};
int i;
for( i = 0; i< MESSAGECOUNT ; i++)
{
//Type from queue.h
queuedMessage msg;
msg.type = types[i];
strcpy(msg.payload, payloads[i]);
msgsnd(qid,&msg,MESSAGELENGTH + 1, IPC_NOWAIT);
printf("%s sent as type %i\n", msg.payload, (int) msg.type);
}
return 0;
}
#define PROJECTID 123
#define PATHNAME "queue.h"
#define MESSAGELENGTH 4
#define MESSAGECOUNT 6
typedef struct
{
long type; //message type
char payload[MESSAGELENGTH + 1]; //message. Some text.
} queuedMessage;
#include <stdio.h>
#include <sys/ipc.h> //ftok() convert pathname + ProjecID to System V IPC key
#include <sys/msg.h>
#include <stdlib.h>
#include "queue.h"
void report_and_exit(const char* msg)
{
perror(msg);
exit(-1);
}
int main()
{
//Sys V IPC key
key_t key = ftok(PATHNAME, PROJECTID);
printf("key is %i\n", key);
if(key<0)
report_and_exit("key not gotten");
//Create if needed, otherwise access. Not create again.
int qid = msgget(key, 0666 | IPC_CREAT);
if(qid < 0)
report_and_exit("no access to queue...");
//Different from sender.c
int types[] = {3,1,2,1,3,2};
int i;
//Sender.c uses msgsend(). Receiver.c uses msgrcv()
for(i=0; i < MESSAGECOUNT ; i++)
{
queuedMessage msg;
if(msgrcv(qid,&msg, MESSAGELENGTH + 1, types[i], MSG_NOERROR |
IPC_NOWAIT) < 0)
puts("msgrcv trouble...");
printf("%s received as type %i\n", msg.payload, (int) msg.type);
}
//Remove the q
if(msgctl(qid, IPC_RMID, NULL) < 0)
report_and_exit("trouble removing queue...");
return 0;
}
--
Problem reports: https://cygwin.com/problems.html
FAQ: https://cygwin.com/faq/
Documentation: https://cygwin.com/docs.html
Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple