unix message queues

svn path=/trunk/boinc/; revision=1058
This commit is contained in:
Eric Heien 2003-03-13 21:20:33 +00:00
parent fd525409bb
commit dfb84db067
6 changed files with 149 additions and 5 deletions

View File

@ -3788,11 +3788,17 @@ Eric March 11, 2003
Eric March 12, 2003
- Quit requests are now sent via the SIGQUIT signal (on UNIX)
or an inherited EventHandle (on Windows), rather than via
an XML file
or a named Event (on Windows), rather than via an XML file
api/
boinc_api.C,h
client/
app.C,h
Eric March 13, 2003
- Added System V message queue functions to library
lib/
msg_queue.C,h
msg_test.C

View File

@ -13,7 +13,7 @@ CC = @CC@ $(CFLAGS) -I ../RSAEuro/source
CLIBS = @LIBS@
PROGS = md5_test shmem_test crypt_prog
PROGS = md5_test shmem_test msg_queue_test crypt_prog
# PROGS = md5_test shmem_test synch_test crypt_prog
OBJS = \
@ -52,6 +52,9 @@ md5_test: md5_test.o $(MD5_OBJS)
shmem_test: shmem_test.o shmem.o
$(CC) shmem_test.o shmem.o $(CLIBS) -o shmem_test
msg_queue_test: msg_test.o msg_queue.o
$(CC) msg_test.o msg_queue.o $(CLIBS) -o msg_test
synch_test: synch_test.o synch.o
$(CC) synch_test.o synch.o $(CLIBS) -o synch_test

89
lib/msg_queue.C Normal file
View File

@ -0,0 +1,89 @@
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
//
// The Initial Developer of the Original Code is the SETI@home project.
// Portions created by the SETI@home project are Copyright (C) 2002
// University of California at Berkeley. All Rights Reserved.
//
// Contributor(s):
//
// interfaces for accessing message queues
#include <stdio.h>
#include <string.h>
#include "msg_queue.h"
int create_message_queue(key_t key) {
int mq_id;
mq_id = msgget(key, IPC_CREAT | IPC_EXCL | 0666);
if (mq_id < 0) {
perror("create_message_queue: msgget");
return -1;
}
return 0;
}
int receive_message(key_t key, void *msg, size_t msg_size, bool wait) {
int mq_id, retval;
mq_id = msgget(key, 0666);
if (mq_id < 0) {
perror("receive_message: msgget");
return -1;
}
retval = msgrcv(mq_id, msg, msg_size, 0, (wait?0:IPC_NOWAIT));
if (retval < 0) {
perror("receive_message: msgrcv");
return -1;
}
return 0;
}
int send_message(key_t key, void *msg, size_t msg_size, bool wait) {
int mq_id, retval;
mq_id = msgget(key, 0666);
if (mq_id < 0) {
perror("send_message: msgget");
return -1;
}
retval = msgsnd(mq_id, msg, msg_size, (wait?0:IPC_NOWAIT));
if (retval < 0) {
perror("send_message: msgsnd");
return -1;
}
return 0;
}
int destroy_message_queue(key_t key) {
int mq_id, retval;
mq_id = msgget(key, 0666);
if (mq_id < 0) {
perror("delete_message_queue: msgget");
return -1;
}
retval = msgctl(mq_id, IPC_RMID, NULL);
if (retval) {
perror("delete_message_queue: msgctl");
return -1;
}
return 0;
}

6
lib/msg_queue.h Normal file
View File

@ -0,0 +1,6 @@
#include <sys/msg.h>
extern int create_message_queue(key_t);
extern int receive_message(key_t,void*,size_t,bool);
extern int send_message(key_t,void*,size_t,bool);
extern int destroy_message_queue(key_t);

42
lib/msg_test.C Normal file
View File

@ -0,0 +1,42 @@
// test program for message queue functions
// -d destroy
// -c create
// -s [msg] send message [msg]
// -r receive message
// -rw wait for message
#define KEY 0xb01fcafe
#include <string.h>
#include <stdio.h>
#include "msg_queue.h"
struct my_msg {
long msg_type;
char msg_text[256];
};
int main(int argc, char** argv) {
my_msg the_msg;
int retval;
if (!strcmp(argv[1], "-d")) {
destroy_message_queue(KEY);
} else if (!strcmp(argv[1], "-c")) {
create_message_queue(KEY);
} else if (!strcmp(argv[1], "-rw")) {
retval = receive_message(KEY, &the_msg, sizeof(my_msg),true);
printf("Received message: %s\n", the_msg.msg_text);
} else if (!strcmp(argv[1], "-r")) {
retval = receive_message(KEY, &the_msg, sizeof(my_msg),false);
if (!retval) printf("Received message: %s\n", the_msg.msg_text);
} else if (!strcmp(argv[1], "-s")) {
the_msg.msg_type = 1;
strcpy(the_msg.msg_text, argv[2]);
send_message(KEY, &the_msg, sizeof(my_msg),true);
}
return 0;
}

2
todo
View File

@ -7,10 +7,8 @@ BUGS (arranged from high to low priority)
should there be a user control for this?
- Client treats URL "maggie/ap/" different than URL "maggie/ap",
though this isn't really a bug it might be good to fix anyway
- need a way to refresh prefs from client
- global battery/user active prefs are always true in the client
- Client should display "Upload failed" and "Download failed" when failure occurs
- Download speed is not as fast as it should be
- Result status should say "downloading files", "uploading files", etc.
-----------------------