public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Yeo Kai Wei <yeokaiwei@hotmail.com>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: [ERROR] msgget() "Function not implmented" Error : Cygwin
Date: Tue, 28 Feb 2023 18:13:24 +0800	[thread overview]
Message-ID: <PH0PR05MB991839979E718043F9917BCEA4AC9@PH0PR05MB9918.namprd05.prod.outlook.com> (raw)

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


             reply	other threads:[~2023-02-28 10:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 10:13 Yeo Kai Wei [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PH0PR05MB991839979E718043F9917BCEA4AC9@PH0PR05MB9918.namprd05.prod.outlook.com \
    --to=yeokaiwei@hotmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).