esound r495 - in trunk: . docs



Author: fejj
Date: Tue Jul 15 16:33:19 2008
New Revision: 495
URL: http://svn.gnome.org/viewvc/esound?rev=495&view=rev

Log:
2008-07-15  Jeffrey Stedfast  <fejj novell com>

	* configure.ac: Release 0.2.39

	* NEWS: updated

	* esdlib.c Update all code to use new read/write/connect wrappers
	that abort if the operation takes too long and/or the other end
	drops the connection. Fixes bug #542391.
	(read_timeout): New function to abort a read() if it takes too
	long and/or if the other end drops the connection.
	(write_timeout): Same idea here.
	(connect_timeout): Same.

2008-07-15  Jeffrey Stedfast  <fejj novell com>

	* audio_alsa09.c: Suppress verbose error messages from ALSA. Patch
	by Stanislav Brabec to fix bug #528718.

2008-07-15  Jeffrey Stedfast  <fejj novell com>

	* util.c (esd_get_socket_dirname): Allow for multiple esd
	instances. Patch by Martin (Pitt?) from Ubuntu. Fixes bug #465067.

2008-07-15  Jeffrey Stedfast  <fejj novell com>

	* esd-config.in: Fix esound-config on multilib setups (bug
	#435652). Patch by Matthias Clasen <mclasen redhat com>.

2008-07-15  Jeffrey Stedfast  <fejj novell com>

	* esddsp.in (LD_PRELOAD): search for library by itself, so that
	both 32-bit and 64-bit programs work with a single esddsp
	script. Fixes bug #435651.

2008-07-15  Jeffrey Stedfast  <fejj novell com>

	* audio_oss.c (esd_audio_open): Don't report errors if /dev/dsp
	doesn't exist (Based on Havoc's patch).  Fixes bug #435649.

2008-07-15  Jeffrey Stedfast  <fejj novell com>

	Following fixes by RÃmi Cardona - fixes bug #531947

	* doc/Makefile.am: Fixed up gtk-doc build.

	* Makefile.am: Reorder LDADD for libesddsp

	* esddsp.c (open_wrapper): If mode_t is smaller than int, pop the
	mode as an int from the varargs.

	* clients.c (get_new_clients): Cast 3rd argument of accept() to a
	socklen_t* to fix some breakage on amd64(?).



Modified:
   trunk/ChangeLog
   trunk/Makefile.am
   trunk/NEWS
   trunk/audio_alsa09.c
   trunk/audio_oss.c
   trunk/clients.c
   trunk/configure.ac
   trunk/docs/Makefile.am
   trunk/esd-config.in
   trunk/esddsp.c
   trunk/esddsp.in
   trunk/esdlib.c
   trunk/util.c

Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am	(original)
+++ trunk/Makefile.am	Tue Jul 15 16:33:19 2008
@@ -61,7 +61,7 @@
 	audio_win32.c
 
 libesddsp_la_LDFLAGS = -version-info $(ESD_VERSION_INFO)
-libesddsp_la_LIBADD = $(DL_LIB) -lm libesd.la
+libesddsp_la_LIBADD = libesd.la $(DL_LIB) -lm
 
 libesddsp_la_SOURCES = \
 	esddsp.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Tue Jul 15 16:33:19 2008
@@ -1,4 +1,15 @@
 ===============
+Version 0.2.39
+===============
+	* Fixed esd client-side code to not hang if esd crashes/hangs
+          or otherwise becomes unreachable (Jeffrey Stedfast)
+	* Suppress verbose error messages from ALSA (Stanislav Brabec)
+	* Allow for multiple esd instances 
+	* Fix esound-config for multi-lib setups (Matthias Clasen)
+	* Don't report errors about /dev/dsp not existing (Havoc Pennington)
+	* Various other build fixes for AMD64 (RÃmi Cardona)
+
+===============
 Version 0.2.38
 ===============
 	* Fix 100% CPU problem introduced in 0.2.37 (Joe Marcus Clarke)

Modified: trunk/audio_alsa09.c
==============================================================================
--- trunk/audio_alsa09.c	(original)
+++ trunk/audio_alsa09.c	Tue Jul 15 16:33:19 2008
@@ -22,9 +22,9 @@
 
 
 /* Debug flag */
-int alsadbg = 0;
+static int alsadbg = 0;
 /* Error flag */
-int alsaerr = 0;
+static int alsaerr = 0;
 #include <alsa/asoundlib.h>
 
 /* FULL DUPLEX => two handlers */
@@ -285,6 +285,10 @@
         }
 }
 
+static void noerr(const char *file, int line, const char *func, int err,
+				  const char *fmt, ...)
+{
+}
 
 #define ARCH_esd_audio_open
 
@@ -294,7 +298,18 @@
 	int channels;
 	int format;
 	char *dev;
+	char *debug;
   
+	debug = getenv("ESD_DEBUG");
+	if (debug && *debug) {
+		alsadbg = atoi(debug);
+		if (alsadbg < 0)
+			alsadbg = 0;
+	} else {
+		/* suppress verbose error messages from alsa-lib */
+		snd_lib_error_set_handler(noerr);
+	}
+
 	if (alsadbg)
 		fprintf(stderr, "esd_audio_open\n");
 

Modified: trunk/audio_oss.c
==============================================================================
--- trunk/audio_oss.c	(original)
+++ trunk/audio_oss.c	Tue Jul 15 16:33:19 2008
@@ -41,7 +41,8 @@
     device = esd_audio_device ? esd_audio_device : "/dev/dsp";
     if ((afd = open(device, mode, 0)) == -1)
     {   /* Opening device failed */
-        perror(device);
+	if (errno != ENOENT)
+		perror(device);
         return( -2 );
     }
 

Modified: trunk/clients.c
==============================================================================
--- trunk/clients.c	(original)
+++ trunk/clients.c	Tue Jul 15 16:33:19 2008
@@ -155,7 +155,7 @@
       if ( esd_use_ipv6 ) {
 	char addrbuf[INET6_ADDRSTRLEN];
 
-	fd = accept( listen,(struct sockaddr *)&incoming6, &size_in6 );
+	fd = accept( listen,(struct sockaddr *)&incoming6, (socklen_t *) &size_in6 );
 	if ( fd < 0 )
                 goto again;
 	port = ntohs( incoming6.sin6_port );
@@ -168,7 +168,7 @@
       else
 #endif
       {
-	fd = accept( listen, (struct sockaddr*) &incoming, &size_in );
+	      fd = accept( listen, (struct sockaddr*) &incoming, (socklen_t *) &size_in );
 	if ( fd < 0 )
 		goto again;
 	    port = ntohs( incoming.sin_port );

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Tue Jul 15 16:33:19 2008
@@ -1,9 +1,9 @@
 AC_PREREQ([2.58])
-AC_INIT(esound, 0.2.38)
+AC_INIT(esound, 0.2.39)
 
 ESD_MAJOR_VERSION=0
 ESD_MINOR_VERSION=2
-ESD_MICRO_VERSION=38
+ESD_MICRO_VERSION=39
 ESD_VERSION=$ESD_MAJOR_VERSION.$ESD_MINOR_VERSION.$ESD_MICRO_VERSION
 
 AC_CANONICAL_TARGET([])
@@ -25,10 +25,8 @@
 AC_SUBST(ESD_VERSION)
 AC_SUBST(ESD_VERSION_INFO)
 
-pkgdocdir="\$(datadir)/doc/esound"
-AC_SUBST(pkgdocdir)
-
 AC_PROG_CC
+AC_PROG_CXX
 AC_PROG_CPP
 AC_LIBTOOL_WIN32_DLL
 AM_PROG_LIBTOOL

Modified: trunk/docs/Makefile.am
==============================================================================
--- trunk/docs/Makefile.am	(original)
+++ trunk/docs/Makefile.am	Tue Jul 15 16:33:19 2008
@@ -14,8 +14,6 @@
 
 CLEANFILES = esound.dvi esound.ps esound.tex esound.aux esound.log
 
-htmldir=$(pkgdocdir)/html
-
 if HAVE_JW
 noinst_DATA = html/index.html
 else

Modified: trunk/esd-config.in
==============================================================================
--- trunk/esd-config.in	(original)
+++ trunk/esd-config.in	Tue Jul 15 16:33:19 2008
@@ -1,10 +1,7 @@
 #!/bin/sh
 
-audiofile_libs="@AUDIOFILE_LIBS@"
-audiofile_cflags="@AUDIOFILE_CFLAGS@"
-
-prefix= prefix@
-exec_prefix= exec_prefix@
+prefix=`pkg-config --variable prefix esound`
+exec_prefix=`pkg-config --variable exec_prefix esound`
 exec_prefix_set=no
 
 usage="\
@@ -39,32 +36,13 @@
       echo $exec_prefix
       ;;
     --version)
-      echo @ESD_VERSION@
+      pkg-config --modversion esound
       ;;
     --cflags)
-      if test @includedir@ != /usr/include ; then
-        includes=-I includedir@
-        for i in $audiofile_cflags ; do
-          if test $i = -I includedir@ ; then
-            includes=""
-          fi
-        done      
-      fi
-      echo $includes $audiofile_cflags
+      pkg-config --cflags esound
       ;;
     --libs)
-      my_audiofile_libs=
-      libdirs=-L libdir@
-      for i in $audiofile_libs ; do
-        if test $i != -L libdir@ ; then
-          if test -z "$my_audiofile_libs" ; then
-            my_audiofile_libs="$i"
-          else
-            my_audiofile_libs="$my_audiofile_libs $i"
-          fi
-        fi
-      done
-      echo $libdirs -lesd $my_audiofile_libs @LIBS@
+      pkg-config --libs esound
       ;;
     *)
       echo "${usage}" 1>&2

Modified: trunk/esddsp.c
==============================================================================
--- trunk/esddsp.c	(original)
+++ trunk/esddsp.c	Tue Jul 15 16:33:19 2008
@@ -225,7 +225,10 @@
   dsp_init ();
 
   va_start (args, flags);
-  mode = va_arg (args, mode_t);
+  if (sizeof (mode_t) < sizeof (int))
+	  mode = va_arg (args, int);
+  else
+	  mode = va_arg (args, mode_t);
   va_end (args);
 
   if (!strcmp (pathname, "/dev/dsp"))

Modified: trunk/esddsp.in
==============================================================================
--- trunk/esddsp.in	(original)
+++ trunk/esddsp.in	Tue Jul 15 16:33:19 2008
@@ -106,7 +106,7 @@
 prefix= prefix@
 exec_prefix= exec_prefix@
 
-LD_PRELOAD="@libdir@/libesddsp so  ESD_MAJOR_VERSION@ @libdir@/libesd so  ESD_MAJOR_VERSION@ $LD_PRELOAD"
+LD_PRELOAD="libesddsp so  ESD_MAJOR_VERSION@ libesd so  ESD_MAJOR_VERSION@ $LD_PRELOAD"
 export LD_PRELOAD
 
 # invoke the program with the args given

Modified: trunk/esdlib.c
==============================================================================
--- trunk/esdlib.c	(original)
+++ trunk/esdlib.c	Tue Jul 15 16:33:19 2008
@@ -20,9 +20,11 @@
 #include <arpa/inet.h>
 #include <errno.h>
 #include <sys/wait.h>
+#include <poll.h>
 
 #include <sys/un.h>
 
+
 #ifndef SUN_LEN
 #define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path)  \
                      + strlen ((ptr)->sun_path))
@@ -75,6 +77,88 @@
 #endif
 #endif
 
+static ssize_t
+read_timeout (int fd, char *buf, size_t buflen)
+{
+	struct pollfd pfd[1];
+	int flags, rv;
+	ssize_t n;
+	
+	pfd[0].fd = fd;
+	pfd[0].events = POLLIN;
+	
+	do {
+		pfd[0].revents = 0;
+		rv = poll (pfd, 1, 100);
+	} while (rv == -1 && errno == EINTR);
+	
+	if (rv < 1 || !(pfd[0].revents & POLLIN)) {
+		errno = ETIMEDOUT;
+		return -1;
+	}
+	
+	if ((flags = fcntl (fd, F_GETFL)) == -1)
+		return -1;
+	
+	fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+	
+	do {
+		n = read (fd, buf, buflen);
+	} while (n == -1 && errno == EINTR);
+	
+	if (n == -1) {
+		rv = errno;
+		fcntl (fd, F_SETFL, flags);
+		errno = rv;
+		return -1;
+	}
+	
+	fcntl (fd, F_SETFL, flags);
+	
+	return n;
+}
+
+static ssize_t
+write_timeout (int fd, const char *buf, size_t buflen)
+{
+	struct pollfd pfd[1];
+	size_t nwritten = 0;
+	int flags, rv;
+	ssize_t n;
+	
+	if ((flags = fcntl (fd, F_GETFL)) == -1)
+		return -1;
+	
+	fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+	
+	do {
+		pfd[0].fd = fd;
+		pfd[0].events = POLLOUT;
+		
+		do {
+			pfd[0].revents = 0;
+			rv = poll (pfd, 1, 100);
+		} while (rv == -1 && errno == EINTR);
+		
+		if (rv < 1 || !(pfd[0].revents & POLLOUT)) {
+			fcntl (fd, F_SETFL, flags);
+			errno = ETIMEDOUT;
+			return -1;
+		}
+		
+		do {
+			n = write (fd, buf + nwritten, buflen - nwritten);
+		} while (n == -1 && errno == EINTR);
+		
+		if (n > 0)
+			nwritten += n;
+	} while (nwritten < buflen);
+	
+	fcntl (fd, F_SETFL, flags);
+	
+	return nwritten;
+}
+
 /**
  * esd_set_socket_buffers: set buffer lengths on a socket to optimal.
  * @sock: ESD socket
@@ -124,13 +208,13 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the necessary information */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
 
     /* get the latency back from the server */
-    if ( read( esd, &lag, sizeof(lag) ) != sizeof(lag) ) {
+    if ( read_timeout( esd, (char *) &lag, sizeof(lag) ) != sizeof(lag) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -149,6 +233,7 @@
     return lag;
 }
 
+
 /**
  * esd_send_auth: send authorization to esd
  * @sock: ESD socket
@@ -207,25 +292,26 @@
 	}
 
 	esound_genrand(auth_key, ESD_KEY_LEN);
-	write( auth_fd, auth_key, ESD_KEY_LEN);
-    } else
+	write_timeout( auth_fd, (const char *) auth_key, ESD_KEY_LEN);
+    } else {
       /* read the key from the authorization file */
-      if ( ESD_KEY_LEN != read( auth_fd, auth_key, ESD_KEY_LEN ) )
+      if ( ESD_KEY_LEN != read_timeout( auth_fd, (char *) auth_key, ESD_KEY_LEN ) )
 	goto exit_fd;
-
+    }
+    
     /* send the key to the server */
-    if ( ESD_KEY_LEN != write( sock, auth_key, ESD_KEY_LEN ) )
+    if ( ESD_KEY_LEN != write_timeout( sock, (const char *) auth_key, ESD_KEY_LEN ) )
 	/* send key failed */
 	goto exit_fd;
 
     /* send the key to the server */
-    if ( sizeof(endian) != write( sock, &endian, sizeof(endian) ) )
+    if ( sizeof(endian) != write_timeout( sock, (const char *) &endian, sizeof(endian) ) )
 	/* send key failed */
 	goto exit_fd;
 
     /* read auth reply. esd will reply 1 as an int for yes and 0 for no */
     /* then close the connection */
-    if ( sizeof(reply) != read( sock, &reply, sizeof(reply) ) ) {
+    if ( sizeof(reply) != read_timeout( sock, (char *) &reply, sizeof(reply) ) ) {
 	/* read ok failed */
 	retval = 0;
 	goto exit_fd;
@@ -278,10 +364,10 @@
       printf( "esound locking\n" );
     */
 
-    write( esd, &proto, sizeof(proto) );
+    write_timeout( esd, (const char *) &proto, sizeof(proto) );
     esd_send_auth( esd );
 
-    if ( read( esd, &ok, sizeof(ok) ) != sizeof(ok) ) {
+    if ( read_timeout( esd, (char *) &ok, sizeof(ok) ) != sizeof(ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -317,10 +403,10 @@
       printf( "esound unlocking\n" );
     */
 
-    write( esd, &proto, sizeof(proto) );
+    write_timeout( esd, (const char *) &proto, sizeof(proto) );
     esd_send_auth( esd );
 
-    if ( read( esd, &ok, sizeof(ok) ) != sizeof(ok) ) {
+    if ( read_timeout( esd, (char *) &ok, sizeof(ok) ) != sizeof(ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -357,10 +443,10 @@
       printf( "esound standing by\n" );
     */
 
-    write( esd, &proto, sizeof(proto) );
+    write_timeout( esd, (const char *) &proto, sizeof(proto) );
     esd_send_auth( esd );
 
-    if ( read( esd, &ok, sizeof(ok) ) != sizeof(ok) ) {
+    if ( read_timeout( esd, (char *) &ok, sizeof(ok) ) != sizeof(ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -396,10 +482,10 @@
       printf( "esound resuming\n" );
     */
 
-    write( esd, &proto, sizeof(proto) );
+    write_timeout( esd, (const char *) &proto, sizeof(proto) );
     esd_send_auth( esd );
 
-    if ( read( esd, &ok, sizeof(ok) ) != sizeof(ok) ) {
+    if ( read_timeout( esd, (char *) &ok, sizeof(ok) ) != sizeof(ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -408,6 +494,43 @@
     return ok;
 }
 
+static int
+connect_timeout (int sockfd, const struct sockaddr *serv_addr, size_t addrlen, int timeout)
+{
+	struct pollfd pfd[1];
+	int flags, rv;
+	
+	if ((flags = fcntl (sockfd, F_GETFL)) == -1)
+		return -1;
+	
+	fcntl (sockfd, F_SETFL, flags | O_NONBLOCK);
+	
+	if (connect (sockfd, serv_addr, addrlen) == 0) {
+		fcntl (sockfd, F_SETFL, flags);
+		return 0;
+	}
+	
+	if (errno != EINPROGRESS)
+		return -1;
+	
+	pfd[0].fd = sockfd;
+	pfd[0].events = POLLIN | POLLOUT;
+	
+	do {
+		pfd[0].revents = 0;
+		rv = poll (pfd, 1, timeout);
+	} while (rv == -1 && errno == EINTR);
+	
+	if (pfd[0].revents & (POLLIN | POLLOUT)) {
+		/* success, we are now connected */
+		fcntl (sockfd, F_SETFL, flags);
+		return 0;
+	}
+	
+	/* took too long / error connecting, either way: epic fail */
+	return -1;
+}
+
 /**
  * esd_connect_tcpip: make a TCPIP connection to ESD
  * @host: specifies hostname and port to connect to as "hostname:port"
@@ -512,7 +635,7 @@
            goto error_out;
          }
 
-         if ( connect( socket_out, res->ai_addr, res->ai_addrlen ) != -1 ) 
+         if ( connect_timeout ( socket_out, res->ai_addr, res->ai_addrlen, 1000 ) != -1 ) 
            break;
 
          close ( socket_out );
@@ -596,9 +719,9 @@
     socket_addr.sin_family = AF_INET;
     socket_addr.sin_port = htons( port );
   
-    if ( connect( socket_out,
-		  (struct sockaddr *) &socket_addr,
-		  sizeof(struct sockaddr_in) ) < 0 )
+    if ( connect_timeout ( socket_out,
+			   (struct sockaddr *) &socket_addr,
+			   sizeof(struct sockaddr_in), 1000 ) < 0 )
 	goto error_out;
 
     }
@@ -650,8 +773,7 @@
     socket_unix.sun_family = AF_UNIX;
     strncpy(socket_unix.sun_path, ESD_UNIX_SOCKET_NAME, sizeof(socket_unix.sun_path));
   
-    if ( connect( socket_out,
-		  (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix) ) < 0 )
+    if ( connect_timeout ( socket_out, (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix), 100 ) < 0 )
 	goto error_out;
   
     return socket_out;
@@ -795,7 +917,7 @@
 	
 	if (ret == 1) {
 	    char c;
-	    ret = read (esd_pipe[0], &c, 1);
+	    ret = read_timeout (esd_pipe[0], &c, 1);
 
 	    if (ret == 1) {
 		socket_out = esd_connect_unix();
@@ -857,19 +979,19 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the audio format information */
-    if ( write( sock, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( sock, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler );
 	return -1;
     }
-    if ( write( sock, &format, sizeof(format) ) != sizeof(format) ) {
+    if ( write_timeout( sock, (const char *) &format, sizeof(format) ) != sizeof(format) ) {
 	signal( SIGPIPE, phandler );
 	return -1;
     }
-    if( write( sock, &rate, sizeof(rate) ) != sizeof(rate) ) {
+    if( write_timeout( sock, (const char *) &rate, sizeof(rate) ) != sizeof(rate) ) {
 	signal( SIGPIPE, phandler );
 	return -1;
     }
-    if( write( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
+    if( write_timeout( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
 	signal( SIGPIPE, phandler );
 	return -1;
     }
@@ -971,19 +1093,19 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the audio format information */
-    if ( write( sock, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( sock, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( sock, &format, sizeof(format) ) != sizeof(format) ) {
+    if ( write_timeout( sock, (const char *) &format, sizeof(format) ) != sizeof(format) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if( write( sock, &rate, sizeof(rate) ) != sizeof(rate) ) {
+    if( write_timeout( sock, (const char *) &rate, sizeof(rate) ) != sizeof(rate) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if( write( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
+    if( write_timeout( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1052,19 +1174,19 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the audio format information */
-    if ( write( sock, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( sock, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( sock, &format, sizeof(format) ) != sizeof(format) ) {
+    if ( write_timeout( sock, (const char *) &format, sizeof(format) ) != sizeof(format) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if( write( sock, &rate, sizeof(rate) ) != sizeof(rate) ) {
+    if( write_timeout( sock, (const char *) &rate, sizeof(rate) ) != sizeof(rate) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if( write( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
+    if( write_timeout( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1122,19 +1244,19 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the audio format information */
-    if ( write( sock, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( sock, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( sock, &format, sizeof(format) ) != sizeof(format) ) {
+    if ( write_timeout( sock, (const char *) &format, sizeof(format) ) != sizeof(format) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if( write( sock, &rate, sizeof(rate) ) != sizeof(rate) ) {
+    if( write_timeout( sock, (const char *) &rate, sizeof(rate) ) != sizeof(rate) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if( write( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
+    if( write_timeout( sock, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1235,24 +1357,24 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the necessary information */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
 
-    if ( write( esd, &format, sizeof(format) ) != sizeof(format) ) {
+    if ( write_timeout( esd, (const char *) &format, sizeof(format) ) != sizeof(format) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, &rate, sizeof(rate) ) != sizeof(rate) ) {
+    if ( write_timeout( esd, (const char *) &rate, sizeof(rate) ) != sizeof(rate) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, &size, sizeof(size) ) != sizeof(size) ) {
+    if ( write_timeout( esd, (const char *) &size, sizeof(size) ) != sizeof(size) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
+    if ( write_timeout( esd, name_buf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1261,7 +1383,7 @@
     /* fsync( esd ); */
 
     /* get the sample id back from the server */
-    if ( read( esd, &id, sizeof(id) ) != sizeof(id) ) {
+    if ( read_timeout( esd, (char *) &id, sizeof(id) ) != sizeof(id) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1290,7 +1412,7 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* get the sample id back from the server */
-    if ( read( esd, &id, sizeof(id) ) != sizeof(id) ) {
+    if ( read_timeout( esd, (char *) &id, sizeof(id) ) != sizeof(id) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1319,7 +1441,7 @@
 /* we need to catch SIGPIPE to avoid the default handler giving us */
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1330,7 +1452,7 @@
     else
 	namebuf[ 0 ] = '\0';
 
-    if ( write( esd, namebuf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
+    if ( write_timeout( esd, namebuf, ESD_NAME_MAX ) != ESD_NAME_MAX ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1339,7 +1461,7 @@
     /* fsync( esd ); */
 
     /* get the sample id back from the server */
-    if ( read( esd, &id, sizeof(id) ) != sizeof(id) ) {
+    if ( read_timeout( esd, (char *) &id, sizeof(id) ) != sizeof(id) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1371,18 +1493,18 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the necessary information */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) ) {
+    if ( write_timeout( esd, (const char *) &sample, sizeof(sample) ) != sizeof(sample) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
     /* fsync( esd ); */
 
     /* get the sample id back from the server */
-    if ( read( esd, &id, sizeof(id) ) != sizeof(id) ) {
+    if ( read_timeout( esd, (char *) &id, sizeof(id) ) != sizeof(id) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1413,11 +1535,11 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the necessary information */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) ) {
+    if ( write_timeout( esd, (const char *) &sample, sizeof(sample) ) != sizeof(sample) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1425,7 +1547,7 @@
      fsync( esd ); 
 #endif
     /* get the sample id back from the server */
-    if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
+     if ( read_timeout( esd, (char *) &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1457,18 +1579,18 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the necessary information */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) ) {
+    if ( write_timeout( esd, (const char *) &sample, sizeof(sample) ) != sizeof(sample) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
     /* fsync( esd ); */
 
     /* get the sample id back from the server */
-    if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
+    if ( read_timeout( esd, (char *) &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1499,18 +1621,18 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the necessary information */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) ) {
+    if ( write_timeout( esd, (const char *) &sample, sizeof(sample) ) != sizeof(sample) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
     /* fsync( esd ); */
 
     /* get the sample id back from the server */
-    if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
+    if ( read_timeout( esd, (char *) &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
@@ -1541,18 +1663,18 @@
 /* a bad day - ignore the SIGPIPE, then make sure to catch all errors */
     phandler = signal( SIGPIPE, dummy_signal );    /* for closed esd conns */
     /* send the necessary information */
-    if ( write( esd, &proto, sizeof(proto) ) != sizeof(proto) ) {
+    if ( write_timeout( esd, (const char *) &proto, sizeof(proto) ) != sizeof(proto) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
-    if ( write( esd, &sample, sizeof(sample) ) != sizeof(sample) ) {
+    if ( write_timeout( esd, (const char *) &sample, sizeof(sample) ) != sizeof(sample) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }
     /* fsync( esd ); */
 
     /* get the sample id back from the server */
-    if ( read( esd, &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
+    if ( read_timeout( esd, (char *) &is_ok, sizeof(is_ok) ) != sizeof(is_ok) ) {
 	signal( SIGPIPE, phandler ); 
 	return -1;
     }

Modified: trunk/util.c
==============================================================================
--- trunk/util.c	(original)
+++ trunk/util.c	Tue Jul 15 16:33:19 2008
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdio.h>
 
 /* Run-time check for IPv6 support */
 int 
@@ -23,22 +24,18 @@
 const char*
 esd_get_socket_dirname (void) 
 {
-	const char *audiodev;
+	const char *audiodev = NULL;
 	static char *dirname = NULL;
 
-	if (dirname == NULL) {
-		if (!(audiodev = getenv("AUDIODEV"))) {
-			audiodev = "";
-		} else {
-			char *newdev = strrchr(audiodev, '/');
-			if (newdev != NULL) {
-				audiodev = newdev++;
-			}
-		}
-		dirname = malloc(strlen(audiodev) + sizeof("/tmp/.esd"));
-		strcpy(dirname, "/tmp/.esd");
-		strcat(dirname, audiodev);
-	}
+        if ((audiodev = getenv("AUDIODEV"))) {
+                char *newdev = strrchr(audiodev, '/');
+                if (newdev != NULL) {
+                        audiodev = newdev++;
+                }
+        } else
+            audiodev = "";
+        dirname = malloc(strlen(audiodev) +  40);
+        sprintf (dirname, "/tmp/.esd%s-%i", audiodev, getuid());
 
 	return dirname;
 }



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