X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=sources%2FMQFortuneClient.c;fp=sources%2FMQFortuneClient.c;h=0000000000000000000000000000000000000000;hb=d12bc3e1e4b3ee762036d1c226c3b2ba1a720fb9;hp=a26f67217586a423c0d3c06826254f4b045cf17d;hpb=e3e15ed6d698e5cc35f3b7f4c5db96adc38255c3;p=gapil.git diff --git a/sources/MQFortuneClient.c b/sources/MQFortuneClient.c deleted file mode 100644 index a26f672..0000000 --- a/sources/MQFortuneClient.c +++ /dev/null @@ -1,127 +0,0 @@ -/* MQFortuneClient.c - * - * Copyright (C) 2002 Simone Piccardi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -/**************************************************************** - * - * Program fortuned - * Fortune Cleint - Using Message Queues - * - * Author: Simone Piccardi - * Oct. 2002 - * - * Usage: fortune -h give all info - * - * $Id: MQFortuneClient.c,v 1.2 2002/12/03 11:06:05 piccardi Exp $ - * - ****************************************************************/ -/* - * Include needed headers - */ -#include /* predefined types */ -#include /* */ -#include /* include unix standard library */ -#include /* include standard I/O library */ -#include /* standard library */ -#include /* ANSI C standard string */ -#include /* errorstring */ -#include /* signals */ -#include -#include - -#include "macros.h" - -/* Maximum message size */ -#define MSGMAX 8192 - -/* Subroutines declaration */ -void usage(void); - -int main(int argc, char *argv[]) -{ -/* Variables definition */ - int i; - struct msgbuf_read { /* message struct to ask fortune to server */ - long mtype; /* message type, must be 1 */ - long pid; /* message data, must be the pid of the client */ - } msg_read; - struct msgbuf_write { /* message struct to get result from server */ - long mtype; /* message type, will be the pid of the client*/ - char mtext[MSGMAX]; /* message data, will be the fortune */ - } msg_write; - int msgid; /* Message queue identifier */ - key_t key; /* Message queue key */ - int size; /* message size */ - /* - * Input section: decode parameters passed in the calling - * Use getopt function - */ - opterr = 0; /* don't want writing to stderr */ - while ( (i = getopt(argc, argv, "h")) != -1) { - switch (i) { - /* - * Handling options - */ - case 'h': - usage(); - return(0); - break; - case '?': /* unrecognized options */ - printf("Unrecognized options -%c\n", optopt); - usage(); - default: /* should not reached */ - usage(); - } - } - /* *********************************************************** - * - * Options processing completed - * - * Main code beginning - * - * ***********************************************************/ - /* - * Comunication section - */ - key = ftok("./MQFortuneServer.c", 1); - msgid = msgget(key, 0); - if (msgid < 0) { - perror("Cannot find message queue"); - exit(1); - } - - /* Main body: do request and write result */ - msg_read.mtype = 1; /* type for request is always 1 */ - msg_read.pid = getpid(); /* use pid for communications */ - size = sizeof(msg_read.pid); - msgsnd(msgid, &msg_read, size, 0); /* send request message */ - debug("sent request from %d\n", msg_read.pid); - msgrcv(msgid, &msg_write, MSGMAX, msg_read.pid, MSG_NOERROR); - printf("%s", msg_write.mtext); -} -/* - * routine to print usage info and exit - */ -void usage(void) { - printf("Elementary fortune server\n"); - printf("Usage:\n"); - printf(" fortuned [-h] [-f] -n XXX \n"); - printf(" -h print this help\n"); - printf(" -f filename set file for fortunes\n"); - printf(" -n XXX set pool depth\n"); - exit(1); -}