Minor hacks really.
[egate.git] / util / gipc.c
1 /* Gateway kernel
2  * Europagate, 1995
3  *
4  * $Log: gipc.c,v $
5  * Revision 1.4  1995/04/20 15:12:45  adam
6  * Minor hacks really.
7  *
8  * Revision 1.3  1995/04/19  16:02:06  adam
9  * Some hacks to get the FIFO communication work!! Isn't reliable.
10  *
11  * Revision 1.2  1995/03/28  08:03:46  adam
12  * Non-blocking open used when sync is set.
13  *
14  * Revision 1.1  1995/03/27  08:24:59  adam
15  * New module gip: Gateway IPc module.
16  * New module gw-db: Gateway hash-db module (user information table).
17  *
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <assert.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26
27 #include <gw-log.h>
28 #include <gip.h>
29
30 GIP gipc_initialize (const char *name)
31 {
32     return gip_initialize (name);
33 }
34
35 int gipc_destroy (GIP gip)
36 {
37     return gip_destroy (gip);
38 }
39
40 int gipc_open (GIP gip, const char *server, int sync)
41 {
42     if (sync) 
43     {
44         gw_log (GW_LOG_DEBUG, "gipc", "Open readonly of %s", gip->name);
45         gip->rfd = open (gip->name, O_RDONLY);
46         gw_log (GW_LOG_DEBUG, "gipc", "Open writeonly of %s", server);
47         gip->wfd = open (server, O_WRONLY);
48     }
49     else
50     {
51         gip->wfd = open (server, O_WRONLY|O_NONBLOCK);
52         gip->rfd = open (gip->name, O_RDONLY|O_NONBLOCK);
53     }
54     if (gip->rfd == -1)
55         return -1;
56     if (gip->wfd == -1)
57         return -2;
58     fcntl (gip->wfd, F_SETFL, 0);
59     fcntl (gip->rfd, F_SETFL, 0);
60     return 0;
61 }
62
63 int gipc_close (GIP gip)
64 {
65     if (gip->rfd != -1)
66     {
67         close (gip->rfd);
68         gip->rfd = -1;
69     }
70     if (gip->wfd != -1)
71     {
72         close (gip->wfd);
73         gip->wfd = -1;
74     }
75     return 0;
76 }