Using a Gio.SocketClient
one can connect asynchronously to a server using connectAsync
. This requires supplying a function with the signature extern(C) void connectionCallback(GObject* object, GAsyncResult* result, void * userData)
. This function is supposed to call connectFinish
to complete the data collection. In C this is easy as the parameter to connectFinish
is a GAsyncResult*
, exactly the result parameter to connectCallback
. However the signature in D requires the parameter be an AsyncResultIF
. So the question is how does one create an instance of an AsyncResultIF
from a GAsyncResult*
in D. The subsidiary question is why does this have to be done in D when it is not needed in C?
On 17-05-2020 18:53, Russel Winder wrote:
Using a
Gio.SocketClient
one can connect asynchronously to a server usingconnectAsync
. This requires supplying a function with the signatureextern(C) void connectionCallback(GObject* object, GAsyncResult* result, void * userData)
. This function is supposed to callconnectFinish
to complete the data collection. In C this is easy as the parameter toconnectFinish
is aGAsyncResult*
, exactly the result parameter toconnectCallback
. However the signature in D requires the parameter be anAsyncResultIF
. So the question is how does one create an instance of anAsyncResultIF
from aGAsyncResult*
in D. The subsidiary question is why does this have to be done in D when it is not needed in C?
The callbacks using the unwrapped c parameters is something that needs
some work.
To get a D object from a C pointer you can use:
ObjectG.getDObject!AsyncResultIF(your_result);
Given the GAsyncResult*
parameter result I did:
auto resultData = ObjectG.getDObject!AsyncResultIF(result);
assert(resultData !is null);
writelnUt("@@@@@@ connectionCallback ", resultData.getSourceObject, ", ", resultData.getUserData);
which seems to work fine. :-) However when I call:
auto connection = client.connectFinish(resultData);
I am still getting a SIGSEGV. :-(
It seems that the AsyncResultIF
generated from the GAsyncResult*
is not a real AsynResultIF
.
On 18-05-2020 11:51, Russel Winder wrote:
Given the
GAsyncResult*
parameter result I did:auto resultData = ObjectG.getDObject!AsyncResultIF(result); assert(resultData !is null); writelnUt("@@@@@@ connectionCallback ", resultData.getSourceObject, ", ", resultData.getUserData);
which seems to work fine. :-) However when I call:
auto connection = client.connectFinish(resultData);
I am still getting a SIGSEGV. :-(
It seems that the
AsyncResultIF
generated from theGAsyncResult*
is not a realAsynResultIF
.
It looks like it should work, Is client also working fine.
This being a callback the client may need to be passed in the user_data
parameter.
The SocketClient
is, I believe, being passed to the callback via the GObject*
sourceObject
parameter. Passing it via the userData
would, I believe, be duplication.
In Python 3, using PyGobject, the callback signature seems to be:
def connection_callback(client: Gio.SocketClient, task: Gio.Task, user_data):
but maybe there is extra jiggery-pokery going on under the covers to deliver a Task
?
Hummm… the core of my problem was the type of sourceObject
, I clearly have to convert the GObject*
to a SocketClient
thus:
auto client = ObjectG.getDObject!SocketClient(cast(GSocketClient*)object);
annoying, but it seems to work. I still have problems in that things are not working, but I suspect it is now more to do with the actual I/O than the D/C interworking.
OK, I think I have it all working. :-)
On 19-05-2020 20:35, Russel Winder wrote:
OK, I think I have it all working. :-)
Great :)