Projects
Multimedia
dvswitch-git
retry_connect_option.diff
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File retry_connect_option.diff of Package dvswitch-git
--- doc/dvsink-command.1 | 5 ++++ doc/dvsink-files.1 | 5 ++++ doc/dvsource-alsa.1 | 5 ++++ doc/dvsource-dvgrab.1 | 5 ++++ doc/dvsource-file.1 | 5 ++++ doc/dvswitch.1 | 5 ++++ src/dvsink-command.c | 20 ++++++++++++++++--- src/dvsink-files.c | 46 ++++++++++++++++++++++++++++++-------------- src/dvsource-alsa.c | 19 +++++++++++++++--- src/dvsource-dvgrab.c | 22 +++++++++++++++++---- src/dvsource-file.c | 52 ++++++++++++++++++++++++++++++++++++-------------- src/dvsource-jack.c | 2 - src/socket.c | 18 +++++++++++++++-- src/socket.h | 2 - 14 files changed, 169 insertions(+), 42 deletions(-) Index: dvswitch-0.9-1-da15ba4/doc/dvsink-command.1 =================================================================== --- dvswitch-0.9-1-da15ba4.orig/doc/dvsink-command.1 +++ dvswitch-0.9-1-da15ba4/doc/dvsink-command.1 @@ -16,9 +16,14 @@ appear as its standard input. \fB\-p\fR, \fB\-\-port=\fIPORT\fR .RS Specify the network address on which DVswitch is listening. The host address may be specified by name or as an IPv4 or IPv6 literal. .RE +.TP +\fB\-R\fR, \fB\-\-retry\fR +.RS +Keep retrying to connect, in case DVswitch is not yet listening. +.RE .SH AUTHOR Ben Hutchings <ben@decadent.org.uk>. .SH SEE ALSO /usr/share/doc/dvswitch/README Index: dvswitch-0.9-1-da15ba4/doc/dvsink-files.1 =================================================================== --- dvswitch-0.9-1-da15ba4.orig/doc/dvsink-files.1 +++ dvswitch-0.9-1-da15ba4/doc/dvsink-files.1 @@ -21,9 +21,14 @@ added before the ".dv" if necessary to a \fB\-p\fR, \fB\-\-port=\fIPORT\fR .RS Specify the network address on which DVswitch is listening. The host address may be specified by name or as an IPv4 or IPv6 literal. .RE +.TP +\fB\-R\fR, \fB\-\-retry\fR +.RS +Keep retrying to connect, in case DVswitch is not yet listening. +.RE .SH AUTHOR Ben Hutchings <ben@decadent.org.uk>. .SH SEE ALSO strftime(3), /usr/share/doc/dvswitch/README Index: dvswitch-0.9-1-da15ba4/doc/dvsource-alsa.1 =================================================================== --- dvswitch-0.9-1-da15ba4.orig/doc/dvsource-alsa.1 +++ dvswitch-0.9-1-da15ba4/doc/dvsource-alsa.1 @@ -25,10 +25,15 @@ for an explanation of these names. .RS Specify the network address on which DVswitch is listening. The host address may be specified by name or as an IPv4 or IPv6 literal. .RE .TP +\fB\-R\fR, \fB\-\-retry\fR +.RS +Keep retrying to connect, in case DVswitch is not yet listening. +.RE +.TP \fB\-s\fR, \fB\-\-system=\fRntsc|pal .RS Specify the video system to use. This must match the system used by DVswitch. The default is "pal". .RE Index: dvswitch-0.9-1-da15ba4/doc/dvsource-dvgrab.1 =================================================================== --- dvswitch-0.9-1-da15ba4.orig/doc/dvsource-dvgrab.1 +++ dvswitch-0.9-1-da15ba4/doc/dvsource-dvgrab.1 @@ -50,10 +50,15 @@ Print more information at startup. .RS Specify the network address on which DVswitch is listening. The host address may be specified by name or as an IPv4 or IPv6 literal. .RE .TP +\fB\-R\fR, \fB\-\-retry\fR +.RS +Keep retrying to connect, in case DVswitch is not yet listening. +.RE +.TP \fB\-c\fR, \fB\-\-card=\fICARD-NUMBER\fR .RS Specify the index of the Firewire card the DV device is connected to. .RE .TP Index: dvswitch-0.9-1-da15ba4/doc/dvsource-file.1 =================================================================== --- dvswitch-0.9-1-da15ba4.orig/doc/dvsource-file.1 +++ dvswitch-0.9-1-da15ba4/doc/dvsource-file.1 @@ -20,10 +20,15 @@ purposes. .RS Specify the network address on which DVswitch is listening. The host address may be specified by name or as an IPv4 or IPv6 literal. .RE .TP +\fB\-R\fR, \fB\-\-retry\fR +.RS +Keep retrying to connect, in case DVswitch is not yet listening. +.RE +.TP .BR \-l , " \-\-loop" .RS Play the file repeatedly in a loop. .RE .TP Index: dvswitch-0.9-1-da15ba4/doc/dvswitch.1 =================================================================== --- dvswitch-0.9-1-da15ba4.orig/doc/dvswitch.1 +++ dvswitch-0.9-1-da15ba4/doc/dvswitch.1 @@ -29,9 +29,14 @@ or as an IPv4 or IPv6 literal. This option activates the remote-control mode. If set, dvswitch will listen for OSC messages on the given port. OSC messages understood by dvcontrol are documented in the \fBREADME\fR file. .RE +.TP +\fB\-R\fR, \fB\-\-retry\fR +.RS +Keep retrying to connect, in case DVswitch is not yet listening. +.RE .SH AUTHOR Ben Hutchings <ben@decadent.org.uk>. .SH SEE ALSO gtk-options(7), /usr/share/doc/dvswitch/README Index: dvswitch-0.9-1-da15ba4/src/dvsink-command.c =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dvsink-command.c +++ dvswitch-0.9-1-da15ba4/src/dvsink-command.c @@ -2,10 +2,11 @@ // See the file "COPYING" for licence details. // Sink that runs an arbitrary command #include <assert.h> +#include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -18,15 +19,17 @@ static struct option options[] = { {"host", 1, NULL, 'h'}, {"port", 1, NULL, 'p'}, {"help", 0, NULL, 'H'}, + {"retry", 0, NULL, 'R'}, {NULL, 0, NULL, 0} }; static char * mixer_host = NULL; static char * mixer_port = NULL; +static bool retry_connect = false; static void handle_config(const char * name, const char * value) { if (strcmp(name, "MIXER_HOST") == 0) { @@ -36,17 +39,25 @@ static void handle_config(const char * n else if (strcmp(name, "MIXER_PORT") == 0) { free(mixer_port); mixer_port = strdup(value); } + else if (strcmp(name, "RETRY_CONNECT") == 0) + { + if (!strcasecmp(value, "yes") || !strcmp(value, "1") || + !strcasecmp(value, "true") || !strcasecmp(value, "on")) + retry_connect = true; + else + retry_connect = false; + } } static void usage(const char * progname) { fprintf(stderr, "\ -Usage: %s [-h HOST] [-p PORT] COMMAND...\n", +Usage: %s [-r] [-h HOST] [-p PORT] COMMAND...\n", progname); } int main(int argc, char ** argv) { @@ -54,11 +65,11 @@ int main(int argc, char ** argv) dvswitch_read_config(handle_config); // Parse arguments. int opt; - while ((opt = getopt_long(argc, argv, "h:p:", options, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "h:p:R", options, NULL)) != -1) { switch (opt) { case 'h': free(mixer_host); @@ -69,10 +80,13 @@ int main(int argc, char ** argv) mixer_port = strdup(optarg); break; case 'H': // --help usage(argv[0]); return 0; + case 'R': + retry_connect = true; + break; default: usage(argv[0]); return 2; } } @@ -92,11 +106,11 @@ int main(int argc, char ** argv) } // Connect to the mixer, set that as stdin, and run given command. printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port); - int sock = create_connected_socket(mixer_host, mixer_port); + int sock = create_connected_socket(mixer_host, mixer_port, retry_connect); assert(sock >= 0); // create_connected_socket() should handle errors if (write(sock, GREETING_RAW_SINK, GREETING_SIZE) != GREETING_SIZE) { perror("ERROR: write"); exit(1); Index: dvswitch-0.9-1-da15ba4/src/dvsink-files.c =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dvsink-files.c +++ dvswitch-0.9-1-da15ba4/src/dvsink-files.c @@ -3,10 +3,11 @@ // See the file "COPYING" for licence details. // Sink that creates DIF ("raw DV") files #include <assert.h> +#include <stdbool.h> #include <errno.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -25,16 +26,18 @@ static struct option options[] = { {"host", 1, NULL, 'h'}, {"port", 1, NULL, 'p'}, {"help", 0, NULL, 'H'}, + {"retry", 0, NULL, 'R'}, {NULL, 0, NULL, 0} }; static char * mixer_host = NULL; static char * mixer_port = NULL; static char * output_name_format = NULL; +static bool retry_connect = false; static void handle_config(const char * name, const char * value) { if (strcmp(name, "MIXER_HOST") == 0) { @@ -49,17 +52,25 @@ static void handle_config(const char * n else if (strcmp(name, "OUTPUT_NAME_FORMAT") == 0) { free(output_name_format); output_name_format = strdup(value); } + else if (strcmp(name, "RETRY_CONNECT") == 0) + { + if (!strcasecmp(value, "yes") || !strcmp(value, "1") || + !strcasecmp(value, "true") || !strcasecmp(value, "on")) + retry_connect = true; + else + retry_connect = false; + } } static void usage(const char * progname) { fprintf(stderr, "\ -Usage: %s [-h HOST] [-p PORT] [NAME-FORMAT]\n", +Usage: %s [-R] [-h HOST] [-p PORT] [NAME-FORMAT]\n", progname); } struct transfer_params { int sock; @@ -160,11 +171,11 @@ static ssize_t write_retry(int fd, const while (count); return total; } -static void transfer_frames(struct transfer_params * params) +static void transfer_frames(struct transfer_params * params, int retry_connect) { static uint8_t buf[SINK_FRAME_HEADER_SIZE + DIF_MAX_FRAME_SIZE]; const struct dv_system * system; int file = -1; @@ -236,19 +247,19 @@ static void transfer_frames(struct trans if (write_retry(file, buf + SINK_FRAME_HEADER_SIZE, system->size) != (ssize_t)system->size) { perror("ERROR: write"); - exit(1); + if (!retry_connect) exit(1); } } read_failed: if (read_size != 0) { perror("ERROR: read"); - exit(1); + if (!retry_connect) exit(1); } if (file >= 0) close(file); } @@ -259,11 +270,11 @@ int main(int argc, char ** argv) dvswitch_read_config(handle_config); // Parse arguments. int opt; - while ((opt = getopt_long(argc, argv, "h:p:", options, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "h:p:R", options, NULL)) != -1) { switch (opt) { case 'h': free(mixer_host); @@ -274,10 +285,13 @@ int main(int argc, char ** argv) mixer_port = strdup(optarg); break; case 'H': // --help usage(argv[0]); return 0; + case 'R': + retry_connect = true; + break; default: usage(argv[0]); return 2; } } @@ -308,20 +322,24 @@ int main(int argc, char ** argv) } struct transfer_params params; printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port); fflush(stdout); - params.sock = create_connected_socket(mixer_host, mixer_port); - assert(params.sock >= 0); // create_connected_socket() should handle errors - if (write(params.sock, GREETING_REC_SINK, GREETING_SIZE) != GREETING_SIZE) + do { - perror("ERROR: write"); - exit(1); - } - printf("INFO: Connected.\n"); + params.sock = create_connected_socket(mixer_host, mixer_port, retry_connect); + assert(params.sock >= 0); // create_connected_socket() should handle errors + if (write(params.sock, GREETING_REC_SINK, GREETING_SIZE) != GREETING_SIZE) + { + perror("ERROR: write GREETING_REC_SINK"); + exit(1); + } + printf("INFO: Connected.\n"); - transfer_frames(¶ms); + transfer_frames(¶ms, retry_connect); - close(params.sock); + close(params.sock); + printf("INFO: Disconnected.\n"); + } while (retry_connect); return 0; } Index: dvswitch-0.9-1-da15ba4/src/dvsource-alsa.c =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dvsource-alsa.c +++ dvswitch-0.9-1-da15ba4/src/dvsource-alsa.c @@ -29,15 +29,17 @@ static struct option options[] = { {"port", 1, NULL, 'p'}, {"system", 1, NULL, 's'}, {"rate", 1, NULL, 'r'}, {"delay", 1, NULL, 'd'}, {"help", 0, NULL, 'H'}, + {"retry", 0, NULL, 'R'}, {NULL, 0, NULL, 0} }; static char * mixer_host = NULL; static char * mixer_port = NULL; +static bool retry_connect = false; static void handle_config(const char * name, const char * value) { if (strcmp(name, "MIXER_HOST") == 0) { @@ -47,17 +49,25 @@ static void handle_config(const char * n else if (strcmp(name, "MIXER_PORT") == 0) { free(mixer_port); mixer_port = strdup(value); } + else if (strcmp(name, "RETRY_CONNECT") == 0) + { + if (!strcasecmp(value, "yes") || !strcmp(value, "1") || + !strcasecmp(value, "true") || !strcasecmp(value, "on")) + retry_connect = true; + else + retry_connect = false; + } } static void usage(const char * progname) { fprintf(stderr, "\ -Usage: %s [-h HOST] [-p PORT] [-s ntsc|pal] \\\n\ +Usage: %s [-R] [-h HOST] [-p PORT] [-s ntsc|pal] \\\n\ [-r 48000|32000|44100] [-d DELAY] [DEVICE]\n", progname); } struct transfer_params { @@ -140,11 +150,11 @@ int main(int argc, char ** argv) double delay = 0.2; /* Parse arguments. */ int opt; - while ((opt = getopt_long(argc, argv, "h:p:s:r:d:", options, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "h:p:s:r:d:R", options, NULL)) != -1) { switch (opt) { case 'h': free(mixer_host); @@ -165,10 +175,13 @@ int main(int argc, char ** argv) delay = strtod(optarg, NULL); break; case 'H': /* --help */ usage(argv[0]); return 0; + case 'R': + retry_connect = true; + break; default: usage(argv[0]); return 2; } } @@ -277,11 +290,11 @@ int main(int argc, char ** argv) fprintf(stderr, "ERROR: snd_pcm_hw_params: %s\n", snd_strerror(rc)); return 1; } printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port); - params.sock = create_connected_socket(mixer_host, mixer_port); + params.sock = create_connected_socket(mixer_host, mixer_port, retry_connect); assert(params.sock >= 0); /* create_connected_socket() should handle errors */ if (write(params.sock, GREETING_SOURCE, GREETING_SIZE) != GREETING_SIZE) { perror("ERROR: write"); exit(1); Index: dvswitch-0.9-1-da15ba4/src/dvsource-dvgrab.c =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dvsource-dvgrab.c +++ dvswitch-0.9-1-da15ba4/src/dvsource-dvgrab.c @@ -4,10 +4,11 @@ * See the file "COPYING" for licence details. */ /* Source that reads DIF over USB or Firewire using dvgrab */ #include <assert.h> +#include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -18,14 +19,15 @@ #include "protocol.h" #include "socket.h" static struct option options[] = { {"card", 1, NULL, 'c'}, - {"guid", 1, NULL, 'g'}, + {"guid", 1, NULL, 'g'}, {"firewire", 0, NULL, 'F'}, {"v4l2", 0, NULL, 'V'}, {"command", 0, NULL, 'C'}, + {"retry", 0, NULL, 'R'}, {"host", 1, NULL, 'h'}, {"port", 1, NULL, 'p'}, {"tally", 0, NULL, 't'}, {"verbose", 0, NULL, 'v'}, {"help", 0, NULL, 'H'}, @@ -44,10 +46,11 @@ static char * device_name = NULL; static char * firewire_card = NULL; static char * firewire_guid = NULL; static char * mixer_host = NULL; static char * mixer_port = NULL; static int do_tally = 0; +static bool retry_connect = false; static int verbose = 0; static enum mode program_mode(const char * progname) { const char * slash = strrchr(progname, '/'); @@ -89,20 +92,28 @@ static void handle_config(const char * n else if (strcmp(name, "MIXER_PORT") == 0) { free(mixer_port); mixer_port = strdup(value); } + else if (strcmp(name, "RETRY_CONNECT") == 0) + { + if (!strcasecmp(value, "yes") || !strcmp(value, "1") || + !strcasecmp(value, "true") || !strcasecmp(value, "on")) + retry_connect = true; + else + retry_connect = false; + } } static void usage(const char * progname) { static const char firewire_args[] = "[-c CARD-NUMBER | DEVICE] [-g GUID]"; static const char v4l2_args[] = "[DEVICE]"; static const char cmd_args[] = "['ffmpeg -v quiet -f alsa -ac 1 -i hw:1 -f v4l2 -i /dev/video0 -target pal-dv pipe:1']"; static const char other_args[] = - "[-t] [-v] [-h HOST] [-p PORT]"; + "[--tally|-t] [-v] [--retry|-R] [-h HOST] [-p PORT]"; switch (program_mode(progname)) { case mode_unknown: fprintf(stderr, @@ -191,11 +202,11 @@ int main(int argc, char ** argv) dvswitch_read_config(handle_config); /* Parse arguments. */ int opt; - while ((opt = getopt_long(argc, argv, "c:g:h:p:tvFVC", options, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "c:g:h:p:tvFVCR", options, NULL)) != -1) { switch (opt) { case 'c': free(firewire_card); @@ -212,10 +223,13 @@ int main(int argc, char ** argv) mode = mode_v4l2; break; case 'C': mode = mode_command; break; + case 'R': + retry_connect = true; + break; case 'h': free(mixer_host); mixer_host = strdup(optarg); break; case 'p': @@ -287,11 +301,11 @@ int main(int argc, char ** argv) } /* Connect to the mixer. */ printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port); - int sock = create_connected_socket(mixer_host, mixer_port); + int sock = create_connected_socket(mixer_host, mixer_port, retry_connect); assert(sock >= 0); /* create_connected_socket() should handle errors */ if (write(sock, do_tally ? GREETING_ACT_SOURCE : GREETING_SOURCE, GREETING_SIZE) != GREETING_SIZE) { perror("ERROR: write"); Index: dvswitch-0.9-1-da15ba4/src/socket.c =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/socket.c +++ dvswitch-0.9-1-da15ba4/src/socket.c @@ -4,16 +4,19 @@ /* Socket utility functions */ #include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <unistd.h> // sleep() #include <netdb.h> #include <sys/socket.h> #include <sys/types.h> -int create_connected_socket(const char * host, const char * port) +#include "socket.h" + +int create_connected_socket(const char * host, const char * port, int do_retry) { struct addrinfo addr_hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM, .ai_flags = AI_ADDRCONFIG @@ -31,15 +34,26 @@ int create_connected_socket(const char * if (sock < 0) { perror("ERROR: socket"); exit(1); } - if (connect(sock, addr->ai_addr, addr->ai_addrlen) != 0) + + int dots = 0; + while (connect(sock, addr->ai_addr, addr->ai_addrlen) != 0) { + if (do_retry) + { + dots = 1; + fprintf(stderr, "."); + sleep(2); + continue; + } perror("ERROR: connect"); exit(1); } + if (dots) + fprintf(stderr, "\n"); freeaddrinfo(addr); return sock; } Index: dvswitch-0.9-1-da15ba4/src/socket.h =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/socket.h +++ dvswitch-0.9-1-da15ba4/src/socket.h @@ -8,11 +8,11 @@ #ifdef __cplusplus extern "C" { #endif -int create_connected_socket(const char * host, const char * port); +int create_connected_socket(const char * host, const char * port, int do_retry); int create_listening_socket(const char * host, const char * port); #ifdef __cplusplus } #endif Index: dvswitch-0.9-1-da15ba4/src/dvsource-jack.c =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dvsource-jack.c +++ dvswitch-0.9-1-da15ba4/src/dvsource-jack.c @@ -431,11 +431,11 @@ int main(int argc, char ** argv) params.rb = jack_ringbuffer_create(rbsize); memset(params.rb->buf, 0, rbsize); printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port); - params.sock = create_connected_socket(mixer_host, mixer_port); + params.sock = create_connected_socket(mixer_host, mixer_port, 0); assert(params.sock >= 0); /* create_connected_socket() should handle errors */ if (write(params.sock, GREETING_SOURCE, GREETING_SIZE) != GREETING_SIZE) { close_jack(¶ms); perror("ERROR: write"); Index: dvswitch-0.9-1-da15ba4/src/dvsource-file.c =================================================================== --- dvswitch-0.9-1-da15ba4.orig/src/dvsource-file.c +++ dvswitch-0.9-1-da15ba4/src/dvsource-file.c @@ -15,10 +15,11 @@ #include <getopt.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <netinet/in.h> +#include <signal.h> #include "config.h" #include "dif.h" #include "frame_timer.h" #include "protocol.h" @@ -28,15 +29,17 @@ static struct option options[] = { {"host", 1, NULL, 'h'}, {"port", 1, NULL, 'p'}, {"loop", 0, NULL, 'l'}, {"help", 0, NULL, 'H'}, {"timings",0, NULL, 't'}, + {"retry", 0, NULL, 'R'}, {NULL, 0, NULL, 0} }; static char * mixer_host = NULL; static char * mixer_port = NULL; +static bool retry_connect = false; static void handle_config(const char * name, const char * value) { if (strcmp(name, "MIXER_HOST") == 0) { @@ -46,10 +49,18 @@ static void handle_config(const char * n else if (strcmp(name, "MIXER_PORT") == 0) { free(mixer_port); mixer_port = strdup(value); } + else if (strcmp(name, "RETRY_CONNECT") == 0) + { + if (!strcasecmp(value, "yes") || !strcmp(value, "1") || + !strcasecmp(value, "true") || !strcasecmp(value, "on")) + retry_connect = true; + else + retry_connect = false; + } } static unsigned int get_file_size_bytes(int fd) { struct stat filestat; @@ -63,11 +74,11 @@ static unsigned int get_file_size_bytes( static void usage(const char * progname) { fprintf(stderr, "\ -Usage: %s [-h HOST] [-p PORT] [-l] [-t] FILE\n", +Usage: %s [-R] [-h HOST] [-p PORT] [--loop] [-t] FILE\n", progname); } struct transfer_params { int file; @@ -96,11 +107,11 @@ static ssize_t read_retry(int fd, void * while (count); return total; } -static void transfer_frames(struct transfer_params * params) +static void transfer_frames(struct transfer_params * params, int retry_connect) { const struct dv_system * last_system = 0, * system; static uint8_t buf[DIF_MAX_FRAME_SIZE]; uint64_t frame_timestamp = 0; unsigned int frame_interval = 0; @@ -137,18 +148,20 @@ static void transfer_frames(struct trans num_frames = 0; video_length_sec = 0; continue; } perror("ERROR: lseek"); + if (retry_connect) return; exit(1); } if (size != (ssize_t)DIF_SEQUENCE_SIZE) { if (size < 0) perror("ERROR: read"); else fputs("ERROR: Failed to read complete frame\n", stderr); + if (retry_connect) return; exit(1); } system = dv_buffer_system(buf); @@ -167,16 +180,18 @@ static void transfer_frames(struct trans { if (size < 0) perror("ERROR: read"); else fputs("ERROR: Failed to read complete frame\n", stderr); + if (retry_connect) return; exit(1); } frame_number++; if (write(params->sock, buf, system->size) != (ssize_t)system->size) { perror("ERROR: write"); + if (retry_connect) return; exit(1); } frame_timestamp += frame_interval; @@ -235,11 +250,11 @@ int main(int argc, char ** argv) params.timings = false; /* Parse arguments. */ int opt; - while ((opt = getopt_long(argc, argv, "h:p:lt", options, NULL)) != -1) + while ((opt = getopt_long(argc, argv, "h:p:ltR", options, NULL)) != -1) { switch (opt) { case 'h': free(mixer_host); @@ -256,10 +271,13 @@ int main(int argc, char ** argv) usage(argv[0]); return 0; case 't': params.timings = true; break; + case 'R': + retry_connect = true; + break; default: usage(argv[0]); return 2; } } @@ -285,10 +303,12 @@ int main(int argc, char ** argv) } usage(argv[0]); return 2; } + signal(SIGPIPE, SIG_IGN); // make Broken pipe visible in perror write. + const char * filename = argv[optind]; /* Prepare to read the file and connect a socket to the mixer. */ if (strcmp(filename, "-")) { @@ -308,21 +328,25 @@ int main(int argc, char ** argv) if (!is_dv_file(params.file)) { fprintf(stderr, "ERROR: %s is not a DV file\n", filename); return 1; } printf("INFO: Connecting to %s:%s\n", mixer_host, mixer_port); - params.sock = create_connected_socket(mixer_host, mixer_port); - assert(params.sock >= 0); /* create_connected_socket() should handle errors */ - if (write(params.sock, GREETING_SOURCE, GREETING_SIZE) != GREETING_SIZE) + do { - perror("ERROR: write"); - exit(1); - } - printf("INFO: Connected.\n"); - - transfer_frames(¶ms); + params.sock = create_connected_socket(mixer_host, mixer_port, retry_connect); + assert(params.sock >= 0); /* create_connected_socket() should handle errors */ + if (write(params.sock, GREETING_SOURCE, GREETING_SIZE) != GREETING_SIZE) + { + perror("ERROR: write"); + exit(1); + } + printf("INFO: Connected.\n"); - close(params.sock); - close(params.file); + transfer_frames(¶ms, retry_connect); + close(params.sock); + close(params.file); + printf("INFO: Disonnected.\n"); + } while (retry_connect); + return 0; }
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.