[Redbutton-devel] SF.net SVN: redbutton: [173] redbutton-download/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-01-11 16:34:55
|
Revision: 173
http://svn.sourceforge.net/redbutton/?rev=173&view=rev
Author: skilvington
Date: 2007-01-11 08:34:52 -0800 (Thu, 11 Jan 2007)
Log Message:
-----------
always listen for remote rb-browsers, also some reordering to make retuning possible
Modified Paths:
--------------
redbutton-download/trunk/listen.c
redbutton-download/trunk/listen.h
redbutton-download/trunk/rb-download.c
Modified: redbutton-download/trunk/listen.c
===================================================================
--- redbutton-download/trunk/listen.c 2007-01-11 11:10:32 UTC (rev 172)
+++ redbutton-download/trunk/listen.c 2007-01-11 16:34:52 UTC (rev 173)
@@ -17,6 +17,8 @@
#include <sys/wait.h>
#include "command.h"
+#include "findmheg.h"
+#include "carousel.h"
#include "utils.h"
/* listen() backlog, 5 is max for BSD apparently */
@@ -107,23 +109,18 @@
*/
void
-start_listener(struct listen_data *listen_data)
+start_listener(struct sockaddr_in *listen_addr, unsigned int adapter, unsigned int timeout, uint16_t service_id, int carousel_id)
{
+ struct listen_data listen_data;
struct sigaction action;
- pid_t child;
int sockopt;
int listen_sock;
int accept_sock;
fd_set read_fds;
socklen_t addr_len;
struct sockaddr_in client_addr;
+ pid_t child;
- /*
- * fork:
- * the parent listens for commands,
- * the child returns and downloads the carousel
- */
-
/* don't let our children become zombies */
action.sa_handler = dead_child;
sigemptyset(&action.sa_mask);
@@ -131,16 +128,11 @@
if(sigaction(SIGCHLD, &action, NULL) < 0)
fatal("signal: SIGCHLD: %s", strerror(errno));
- /* if we can't fork it's probably best to kill ourselves*/
- if((child = fork()) < 0)
- fatal("fork: %s", strerror(errno));
- /* child returns */
- else if(child == 0)
- return;
- /* parent continues */
+ /* fork off a child to download the carousel */
+ listen_data.carousel = start_downloader(adapter, timeout, service_id, carousel_id);
/* listen on the given ip:port */
- verbose("Listening on %s:%u", inet_ntoa(listen_data->addr.sin_addr), ntohs(listen_data->addr.sin_port));
+ verbose("Listening on %s:%u", inet_ntoa(listen_addr->sin_addr), ntohs(listen_addr->sin_port));
if((listen_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
fatal("socket: %s", strerror(errno));
@@ -150,7 +142,7 @@
if(setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &sockopt, sizeof(sockopt)) < 0)
fatal("setsockopt: SO_REUSEADDR: %s", strerror(errno));
- if(bind(listen_sock, (struct sockaddr *) &listen_data->addr, sizeof(struct sockaddr_in)) < 0)
+ if(bind(listen_sock, (struct sockaddr *) listen_addr, sizeof(struct sockaddr_in)) < 0)
fatal("bind: %s", strerror(errno));
if(listen(listen_sock, BACKLOG) < 0)
@@ -188,7 +180,7 @@
{
/* child */
close(listen_sock);
- handle_connection(listen_data, accept_sock, &client_addr);
+ handle_connection(&listen_data, accept_sock, &client_addr);
close(accept_sock);
/* use _exit in child so stdio etc don't clean up twice */
_exit(EXIT_SUCCESS);
@@ -250,6 +242,37 @@
return;
}
+struct carousel *
+start_downloader(unsigned int adapter, unsigned int timeout, uint16_t service_id, int carousel_id)
+{
+ struct carousel *car;
+ pid_t child;
+
+ /* find the MHEG PIDs */
+ car = find_mheg(adapter, timeout, service_id, carousel_id);
+
+ verbose("Carousel ID=%u", car->carousel_id);
+ verbose("Boot PID=%u", car->boot_pid);
+ verbose("Video PID=%u", car->video_pid);
+ verbose("Audio PID=%u", car->audio_pid);
+
+ /*
+ * fork:
+ * the parent listens for commands,
+ * the child downloads the carousel
+ */
+
+ /* if we can't fork it's probably best to kill ourselves*/
+ if((child = fork()) < 0)
+ fatal("fork: %s", strerror(errno));
+ /* child downloads the carousel until killed by parent */
+ else if(child == 0)
+ load_carousel(car);
+ /* parent continues */
+
+ return car;
+}
+
static void
dead_child(int signo)
{
Modified: redbutton-download/trunk/listen.h
===================================================================
--- redbutton-download/trunk/listen.h 2007-01-11 11:10:32 UTC (rev 172)
+++ redbutton-download/trunk/listen.h 2007-01-11 16:34:52 UTC (rev 173)
@@ -11,12 +11,12 @@
struct listen_data
{
- struct sockaddr_in addr; /* ip:port to listen on */
struct carousel *carousel; /* carousel we are downloading */
};
int parse_addr(char *, struct in_addr *, in_port_t *);
-void start_listener(struct listen_data *);
+void start_listener(struct sockaddr_in *, unsigned int, unsigned int, uint16_t, int);
+struct carousel *start_downloader(unsigned int, unsigned int, uint16_t, int);
#endif
Modified: redbutton-download/trunk/rb-download.c
===================================================================
--- redbutton-download/trunk/rb-download.c 2007-01-11 11:10:32 UTC (rev 172)
+++ redbutton-download/trunk/rb-download.c 2007-01-11 16:34:52 UTC (rev 173)
@@ -1,5 +1,5 @@
/*
- * rb-download [-v] [-a <adapter>] [-b <base_dir>] [-t <timeout>] [-l[<listen-addr>]] [-c <carousel_id>] [<service_id>]
+ * rb-download [-v] [-a <adapter>] [-b <base_dir>] [-t <timeout>] [-l <listen_addr>] [-c <carousel_id>] [<service_id>]
*
* Download the DVB Object Carousel for the given channel onto the local hard disc
* files will be stored under the current dir if no -b option is given
@@ -15,13 +15,12 @@
* /dev/dvb/adapter0/dvr0
* use the -a option to change the adapter number (eg "-a 1" will use /dev/dvb/adapter1/demux0 etc)
*
- * if -l is given, rb-download listens on the network for commands from a remote rb-browser
+ * rb-download listens on the network for commands from a remote rb-browser
* the default IP to listen on is 0.0.0.0 (ie all interfaces), the default TCP port is 10101
- * listen-addr should be given in the form "host:port", where host defaults to 0.0.0.0 and port defaults to 10101
- * eg, to listen on a different port, do "-l8080"
- * to only listen on the loop back, do "-l127.0.0.1" or on a different port too, do "-l127.0.0.1:8080"
- * NOTE: because -l may or may not take an argument, you must not put a space between the -l and the value
- * (otherwise, "rb-download -l 1234", is ambiguous - listen on port 1234 or use service_id 1234?)
+ * the -l option changes the default IP and port
+ * listen_addr should be given in the form "host:port", where host defaults to 0.0.0.0 and port defaults to 10101
+ * eg, to listen on a different port, do "-l 8080"
+ * to only listen on the loop back, do "-l 127.0.0.1" or on a different port too, do "-l 127.0.0.1:8080"
*
* -v is verbose/debug mode, use more v's for more verbosity
*
@@ -35,7 +34,7 @@
*/
/*
- * Copyright (C) 2005, 2006, Simon Kilvington
+ * Copyright (C) 2005, 2006, 2007, Simon Kilvington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -82,16 +81,21 @@
main(int argc, char *argv[])
{
char *prog_name = argv[0];
- unsigned int adapter = 0;
- unsigned int timeout = DEFAULT_TIMEOUT;
- bool listen = false;
- struct listen_data listen_data;
- int carousel_id = -1;
+ unsigned int adapter;
+ unsigned int timeout;
+ struct sockaddr_in listen_addr;
+ int carousel_id;
uint16_t service_id;
- struct carousel *car;
int arg;
- while((arg = getopt(argc, argv, "a:b:t:l::c:v")) != EOF)
+ /* default values */
+ adapter = 0;
+ timeout = DEFAULT_TIMEOUT;
+ listen_addr.sin_addr.s_addr = htonl(DEFAULT_LISTEN_ADDR);
+ listen_addr.sin_port = htons(DEFAULT_LISTEN_PORT);
+ carousel_id = -1; /* read it from the PMT */
+
+ while((arg = getopt(argc, argv, "a:b:t:l:c:v")) != EOF)
{
switch(arg)
{
@@ -109,12 +113,7 @@
break;
case 'l':
- listen = true;
- /* default values */
- listen_data.addr.sin_addr.s_addr = htonl(DEFAULT_LISTEN_ADDR);
- listen_data.addr.sin_port = htons(DEFAULT_LISTEN_PORT);
- /* optarg is NULL if no value is given, parse_addr can't fail with NULL */
- if(parse_addr(optarg, &listen_data.addr.sin_addr, &listen_data.addr.sin_port) < 0)
+ if(parse_addr(optarg, &listen_addr.sin_addr, &listen_addr.sin_port) < 0)
fatal("Unable to resolve host %s", optarg);
break;
@@ -139,17 +138,7 @@
else if(argc - optind == 1)
{
service_id = strtoul(argv[optind], NULL, 0);
- car = find_mheg(adapter, timeout, service_id, carousel_id);
- verbose("Carousel ID=%u", car->carousel_id);
- verbose("Boot PID=%u", car->boot_pid);
- verbose("Video PID=%u", car->video_pid);
- verbose("Audio PID=%u", car->audio_pid);
- if(listen)
- {
- listen_data.carousel = car;
- start_listener(&listen_data);
- }
- load_carousel(car);
+ start_listener(&listen_addr, adapter, timeout, service_id, carousel_id);
}
else
{
@@ -207,7 +196,7 @@
"[-a <adapter>] "
"[-b <base_dir>] "
"[-t <timeout>] "
- "[-l[<listen-addr>]] "
+ "[-l <listen_addr>] "
"[-c carousel_id] "
"[<service_id>]", prog_name);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|