[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#82713: marked as done ([patch] fix for listen's busy-wait behaviour, and some other dumb stuff)



Your message dated Wed, 22 Mar 2006 15:16:14 +0100
with message-id <877j6mo98x.fsf@diziet.irb.hr>
and subject line Removed
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
package: icecast-client
version: 1.4.0

Here's a patch I wrote that fixes some dumb stuff in listen.c.  I haven't
tested it very much, but it can connect to servers and download stuff.  The
udp stuff is not really tested at all (other than printing that the
connection was refused.)

--- old-listen.c	Wed Jan 17 21:10:43 2001
+++ listen.c	Wed Jan 17 23:24:57 2001
@@ -3,12 +3,16 @@
    Compile with: gcc -O<lots> -o listen listen.c
    Run with: listen <host> <port> | mpg123 -
    Or with: listen <host> <port> <proxy> <proxy_port> | mpg123 -
-   The proxy modificates are done by Tim Jansen <tjansen@gmx.net>
-   NOTE:
+   The proxy modifications are done by Tim Jansen <tjansen@gmx.net>
+   busy-waiting fixed (removed) by Peter Cordes <peter@llama.nslug.ns.ca>
+  NOTE:
    Lately, mpg123 (version 0.59p-pre) has been handling http-streams
    very nicely. So this program is more or less obsolete, unless you
    want to dump the mp3-stream to a file.
-   -
+
+  Also note that only one listen program at a time can actually listen to UDP
+  messages, because we use a static port number on the local machine
+  -
    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
    the Free Software Foundation; either version 2, or (at your option)
@@ -153,12 +157,10 @@
 
   if (connect (udps, (struct sockaddr *) &name, sizeof (name)) < 0)
   {
-	  perror ("udpconnect:");
+	  perror ("UDP connect:");
 	  exit (2);
   }
 
-  fcntl (udps, F_SETFL, O_NONBLOCK);
-
   /* Connect to the server */
   fprintf (stderr, "Connecting to %s port %d\n", contacthost, contactport);
   if (connect (s, (struct sockaddr *) &name, len) < 0)
@@ -176,7 +178,6 @@
     setsockopt (s, SOL_SOCKET, SO_KEEPALIVE, (void *)&tmp, sizeof (tmp));
     tmp = 100000;
     setsockopt (s, SOL_SOCKET, SO_RCVBUF, (void *)&tmp, sizeof (tmp));
-    fcntl (s, F_SETFL, O_NONBLOCK);
   }
 
   /* Read from standard input and put on the socket */
@@ -191,7 +192,7 @@
   else
     {
       my_snprintf (buf, LBUFSIZE, 
-		   "GET / HTTP/1.0\r\nHost: %s\r\nx-audiocast-udpport: 6000\r\nAccept: */*\r\n\r\n", 
+		   "GET / HTTP/1.0\r\nHost: %s\r\nx-audiocast-udpport: 6000\r\nAccept: */*\r\n\r\n",
 		   argv[1]);
     }
   send (s, buf, strlen (buf), 0);
@@ -199,7 +200,7 @@
   fprintf (stderr, "Reading response..\n");
   /* Make sure we read LBUFSIZE before we go on */
   n = 0;
-  while (n != LBUFSIZE)
+  while (n < LBUFSIZE)
     {
       errno = 0;
       len = recv (s, header + n, LBUFSIZE - n, 0);
@@ -234,7 +235,9 @@
     n = strip_shout_header (header, n);
 
   /* This little prebuffer is a contribution from <kit@connectnet.com> */
-  while (n != PREBUFFER) 
+  
+  n = 0;  /* start counting from zero again for the data */
+  while (n < PREBUFFER)
     {
       errno = 0;
       len = recv (s, buf + n, PREBUFFER - n, 0);
@@ -254,46 +257,62 @@
 
   write (1, &buf[find_frame_ofs(buf, n)], n);
 
-  sendto (udps, "x-audiocast-udpport: 6000\r\n", strlen ("x-audiocast-udpport: 7000\r\n"), 0, (struct sockaddr *)&name, sizeof (name));
-
+  {
+    char m[] = "x-audiocast-udpport: 7000\r\n";
+    sendto (udps, m, sizeof(m)-1, 0, (struct sockaddr *)&name, sizeof (name));
+  }
   
   errno = 0;
   fprintf (stderr, "Reading from socket\n");
   while (42)
   {
+	  fd_set fds;
+
+	  FD_ZERO( &fds );
+	  FD_SET( udps, &fds );
+	  FD_SET( s, &fds );
+
+	  if( -1 == select( FD_SETSIZE, &fds, NULL, NULL, NULL ) )
 	  {
-		  char buf[BUFSIZE];
-		  int udpn = recv (udps, buf, BUFSIZE - 1, 0);
+		  perror( "select" );
+		  exit( 1 );
+	  }
 
-		  if (udpn > 0)
+	  if( FD_ISSET( udps, &fds ) )
+	  {
+		  int udpn = recv (udps, buf, BUFSIZE - 1, 0);
+		  if( udpn < 0 )
+			  fprintf (stderr, "UDP read failed with [%s]\n", strerror (errno));
+		  else if( udpn > 0 )
 		  {
 			  buf[udpn] = '\0';
 			  if (buf[udpn - 1] == '\n')
 				  buf[udpn - 1] = '\0';
 			  fprintf (stderr, "Server says: [%s]\n", buf);
-			  fflush (stderr);
-		  } else {
-			  if (!is_recoverable (errno))
-				  fprintf (stderr, "UDP read failed with [%s]\n", strerror (errno));
-			  fflush (stderr);
-		  }
+		  }else
+			  fputs( "zero length UDP read?!\n", stderr );
+		  fflush (stderr);   /* why is this needed? */
 	  }
-
-	  n = recv (s, buf, LBUFSIZE, 0);
+	  
+	  if( FD_ISSET( s, &fds ) )
+	  {
+		  n = recv (s, buf, LBUFSIZE, 0);
 #ifdef DEBUG
-	  fprintf (stderr, "%d\n", n); /* Tells us how much each read() read */
+		  fprintf (stderr, "%d\n", n); /* Tells us how much each read() read */
 #endif
-	  if ((n == -1) && !is_recoverable (errno))
-	  {
-		  fprintf (stderr, "Error in read, exiting\n");
-		  perror ("recv");
-		  exit (3);
+		  if ((n == -1) && !is_recoverable (errno))
+		  {
+			  fprintf (stderr, "Error in read, exiting\n");
+			  perror ("recv");
+			  exit (3);
+		  }
+		  if (n == 0) /* EOF */
+			  break;
+		  write (1, buf, n);
+		  errno = 0;
 	  }
-	  if (n == 0) /* EOF */
-		  break;
-      write (1, buf, n);
-      errno = 0;
-    }
+  }				       /* main loop */
+   
   fprintf (stderr, "No more data, closing down socket, last error [%s]\n", strerror (errno));
   close (s);
   exit (0);
@@ -382,7 +401,7 @@
 	fprintf (stderr, 
 		 "Caught signal %d, guess the player exited. Damn.\n", sig);
 #ifdef DEBUG
-	fprintf (stderr, "The last we fead it was:\n[%s]\n", buf);
+	fprintf (stderr, "The last we fed it was:\n[%s]\n", buf);
 	fprintf (stderr, "Which, in hex would be:\n[%p]\n", buf);
 #endif
 	exit (1);


-- 
#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter@llama.nslug. , ns.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BCE


--- End Message ---
--- Begin Message ---
icecast-client has been removed from Debian.  For more information,
please see <http://bugs.debian.org/279526>.

--- End Message ---

Reply to: