ba1cfd20bba03651387e1bb1826baa0592ab2b46
2 * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 #include "recv.cmdline.h"
25 struct gengetopt_args_info conf
;
29 __printf_2_3
void para_log(int ll
, const char* fmt
,...)
33 /* ignore log message if loglevel is not high enough */
34 if (ll
< conf
.loglevel_arg
)
37 vfprintf(stderr
, fmt
, argp
);
41 static void *parse_config(int argc
, char *argv
[], int *receiver_num
)
45 if (cmdline_parser(argc
, argv
, &conf
))
47 if (conf
.list_receivers_given
) {
48 printf("available receivers: ");
49 for (i
= 0; receivers
[i
].name
; i
++)
50 printf("%s%s", i
? " " : "", receivers
[i
].name
);
51 printf("\nTry\n\tpara_recv -r '<receivername> -h'\n"
52 "for help on <receivername>.\n");
55 return check_receiver_arg(conf
.receiver_arg
, receiver_num
);
58 int main(int argc
, char *argv
[])
60 int ret
, eof
= 0, max
, r_opened
= 0, receiver_num
;
61 struct timeval timeout
;
62 struct receiver
*r
= NULL
;
64 struct receiver_node rn
;
66 memset(&rn
, 0, sizeof(struct receiver_node
));
67 for (ret
= 0; receivers
[ret
].name
; ret
++)
68 receivers
[ret
].init(&receivers
[ret
]);
70 rn
.conf
= parse_config(argc
, argv
, &receiver_num
);
72 PARA_EMERG_LOG("%s", "parse failed\n");
75 r
= &receivers
[receiver_num
];
85 timeout
.tv_usec
= 1000 * 1000;
87 ret
= r
->pre_select(&rn
, &rfds
, &wfds
, &timeout
);
90 PARA_DEBUG_LOG("timeout: %lums\n", tv2ms(&timeout
));
91 ret
= para_select(max
+ 1, &rfds
, &wfds
, &timeout
);
96 ret
= r
->post_select(&rn
, ret
, &rfds
, &wfds
);
106 ret
= write(STDOUT_FILENO
, rn
.buf
, rn
.loaded
);
107 PARA_DEBUG_LOG("wrote %d/%zd\n", ret
, rn
.loaded
);
109 ret
= -E_WRITE_STDOUT
;
112 if (ret
!= rn
.loaded
) {
113 PARA_INFO_LOG("short write %d/%zd\n", ret
, rn
.loaded
);
114 memmove(rn
.buf
, rn
.buf
+ ret
, rn
.loaded
- ret
);
117 if (rn
.loaded
|| !eof
)
125 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret
));