31 |
#include "access.h" |
#include "access.h" |
32 |
#include "if.h" |
#include "if.h" |
33 |
#include "buffer.h" |
#include "buffer.h" |
|
#include "options.h" |
|
|
#include "utils.h" |
|
34 |
|
|
35 |
int access_fd = -1; |
#include "protocol.h" |
36 |
int if_fd = -1; |
#include "engine.h" |
37 |
|
|
38 |
|
int fd = -1; |
39 |
int exiting; |
int exiting; |
40 |
|
|
41 |
buffer_t access_in, access_out, if_in, if_out; |
buffer_t in, out; |
42 |
|
|
43 |
int |
int |
44 |
engine_init () |
engine_init () |
45 |
{ |
{ |
46 |
if ((access_fd = access_getfd ()) < 0) |
if ((fd = *(haccess->fd)) < 0) |
47 |
{ |
{ |
48 |
log (LOG_ERR, "ENGINE - Cound not open input device\n"); |
log (LOG_ERR, "ENGINE - Cound not open input device\n"); |
49 |
return 0; |
return 0; |
50 |
} |
} |
51 |
if ((if_fd = if_getfd ()) < 0) |
|
52 |
{ |
exiting = 0; |
53 |
log (LOG_ERR, "ENGINE - Could not open interface file descriptor\n"); |
protocol->init (&in, &out); |
|
return 0; |
|
|
} |
|
|
|
|
|
create_buffer (&if_in, 3000); |
|
|
create_buffer (&if_out, 3000); |
|
54 |
|
|
55 |
return 1; |
return 1; |
56 |
} |
} |
67 |
int fds; |
int fds; |
68 |
int timedout = 0; |
int timedout = 0; |
69 |
|
|
70 |
while (exiting) |
while (!exiting) |
71 |
{ |
{ |
72 |
FD_ZERO (&rfdset); |
FD_ZERO (&rfdset); |
73 |
FD_ZERO (&wfdset); |
FD_ZERO (&wfdset); |
74 |
FD_ZERO (&efdset); |
FD_ZERO (&efdset); |
75 |
|
|
76 |
|
|
77 |
tv.tv_sec = 30; /* arbitrary value should be good */ |
tv.tv_sec = 30; /* arbitrary value should be good */ |
78 |
tv.tv_usec = 0; |
tv.tv_usec = 0; |
79 |
timedout = 0; |
timedout = 0; |
80 |
fds = select (maxfd, &rfdset, &wfdset, &efdset, &tv); |
fds = select (maxfd, &rfdset, &wfdset, &efdset, &tv); |
81 |
|
|
82 |
if (access_is_connected ()) |
if (haccess->is_connected ()) |
83 |
{ |
{ |
84 |
if (fds > 0) |
if (fds > 0) |
85 |
{ |
{ |
86 |
if (FD_ISSET (access_fd, &rfdset)) |
if (FD_ISSET (fd, &rfdset)) |
87 |
{ |
{ |
88 |
buffer_recv (&access_in, access_fd); |
buffer_recv (&in, fd); |
89 |
} |
} |
90 |
if (FD_ISSET (access_fd, &wfdset)) |
if (FD_ISSET (fd, &wfdset)) |
91 |
buffer_send (&access_out, access_fd); |
buffer_send (&out, fd); |
92 |
|
|
|
if (FD_ISSET (if_fd, &rfdset)) |
|
|
{ |
|
|
debug (5, "Read data from if_fd\n"); |
|
|
buffer_recv (&if_in, if_fd); |
|
|
} |
|
|
|
|
|
if (FD_ISSET (if_fd, &wfdset)) |
|
|
{ |
|
|
debug (5, "Send data to if_fd\n"); |
|
|
buffer_send (&if_out, if_fd); |
|
|
} |
|
93 |
} |
} |
94 |
else |
else |
95 |
{ |
{ |