[pygobject] Wrap gio.SocketListener.accept_finish() and add a test



commit a5ae2d5ba3db34967fe07a3cc97b75df2793988c
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Fri Jan 1 12:28:53 2010 +0100

    Wrap gio.SocketListener.accept_finish() and add a test

 gio/gsocket.override  |   44 ++++++++++++++++++++++++++++++++++++++++++--
 tests/test_gsocket.py |   24 ++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 2 deletions(-)
---
diff --git a/gio/gsocket.override b/gio/gsocket.override
index 9625dfd..449514c 100644
--- a/gio/gsocket.override
+++ b/gio/gsocket.override
@@ -392,6 +392,48 @@ _wrap_g_socket_listener_accept_async(PyGObject *self,
     return NULL;
 }
 %%
+override g_socket_listener_accept_finish kwargs
+static PyObject *
+_wrap_g_socket_listener_accept_finish(PyGObject *self,
+                                      PyObject *args,
+                                      PyObject *kwargs)
+{
+    static char *kwlist[] = { "result", NULL };
+    GError *error = NULL;
+    PyGObject *result;
+    PyObject *py_connection, *py_source_object;
+    GObject *source_object;
+    GSocketConnection *connection;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:gio.SocketListener.accept_finish",
+                                     kwlist,
+                                     &PyGAsyncResult_Type, &result))
+        return NULL;
+
+    connection = g_socket_listener_accept_finish(G_SOCKET_LISTENER(self->obj),
+                                                 G_ASYNC_RESULT(result->obj),
+                                                 &source_object,
+                                                 &error);
+
+    if (pyg_error_check(&error))
+        return NULL;
+
+    if (connection)
+        py_connection = pygobject_new((GObject *)connection);
+    else {
+        py_connection = Py_None;
+        Py_INCREF(py_connection);
+    }
+
+    if (source_object)
+        py_source_object = pygobject_new((GObject *)source_object);
+    else {
+        py_source_object= Py_None;
+        Py_INCREF(py_source_object);
+    }
+    return Py_BuildValue("(NN)", py_connection, py_source_object);
+}
+%%
 override g_socket_listener_accept_socket kwargs
 static PyObject *
 _wrap_g_socket_listener_accept_socket(PyGObject *self,
@@ -446,5 +488,3 @@ _wrap_g_socket_listener_accept_socket(PyGObject *self,
 /* Could not write method GSocketControlMessage.serialize: No ArgType for gpointer */
 /* Could not write method GSocketListener.accept_socket_async: No ArgType for GAsyncReadyCallback */
 /* Could not write method GSocketListener.accept_socket_finish: No ArgType for GObject** */
-/* Could not write method GSocketListener.accept_async: No ArgType for GAsyncReadyCallback */
-/* Could not write method GSocketListener.accept_finish: No ArgType for GObject** */
diff --git a/tests/test_gsocket.py b/tests/test_gsocket.py
index fd19cbb..bfc25f2 100644
--- a/tests/test_gsocket.py
+++ b/tests/test_gsocket.py
@@ -74,3 +74,27 @@ class TestSocketListener(unittest.TestCase):
 
         socket, source = listener.accept_socket(cancellable=None)
         self.failUnless(isinstance(socket, gio.Socket))
+
+    def test_socket_listener_accept_async(self):
+        def callback(listener, result):
+            try:
+                connection, source = listener.accept_finish(result)
+                self.failUnless(isinstance(connection, gio.TcpConnection))
+            finally:
+                loop.quit()
+
+        address = gio.inet_address_new_from_string("127.0.0.1")
+        inetsock = gio.InetSocketAddress(address, 1024)
+        
+        listener = gio.SocketListener()
+        listener.add_address(inetsock,
+                             gio.SOCKET_TYPE_STREAM,
+                             gio.SOCKET_PROTOCOL_TCP)
+
+        client = gio.SocketClient()
+        client.connect_to_host("127.0.0.1:1024", 1024)
+        
+        listener.accept_async(callback)
+
+        loop = glib.MainLoop()
+        loop.run()



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