[xiph-commits] r15283 - icecast/trunk/shout-python

brendan at svn.xiph.org brendan at svn.xiph.org
Wed Sep 10 00:25:17 PDT 2008


Author: brendan
Date: 2008-09-10 00:25:16 -0700 (Wed, 10 Sep 2008)
New Revision: 15283

Modified:
   icecast/trunk/shout-python/shout.c
Log:
Export get_connected, and allow threads during shout_open.
From: Michel Van den Bergh <michel.vandenbergh at uhasselt.be>


Modified: icecast/trunk/shout-python/shout.c
===================================================================
--- icecast/trunk/shout-python/shout.c	2008-09-10 04:57:43 UTC (rev 15282)
+++ icecast/trunk/shout-python/shout.c	2008-09-10 07:25:16 UTC (rev 15283)
@@ -57,6 +57,7 @@
 
 static PyObject* pshoutobj_open(ShoutObject* self);
 static PyObject* pshoutobj_close(ShoutObject* self);
+static PyObject* pshoutobj_get_connected(ShoutObject* self);
 static PyObject* pshoutobj_send(ShoutObject* self, PyObject* args);
 static PyObject* pshoutobj_sync(ShoutObject* self);
 static PyObject* pshoutobj_delay(ShoutObject* self);
@@ -81,6 +82,7 @@
   "\"host\", \"port\", \"password\" and \"mount\" must be specified).\n\n"
   "Methods:\n"
   "            open() - connect to server\n"
+  "   get_connected() - monitor connection status in nonblocking mode\n"
   "           close() - disconnect from server\n"
   "        send(data) - send audio data to server\n"
   "            sync() - sleep until server needs more data. This is equal to\n"
@@ -185,6 +187,8 @@
     "Connect to server." },
   { "close", (PyCFunction)pshoutobj_close, METH_NOARGS,
     "Close connection to server." },
+  { "get_connected", (PyCFunction)pshoutobj_get_connected, METH_NOARGS,
+    "Check for connection progress." },
   { "send", (PyCFunction)pshoutobj_send, METH_VARARGS,
     "Send audio data to server." },
   { "sync", (PyCFunction)pshoutobj_sync, METH_NOARGS,
@@ -363,9 +367,14 @@
 }
 
 static PyObject* pshoutobj_open(ShoutObject* self) {
-  if (shout_open(self->conn) != SHOUTERR_SUCCESS) {
+  int ret;
+  Py_BEGIN_ALLOW_THREADS
+  ret=shout_open(self->conn);
+  Py_END_ALLOW_THREADS
+  if (!((ret == SHOUTERR_SUCCESS)||
+        ((ret==SHOUTERR_BUSY) && shout_get_nonblocking(self->conn)))) {
     PyErr_SetString(ShoutError, shout_get_error(self->conn));
-
+    
     return NULL;
   }
 
@@ -411,6 +420,10 @@
   return Py_BuildValue("i", 1);
 }
 
+static PyObject* pshoutobj_get_connected(ShoutObject* self) {
+  return Py_BuildValue("i", shout_get_connected(self->conn));
+}
+
 static PyObject* pshoutobj_delay(ShoutObject* self) {
   return Py_BuildValue("i", shout_delay(self->conn));
 }



More information about the commits mailing list