51 |
|
|
52 |
buffer_t access_in, access_out, if_in, if_out; |
buffer_t access_in, access_out, if_in, if_out; |
53 |
|
|
54 |
#define BUFFER_SIZE MAX_PACKET_SIZE*2 /* each buffer can handle 2 full packets */ |
/* each buffer can handle 2 full packets */ |
55 |
|
#define BUFFER_SIZE MAX_PACKET_SIZE*2 |
56 |
|
|
57 |
#define WINDOW 10 /* Packet we can send/receive without ack */ |
#define WINDOW 10 /* Packet we can send/receive without ack */ |
58 |
|
|
59 |
int |
int |
60 |
prot30_start () |
prot30_start () |
61 |
{ |
{ |
62 |
access_fd = access_getfd (); |
if ((access_fd = access_getfd ()) < 0) |
63 |
if_fd = if_getfd (); |
{ |
64 |
|
fprintf (stderr, "Cound not open input device\n"); |
65 |
|
return 0; |
66 |
|
} |
67 |
|
if ((if_fd = if_getfd ()) < 0) |
68 |
|
{ |
69 |
|
fprintf (stderr, "Could not open interface file descriptor\n"); |
70 |
|
return 0; |
71 |
|
} |
72 |
|
|
73 |
client_seq = PACKET_MAX_SEQ; |
client_seq = PACKET_MAX_SEQ; |
74 |
server_lastack = 0; /* We have never received a packet */ |
server_lastack = 0; /* We have never received a packet */ |
122 |
|
|
123 |
case normal: |
case normal: |
124 |
FD_SET (access_fd, &rfdset); |
FD_SET (access_fd, &rfdset); |
|
if (access_out.used > 0) |
|
|
FD_SET (access_fd, &wfdset); |
|
125 |
|
|
126 |
if (buffer_percent_free (&access_out) > 20) |
if (buffer_percent_free (&access_out) > 20) |
127 |
/* Make sure we have enough space for some ACK */ |
/* Make sure we have enough space for some ACK */ |
128 |
FD_SET (if_fd, &rfdset); |
FD_SET (if_fd, &rfdset); |
129 |
|
|
130 |
|
if (access_out.used > 0) |
131 |
|
FD_SET (access_fd, &wfdset); |
132 |
|
|
133 |
if (if_out.used > 0) |
if (if_out.used > 0) |
134 |
FD_SET (if_fd, &wfdset); |
FD_SET (if_fd, &wfdset); |
135 |
|
|
142 |
continue; |
continue; |
143 |
} |
} |
144 |
|
|
145 |
tv.tv_sec = 10; /* arbitrary value should be good */ |
tv.tv_sec = 30; /* arbitrary value should be good */ |
146 |
tv.tv_usec = 0; |
tv.tv_usec = 0; |
147 |
timedout = 0; |
timedout = 0; |
148 |
fds = select (maxfd, &rfdset, &wfdset, &efdset, &tv); |
fds = select (maxfd, &rfdset, &wfdset, &efdset, &tv); |
160 |
|
|
161 |
if (FD_ISSET (if_fd, &rfdset)) |
if (FD_ISSET (if_fd, &rfdset)) |
162 |
{ |
{ |
163 |
|
debug (5, "Read data from if_fd\n"); |
164 |
buffer_recv (&if_in, if_fd); |
buffer_recv (&if_in, if_fd); |
165 |
prot30_send_ip (); |
prot30_send_ip (); |
166 |
} |
} |
167 |
|
|
168 |
if (FD_ISSET (if_fd, &wfdset)) |
if (FD_ISSET (if_fd, &wfdset)) |
169 |
buffer_send (&if_out, if_fd); |
{ |
170 |
|
debug (5, "Send data to if_fd\n"); |
171 |
|
buffer_send (&if_out, if_fd); |
172 |
|
} |
173 |
} |
} |
174 |
else |
else |
175 |
{ |
{ |