[pygobject] Wrap gio.SocketListener.accept() and add a test
- From: Gian Mario Tagliaretti <gianmt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject] Wrap gio.SocketListener.accept() and add a test
- Date: Thu, 31 Dec 2009 15:35:57 +0000 (UTC)
commit 1aa5e301c49f11e1c5ef58de44b4b03f714d1a70
Author: Gian Mario Tagliaretti <gianmt gnome org>
Date: Thu Dec 31 16:35:18 2009 +0100
Wrap gio.SocketListener.accept() and add a test
gio/gsocket.override | 46 +++++++++++++++++++++++++++++++++++++++++++++-
tests/test_gsocket.py | 13 +++++++++++++
2 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/gio/gsocket.override b/gio/gsocket.override
index f40e4df..6745d6b 100644
--- a/gio/gsocket.override
+++ b/gio/gsocket.override
@@ -304,6 +304,51 @@ _wrap_g_socket_listener_add_address(PyGObject *self, PyObject *args, PyObject *k
return Py_None;
}
}
+%%
+override g_socket_listener_accept kwargs
+static PyObject *
+_wrap_g_socket_listener_accept(PyGObject *self, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "cancellable", NULL };
+ GError *error = NULL;
+ PyGObject *py_cancellable = NULL;
+ GCancellable *cancellable;
+ PyObject *py_connection, *py_source_object;
+ GObject *source_object;
+ GSocketConnection *connection;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,"|O:gio.SocketListener.accept",
+ kwlist,
+ &py_cancellable))
+ return NULL;
+
+
+ if (!pygio_check_cancellable(py_cancellable, &cancellable))
+ return NULL;
+
+ connection = g_socket_listener_accept(G_SOCKET_LISTENER(self->obj),
+ &source_object,
+ cancellable,
+ &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);
+}
/* Could not write method GSocket.receive_from: No ArgType for GSocketAddress** */
/* Could not write method GSocket.receive_message: No ArgType for GSocketAddress** */
@@ -313,6 +358,5 @@ _wrap_g_socket_listener_add_address(PyGObject *self, PyObject *args, PyObject *k
/* Could not write method GSocketListener.accept_socket: No ArgType for GObject** */
/* 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: 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 b5b3694..7789332 100644
--- a/tests/test_gsocket.py
+++ b/tests/test_gsocket.py
@@ -48,3 +48,16 @@ class TestSocketListener(unittest.TestCase):
listener = gio.SocketListener()
effective = listener.add_address(inetsock, gio.SOCKET_TYPE_STREAM, gio.SOCKET_PROTOCOL_TCP)
self.failUnless(isinstance(effective, gio.InetSocketAddress))
+
+ def test_socket_listener_accept(self):
+ 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)
+
+ connection, source = listener.accept(cancellable=None)
+ self.failUnless(isinstance(connection, gio.TcpConnection))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]