Skip to content

Commit

Permalink
Wrap gio.SocketListener.accept_socket() and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
gianmt committed Jan 1, 2010
1 parent 1aa5e30 commit c9496b2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
48 changes: 47 additions & 1 deletion gio/gsocket.override
Expand Up @@ -349,13 +349,59 @@ _wrap_g_socket_listener_accept(PyGObject *self, PyObject *args, PyObject *kwargs
}
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,
PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "cancellable", NULL };
GError *error = NULL;
PyGObject *py_cancellable = NULL;
GCancellable *cancellable;
PyObject *py_socket, *py_source_object;
GObject *source_object;
GSocket *socket;

if (!PyArg_ParseTupleAndKeywords(args, kwargs,"|O:gio.SocketListener.accept_socket",
kwlist,
&py_cancellable))
return NULL;


if (!pygio_check_cancellable(py_cancellable, &cancellable))
return NULL;

socket = g_socket_listener_accept_socket(G_SOCKET_LISTENER(self->obj),
&source_object,
cancellable,
&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: 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_async: No ArgType for GAsyncReadyCallback */
Expand Down
13 changes: 13 additions & 0 deletions tests/test_gsocket.py
Expand Up @@ -61,3 +61,16 @@ def test_socket_listener_accept(self):

connection, source = listener.accept(cancellable=None)
self.failUnless(isinstance(connection, gio.TcpConnection))

def test_socket_listener_accept_socket(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)

socket, source = listener.accept_socket(cancellable=None)
self.failUnless(isinstance(socket, gio.Socket))

0 comments on commit c9496b2

Please sign in to comment.