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