author | viric@mandarina |
Thu, 21 Aug 2008 23:21:22 +0200 | |
changeset 93 | 7d9b7a6da507 |
parent 87 | be4ee314545c |
permissions | -rw-r--r-- |
53 | 1 |
/* |
2 |
Terminal Mixer - multi-point multi-user access to terminal applications |
|
3 |
Copyright (C) 2007 LluĂs Batlle i Rossell |
|
4 |
||
5 |
Please find the license in the provided COPYING file. |
|
6 |
*/ |
|
43
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
7 |
#include <unistd.h> |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
8 |
#include <sys/types.h> |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
9 |
#include <sys/select.h> |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
10 |
#include "main.h" |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
11 |
#include "handlers.h" |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
12 |
|
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
13 |
static int myfd = -1; |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
14 |
|
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
15 |
void s_eth_init() |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
16 |
{ |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
17 |
eth_proto_init(); |
87
be4ee314545c
Making client and server use different ethernet protocols
viric@llimona
parents:
66
diff
changeset
|
18 |
myfd = eth_proto_open(ETH_SERVER); |
43
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
19 |
if (myfd < 0) |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
20 |
error("Cannot eth_proto_open"); |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
21 |
} |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
22 |
|
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
23 |
void s_eth_shutdown() |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
24 |
{ |
45 | 25 |
eth_proto_send(0, 0); |
43
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
26 |
if (myfd >= 0) |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
27 |
close(myfd); |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
28 |
} |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
29 |
|
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
30 |
void s_eth_prepare_read_fdset(fd_set *read_set, int *maxfd) |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
31 |
{ |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
32 |
FD_SET(myfd, read_set); |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
33 |
*maxfd = max(*maxfd, myfd); |
66
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
34 |
|
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
35 |
if (!eth_proto_allow_sending()) |
b2469563a1dc
Reliable ethernet protocol. I still need pselect instead of select.
viric@mandarina
parents:
60
diff
changeset
|
36 |
avoid_sending(read_set); |
43
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
37 |
} |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
38 |
|
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
39 |
void s_eth_process_read_fdset(fd_set *read_set) |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
40 |
{ |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
41 |
if (FD_ISSET(myfd, read_set)) |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
42 |
{ |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
43 |
int res; |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
44 |
|
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
45 |
res = eth_proto_recv(stream_buffer, stream_buffer_size); |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
46 |
|
60 | 47 |
if (res >= 0) |
48 |
app_control_remote_send_to_stdin(stream_buffer, res); |
|
43
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
49 |
} |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
50 |
} |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
51 |
|
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
52 |
void s_eth_send_to_connected(const char *buffer, size_t size) |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
53 |
{ |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
54 |
eth_proto_send(buffer, size); |
625794738afc
Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents:
diff
changeset
|
55 |
} |