root/trunk/src/msg_mgmt.c @ 54

Revision 28, 2.1 KB (checked in by andreu, 16 years ago)

debug mode in compilation option - Wno-long-long - copyright update

  • Property svn:eol-style set to native
Line 
1/*
2 * File: msg_mgmt.c
3 *
4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2005 2006 2007 GIP RENATER
7 */
8
9/*  This file is part of renetcol.
10 *
11 *  renetcol is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  renetcol is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with renetcol; if not, write to the Free Software
23 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 */
25
26#include <stdio.h>
27#include <string.h>
28#include <errno.h>
29#include <stdlib.h>
30#include <sys/types.h>
31#include <sys/ipc.h>
32#include <sys/msg.h>
33#include <syslog.h>
34
35#include "msg_mgmt.h"
36
37/*
38 * createKey()
39 */
40key_t
41createKey(char *argzero){
42  key_t key;
43  if ((key = ftok (argzero, 0)) == -1) {
44    perror ("ftok");
45    exit(-1);
46  }
47  return key;
48}
49
50/*
51 * createQueue()
52 */
53int
54createQueue(key_t key){
55  int file;
56  if ((file = msgget (key, IPC_CREAT | 0x660)) == -1) {
57    perror ("msgget");
58    exit(-1);
59  }
60  return file;
61}
62
63/*
64 * msgSend()
65 */
66void
67msgSend(int file, msgType msg){
68  if (msgsnd (file, (void *) & msg, sizeof(msg.text),
69              IPC_NOWAIT) <0) {
70    if (errno == EAGAIN) {
71      syslog(LOG_INFO,"The IPC queue is full, I don't wait");
72    } else {
73      syslog(LOG_ERR,"msgsnd : %s", strerror(errno));
74      exit(1);
75    }
76  }
77}
78
79/*
80 * msgRcv()
81 */
82unsigned char *
83msgRcv(int file, msgType *msg, long type)
84{
85  if (msgrcv (file, (void *) msg, sizeof(msg->text), type, 0) >= 0){
86    return (unsigned char *)msg->text;
87  } else if (errno == EINTR) {
88    syslog(LOG_INFO,"msgrcv : Internal system call");
89  } else {
90    syslog (LOG_ERR,"msgrcv : %s", strerror(errno));
91    exit(1);
92  }
93  return (unsigned char *)msg->text; /* FIXME return value if error ? */
94}
Note: See TracBrowser for help on using the browser.