Archived Forum Post

Index of archived forum posts


CkSocket not calling TaskCompleted event

Apr 06 '17 at 10:00

Language: Visual C++ 10.0 (32-bit)

If I open a socket and start a task with AcceptNextConnectionAsync, the event TaskCompleted is not called. The alternative with a get_Finished() while loop works. Is there an error in my usage?

class INetSocketConnectionProgress : public CkBaseProgress
INetSocketConnectionProgress () { }

void INetSocketConnectionProgress::TaskCompleted (CkTask& task)
//do something

void listen ()
CkSocket* socket = new CkSocket ();
socket->BindAndListen (0, 5);

INetSocketConnectionProgress progress;
socket->put_EventCallbackObject (&progress);

CkTask* acceptTask = socket->AcceptNextConnectionAsync (0);
acceptTask->Run ();

This is only an extract from the sourcecode. The function listen() is called by another part.
If I cancel the task, in the debug log of the task it says: "currentTaskStatus: TASK_STATUS_COMPLETED".

Many thanks for a hint in the right direction.

Accepted Answer

Your progress object is local and on the stack.

Your "listen()" method starts the async accept task and returns immediately. Upon returning the progress object (on the stack) is destructed.

The callback never happens because the callback object is no longer in existence.