Problems with URLAudio and leaking file descriptors on record

Anthony DeRobertis <[email protected]> Tue, 16 May 2006 17:01:45 -0400
Newsgroups gmane.comp.gnu.bayonne.devel
Message-ID <[email protected]>
Every time we record an audio file with 1.2.14pl2, Bayonne is leaking 
the file descriptor (=leaving the file open). This appears to be because 
afSeek is failing, because URLAudio is not seeing the recorded files as 
Socket::STREAM.

I think this is because they are being opened by afCreate in ccAudio --- 
which of course has no knowledge of URLAudio.

The following patch adds in a URLAudio::afCreate which seems to fix the 
problem. Is there a better approach?

diff -rdbU3 bayonne-1.2.14pl2/server/audio.cpp bayonne-1.2.14pl2.new/server/audio.cpp
--- bayonne-1.2.14pl2/server/audio.cpp	2006-05-16 14:21:37.000000000 -0400
+++ bayonne-1.2.14pl2.new/server/audio.cpp	2006-05-16 16:53:30.000000000 -0400
@@ -53,6 +53,26 @@
 	return false;
 }
 
+
+bool URLAudio::afCreate(const char *path)
+{
+	offset = 0;
+
+	setProxy(NULL, 0);
+
+	/* this is an evil hack */
+	::close(::open(path, O_CREAT | O_TRUNC | O_RDWR, 0660));
+	
+	if(URLStream::errSuccess == get(path, 0))
+	{
+		file.fd = so;
+		return true;
+	}
+	file.fd = -1;
+	return false;
+}
+
+
 bool URLAudio::isOpen(void)
 {
 	if(so > -1)
diff -rdbU3 bayonne-1.2.14pl2/server/server.h bayonne-1.2.14pl2.new/server/server.h
--- bayonne-1.2.14pl2/server/server.h	2003-04-23 11:42:00.000000000 -0400
+++ bayonne-1.2.14pl2.new/server/server.h	2006-05-16 16:21:41.000000000 -0400
@@ -120,6 +120,7 @@
 private:
 	unsigned long offset;
 	bool afOpen(const char *path);
+	bool afCreate(const char *path);
 	bool afPeek(unsigned char *data, unsigned size);
 	bool afSeek(unsigned long pos);
 	void afClose(void);