Read-only archive of the All About Symbian forum (2001–2013) · About this archive

User::WaitForRequest with Timeout

5 replies · 8,914 views · Started 02 October 2003

Hi all,

I have a problem, I like use the RSocket class but without use the CActive class for the asynchronous service.

The problem is in the RSocket::Read member if I use the User::WaitForResquest is blocking. I like read only if I have got data to read or have a Timeout.

I try to make this:

btsocket->Read(data,status);

int timeout = 1000;
RTimer timer;
TRequestStatus timerstatus;
int nsteps = 2;
int step = ((timeout*1000)/nsteps);

timer.CreateLocal();

timer.After(timerstatus,step);

for(;😉
{
User::WaitForAnyRequest();
if(timerstatus!=KRequestPending)
{
nsteps--;
if(!nsteps) break;
timer.After(timerstatus,step);
}

if(status!=KRequestPending) break;
}

if(timerstatus==KRequestPending) User::WaitForRequest(timerstatus);

timer.Close();

The problem is the Socket operation are pendient and I can�t eliminate. If I make:

static void RequestComplete(TRequestStatus*& aStatus,TInt aReason);

but... Don�t work. It makes error.

other possible solutions is try to use before that read:

err=btsocket->GetOpt(KSockSelectRead,KSOLSocket,bfr);

To know if there is data to read, but this don�t actualize the data (always have the same return).

Anyboy Can help me?
Any idea to resolve this...?

Best regards,
Sir Graham.

Use the Cancel functions of the RTimer and RSocket classes. When the timer completes first, you call the correct Cancel function from the RSocket class. When the socket completes, you call RTimer::Cancel();

Hi cmatthee,

Thanks for you answer, but This not Work. It makes a error: E32USER-CBase 46

"This panic is raised by an active scheduler, a CActiveScheduler. It is caused by a stray signal."

I dont�t understand because, I don�t use a CActive Class....

Regards,
Sir Graham.

I solved this problem (with stray signal) by setting active object e.t SetActive() which indicate that active obbject issue request to asynchronous service provider .
It may help

btsocket->Read(data,status);

int timeout = 1000;
RTimer timer;
TRequestStatus timerstatus;
int nsteps = 2;
int step = ((timeout*1000)/nsteps);

timer.CreateLocal();

timer.After(timerstatus,step);

for( ; ; )
{
User::WaitForAnyRequest();
if(timerstatus!=KRequestPending)
{
nsteps--;
if(!nsteps)
{
// timeout cancelread operation
btsocket->CancelRead();
break;
}
timer.After(timerstatus,step);
}
else if (status!=KRequestPending)
{
// got some data on socket...
timer->Cancel();
break;
}
}
timer.Close();

//Hope it works