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