示例#1
0
int
main(int argc, char **argv)
{
	int		c, flag, mqid;
	long	type;
	ssize_t	n;
	struct msgbuf	*buff;

	type = flag = 0;
	while ( (c = Getopt(argc, argv, "nt:")) != -1) {
		switch (c) {
		case 'n':
			flag |= IPC_NOWAIT;
			break;

		case 't':
			type = atol(optarg);
			break;
		}
	}
	if (optind != argc - 1)
		err_quit("usage: msgrcv [ -n ] [ -t type ] <pathname>");

	mqid = Msgget(Ftok(argv[optind], 0), MSG_R);

	buff = Malloc(MAXMSG);

	n = Msgrcv(mqid, buff, MAXMSG, type, flag);
	printf("read %d bytes, type = %ld\n", n, buff->mtype);

	exit(0);
}
示例#2
0
ssize_t RcvStandardMessage(type_t type) {
	
	CLEAR(standardMessage);
	int x = Msgrcv(SERVER_QUEUE_ID, &standardMessage, sizeof(standardMessage), type, IPC_NOWAIT);
	if (x > 0) {
		Printf("Recieved standard message of type %s [%s]", GetMessageType(type), standardMessage.content.sender);	
	} 
	return x;
}
示例#3
0
ssize_t Rcv(void *structure, int size, long type) {

	memset(structure, 0, size);

	ssize_t x = Msgrcv(SERVER_QUEUE_ID, structure, size, type, IPC_NOWAIT);
	if (x > 0) {
		Printf("Recieved special message of type %s", GetMessageType(type));	
	} 
	return x;
}
示例#4
0
ssize_t RcvCompactMessage(type_t type) {
	
	// printf("Recieving meessage of type %d, queue id is %d\n", type, SERVER_QUEUE_ID);
	CLEAR(compactMessage);
	ssize_t x = Msgrcv(SERVER_QUEUE_ID, &compactMessage, sizeof(compactMessage), type, IPC_NOWAIT);
	if (x > 0) {
		Printf("Recieved compact message of type %s [%s]", GetMessageType(type), compactMessage.content.sender);	
	} 
	return x;
}
示例#5
0
void
reader(int contfd, int msqid, int nbytes)
{
	ssize_t	n;

	Write(contfd, &nbytes, sizeof(nbytes));

	while ((nbytes > 0) &&
		   ( (n = Msgrcv(msqid, buf, xfersize - sizeof(long), 0, 0)) > 0)) {
		nbytes -= n + sizeof(long);
	}
}
示例#6
0
ssize_t RcvHeartBeat() {
	
	CLEAR(compactMessage);
	ssize_t x = Msgrcv(SERVER_QUEUE_ID, &compactMessage, sizeof(compactMessage), MSG_HEARTBEAT, IPC_NOWAIT);
	if (x > 0) {
		Printf("Recieved compact message of type %s [%s]", GetMessageType(MSG_HEARTBEAT), compactMessage.content.sender);	
	} 
	else if (x < 0) {
		int errno;
		if (errno == ENOMSG) return 0;
		Error("Error on hearbeat");
	}
	return x;
}
示例#7
0
int main(int argc, char **argv)
{
	int mqid;
	ssize_t n;
	struct msgbuf *buff;

	if (argc != 2)
		err_quit("Usage: rcv2 <mqid>");
	mqid = atoi(argv[1]);

	buff = (struct msgbuf *)Malloc(MAXMSG);

	n = Msgrcv(mqid, buff, MAXMSG, 0, 0);
	printf("read %d bytes, type = %ld\n", n, buff->mtype);

	exit(0);
}