public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* [ERROR] msgget() "Function not implmented" Error : Cygwin
@ 2023-02-28 10:13 Yeo Kai Wei
  2023-02-28 10:29 ` Corinna Vinschen
  0 siblings, 1 reply; 5+ messages in thread
From: Yeo Kai Wei @ 2023-02-28 10:13 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

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

[-- Attachment #2: sender.c --]
[-- Type: text/plain, Size: 1070 bytes --]

#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;
}


[-- Attachment #3: queue.h --]
[-- Type: text/plain, Size: 241 bytes --]

#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;



[-- Attachment #4: receiver.c --]
[-- Type: text/plain, Size: 1077 bytes --]

#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;
}


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-03-05 16:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-28 10:13 [ERROR] msgget() "Function not implmented" Error : Cygwin Yeo Kai Wei
2023-02-28 10:29 ` Corinna Vinschen
2023-03-01 11:56   ` Yeo Kai Wei
2023-03-01 18:36     ` Ken Brown
2023-03-05 16:35   ` [ERROR] msgget() "Function not implemented" " Yeo Kai Wei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).