[pygobject] Wrap gio.SocketListener.accept_socket_async|finish() and add a test



commit b8c7e996498bd72df551011af85ff05ef7335b4f
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date:   Fri Jan 1 12:41:08 2010 +0100

    Wrap gio.SocketListener.accept_socket_async|finish() and add a test

 gio/gsocket.override  |   86 +++++++++++++++++++++++++++++++++++++++++++++++-
 tests/test_gsocket.py |   24 +++++++++++++
 2 files changed, 108 insertions(+), 2 deletions(-)
---
diff --git a/gio/gsocket.override b/gio/gsocket.override
index 449514c..4ed716e 100644
--- a/gio/gsocket.override
+++ b/gio/gsocket.override
@@ -480,11 +480,93 @@ _wrap_g_socket_listener_accept_socket(PyGObject *self,
     }
     return Py_BuildValue("(NN)", py_socket, py_source_object);
 }
+%%
+override g_socket_listener_accept_socket_async kwargs
+static PyObject *
+_wrap_g_socket_listener_accept_socket_async(PyGObject *self,
+                                            PyObject *args,
+                                            PyObject *kwargs)
+{
+    static char *kwlist[] = { "callback", "cancellable", "user_data", NULL };
+    PyGIONotify *notify;
+    PyGObject *py_cancellable = NULL;
+    GCancellable *cancellable;
+
+    notify = pygio_notify_new();
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+                            "O|OO:gio.SocketListener.accept_socket_async",
+                            kwlist,
+                            &notify->callback,
+                            &py_cancellable,
+                            &notify->data))
+        goto error;
+      
+    if (!pygio_notify_callback_is_valid(notify))
+        goto error;
+
+    if (!pygio_check_cancellable(py_cancellable, &cancellable))
+        goto error;
+
+    pygio_notify_reference_callback(notify);
+
+    g_socket_listener_accept_socket_async(G_SOCKET_LISTENER(self->obj),
+                          cancellable,
+                          (GAsyncReadyCallback) async_result_callback_marshal,
+                          notify);
+
+    Py_INCREF(Py_None);
+    return Py_None;
+
+ error:
+    pygio_notify_free(notify);
+    return NULL;
+}
+%%
+override g_socket_listener_accept_socket_finish kwargs
+static PyObject *
+_wrap_g_socket_listener_accept_socket_finish(PyGObject *self,
+                                            PyObject *args,
+                                            PyObject *kwargs)
+{
+    static char *kwlist[] = { "result", NULL };
+    GError *error = NULL;
+    PyGObject *result;
+    PyObject *py_socket, *py_source_object;
+    GObject *source_object;
+    GSocket *socket;
+
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs,"O!:gio.SocketListener.accept_socket_finish",
+                                     kwlist,
+                                     &PyGAsyncResult_Type, &result))
+        return NULL;
+
+    socket = g_socket_listener_accept_socket_finish(G_SOCKET_LISTENER(self->obj),
+                                                    G_ASYNC_RESULT(result->obj),
+                                                    &source_object,
+                                                    &error);
+
+    if (pyg_error_check(&error))
+        return NULL;
+
+    if (socket)
+        py_socket = pygobject_new((GObject *)socket);
+    else {
+        py_socket= Py_None;
+        Py_INCREF(py_socket);
+    }
+
+    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_socket, py_source_object);
+}
 
 /* Could not write method GSocket.receive_from: No ArgType for GSocketAddress** */
 /* Could not write method GSocket.receive_message: No ArgType for GSocketAddress** */
 /* Could not write method GSocket.send_message: No ArgType for GOutputVector* */
 /* Could not write method GSocket.create_source: No ArgType for GIOCondition */
 /* 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** */
diff --git a/tests/test_gsocket.py b/tests/test_gsocket.py
index bfc25f2..16ff40f 100644
--- a/tests/test_gsocket.py
+++ b/tests/test_gsocket.py
@@ -98,3 +98,27 @@ class TestSocketListener(unittest.TestCase):
 
         loop = glib.MainLoop()
         loop.run()
+
+    def test_socket_listener_accept_socket_async(self):
+        def callback(listener, result):
+            try:
+                socket, source = listener.accept_socket_finish(result)
+                self.failUnless(isinstance(socket, gio.Socket))
+            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_socket_async(callback)
+
+        loop = glib.MainLoop()
+        loop.run()



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