author | viric@llimona |
Mon, 24 Sep 2007 13:59:40 +0200 | |
changeset 38 | f1e581c862d5 |
parent 36 | da427c23d755 |
child 40 | da3ea7f666e3 |
permissions | -rw-r--r-- |
23 | 1 |
#include <stdio.h> |
2 |
#include <stdlib.h> |
|
3 |
#include <sys/types.h> |
|
4 |
#include <sys/select.h> |
|
5 |
#include <unistd.h> |
|
6 |
#include <errno.h> |
|
7 |
#include <string.h> |
|
8 |
||
9 |
#include "main.h" |
|
10 |
#include "handlers.h" |
|
11 |
||
12 |
static void loop() |
|
13 |
{ |
|
14 |
fd_set read_set; |
|
15 |
int maxfd; |
|
16 |
int stdin_opened; |
|
17 |
int res; |
|
18 |
||
19 |
stdin_opened = 1; |
|
20 |
do |
|
21 |
{ |
|
22 |
FD_ZERO(&read_set); |
|
23 |
||
24 |
if (stdin_opened) |
|
25 |
FD_SET(0, &read_set); |
|
26 |
maxfd = 0; |
|
27 |
||
28 |
app_control_prepare_read_fdset(&read_set, &maxfd); |
|
33 | 29 |
if (command_line.s_param.serve_unix) |
30 |
s_unix_prepare_read_fdset(&read_set, &maxfd); |
|
31 |
if (command_line.s_param.serve_tcp) |
|
32 |
s_tcp_prepare_read_fdset(&read_set, &maxfd); |
|
23 | 33 |
|
34 |
/* Will block */ |
|
35 |
res = select(maxfd + 1, &read_set, 0, 0, 0); |
|
36 |
if (res == -1) |
|
37 |
{ |
|
38 |
if (errno == EINTR) |
|
39 |
continue; |
|
40 |
else |
|
41 |
error("Error in select()"); |
|
42 |
} |
|
43 |
||
44 |
res = app_control_process_read_fdset(&read_set); |
|
45 |
if (res == -1) /* app_stdout and app_stderr closed */ |
|
46 |
break; |
|
47 |
||
48 |
if (FD_ISSET(0, &read_set)) |
|
49 |
{ |
|
50 |
res = read(0, stream_buffer, stream_buffer_size); |
|
32
df110f784648
Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents:
29
diff
changeset
|
51 |
/* if res is 0, the fcall will close app_stdin */ |
df110f784648
Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents:
29
diff
changeset
|
52 |
app_control_local_send_to_stdin(stream_buffer, res); |
23 | 53 |
if (res == 0) |
54 |
stdin_opened = 0; |
|
55 |
} |
|
56 |
||
33 | 57 |
if (command_line.s_param.serve_unix) |
58 |
s_unix_process_read_fdset(&read_set); |
|
59 |
if (command_line.s_param.serve_tcp) |
|
60 |
s_tcp_process_read_fdset(&read_set); |
|
23 | 61 |
} while(1); |
62 |
} |
|
63 |
||
29
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
64 |
int server() |
23 | 65 |
{ |
66 |
int child; |
|
67 |
||
68 |
command_line.is_server = 1; |
|
69 |
||
36
da427c23d755
Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents:
33
diff
changeset
|
70 |
app_control_start(); |
da427c23d755
Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents:
33
diff
changeset
|
71 |
|
29
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
72 |
child = fork_app(command_line.s_param.command); |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
73 |
|
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
74 |
if (command_line.s_param.run_in_subterminal) |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
75 |
prepare_user_terminal(); |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
76 |
|
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
77 |
install_signal_forwarders(child); |
23 | 78 |
|
29
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
79 |
/* in raw mode, the signals for Control-C, ... will be generated by the |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
80 |
* slave pty. The master will receive the key codes. */ |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
81 |
if (command_line.s_param.serve_unix) |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
82 |
s_unix_update_served(command_line.s_param.max_served); |
23 | 83 |
|
29
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
84 |
if (command_line.s_param.serve_tcp) |
33 | 85 |
s_tcp_update_served(command_line.s_param.max_served); |
23 | 86 |
|
87 |
loop(); |
|
88 |
||
29
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
89 |
if (command_line.s_param.serve_unix) |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
90 |
s_unix_shutdown(); |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
91 |
|
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
92 |
if (command_line.s_param.serve_tcp) |
33 | 93 |
s_tcp_shutdown(); |
29
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
94 |
|
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
95 |
if (command_line.s_param.run_in_subterminal) |
91286c3ecebc
Added getopt, and some things got based on parameters.
viric@llimona
parents:
26
diff
changeset
|
96 |
restore_user_terminal(); |
23 | 97 |
|
98 |
return 0; |
|
99 |
} |