enum TVerdict CEsockTest29_11::easyTestStepL( void ) { TVerdict verdict = EFail; TInt ret; Logger().WriteFormat(_L("Send/ Recv on PDummy3 socket but no avail MBuf Memory, mBuf becomes avail after send")); RSocketServ ss; ret = ss.Connect(); TESTL(KErrNone == ret); CleanupClosePushL(ss); // open dummy prot 3 Logger().WriteFormat(_L("Openning Dummy Protocol 3")); RSocket sock; ret = sock.Open(ss,_L("Dummy Protocol 3")); TESTL(KErrNone == ret); // connecti socket TSockAddr addr; TRequestStatus stat; sock.Connect(addr, stat); User::WaitForRequest(stat); TESTL(KErrNone == stat.Int()); // drain MBuf Pool Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol")); ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0); Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetFreeMBufs returned %d"), ret); // send data and wait for 1/10 seconds Logger().WriteFormat(_L("Sending Data")); _LIT8( sendData, "bla bla bla bla"); sock.Send(sendData,0,stat); const TUint KTenMilliSecs = 10000; User::After(KTenMilliSecs); // free all mbufs Logger().WriteFormat(_L("Attempting to set KDummyOptionSetFreeMBufs Option in Protocol")); ret = sock.SetOpt(KDummyOptionSetFreeMBufs, 0, 0); TESTL(ret == KErrNone); Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetFreeMBufs returned %d"), ret); // wait for send to return User::WaitForRequest(stat); Logger().WriteFormat(_L("Send has returned %d"), stat.Int()); if(stat.Int() != KErrNone) { verdict = EFail; } // recieve data and verify that it is the same as send data TBuf8<20> recvBuf; TRequestStatus recvStatus; sock.Recv(recvBuf, 0, recvStatus); User::WaitForRequest(recvStatus); Logger().WriteFormat(_L("recieving data on PDummy3 has returned %d"), recvStatus.Int()); if(recvStatus.Int() != KErrNone) { verdict = EFail; } Logger().WriteFormat(_L("Comparing Recieved data and Sent data"), recvStatus.Int()); if(recvBuf.Compare(sendData) == 0) { verdict = EPass; } sock.Close(); CleanupStack::PopAndDestroy(&ss); SetTestStepResult(verdict); return verdict; }
// Main void MainL() { /* Inetd Setup Create a inetd process */ RProcess inetd; CleanupClosePushL(inetd); User::LeaveIfError(inetd.Create(_L("inetd"), _L(""))); // Resume inetd inetd.Resume(); // Wait for inetd to be ready console->Printf(_L("[ press any key ]")); console->Getch(); // Get and ignore character /* IPEcho Part Connect to socket server */ console->Printf(_L("Connect to socket server ... \n")); RSocketServ socketServ; CleanupClosePushL(socketServ); User::LeaveIfError(socketServ.Connect()); // Open RConnection console->Printf(_L("Open RConnection ... \n")); RConnection connect; CleanupClosePushL(connect); User::LeaveIfError(connect.Open(socketServ, KConnectionTypeDefault)); // Start RConnection console->Printf(_L("Start RConnection ... \n")); TCommDbConnPref prefs; prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); User::LeaveIfError(connect.Start(prefs)); // Handle options here like (ie: No Prompt) // Open RSocket console->Printf(_L("Open Socket ... \n")); RSocket sock; CleanupClosePushL(sock); User::LeaveIfError(sock.Open(socketServ, KAfInet, KSockStream, KProtocolInetTcp, connect)); // Connect console->Printf(_L("Connect Socket ... \n")); TRequestStatus status; TInetAddr echoServAddr(KInetAddrLoop, 7); // 7: TCP port sock.Connect(echoServAddr, status); User::WaitForRequest(status); User::LeaveIfError(status.Int()); // Wait for the socket transfer to be over console->Printf(_L("[ press any key ]")); console->Getch(); // Get and ignore character // Send a packet console->Printf(_L("Send a packet ... \n")); HBufC8* packet = HBufC8::NewL(KSocketDefaultBufferSize); CleanupStack::PushL(packet); packet->Des().SetMax(); packet->Des().FillZ(); sock.Send(packet->Des(), 0, status); User::WaitForRequest(status); User::LeaveIfError(status.Int()); // Receive it back console->Printf(_L("Received it back ... \n")); packet->Des().Zero(); TPtr8 buff = packet->Des(); sock.Recv(buff, 0, status); User::WaitForRequest(status); User::LeaveIfError(status.Int()); // Terminates console->Printf(_L("Terminates ... \n")); CleanupStack::PopAndDestroy(packet); CleanupStack::PopAndDestroy(&sock); CleanupStack::PopAndDestroy(&connect); CleanupStack::PopAndDestroy(&socketServ); CleanupStack::PopAndDestroy(&inetd); }
enum TVerdict CEsockTest29_10::easyTestStepL( void ) { SetTestStepResult(EFail); TInt ret; const TUint KOneSecond = 1000000; Logger().WriteFormat(_L("Send/ Recv on PDummy3 socket but no avail MBuf Memory, mBuf becomes avail after send")); RSocketServ ss; ret = ss.Connect(); TESTL(KErrNone == ret); // open dummy prot 3 Logger().WriteFormat(_L("Openning Dummy Protocol 3")); RSocket sock; ret = sock.Open(ss,_L("Dummy Protocol 3")); TESTL(KErrNone == ret); // connect socket TSockAddr addr; TRequestStatus connStat; sock.Connect(addr, connStat); User::WaitForRequest(connStat); TESTL(KErrNone == connStat.Int()); // send packet 1 TRequestStatus stat; Logger().WriteFormat(_L("Attempting to create a packet to receive later")); _LIT8(sendDataOne, "First Send"); sock.Send(sendDataOne,0,stat); User::WaitForRequest(stat); TESTL(KErrNone == stat.Int()); // wait for packets to go through esock User::After(KOneSecond * 2); // gobble mBufs TInt nFree = 0; sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol")); while (nFree > 0) { ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); } Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetGobbleMBufs returned %d"), ret); // we are running in high priority and allocating in a loop. // so kernel may not be able to enlarge the pools. // wait for kernel to enlarge the pool // We have to come out from the loop as well. User::After(KOneSecond * 2); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol")); while (nFree > 0) { ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); } Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetGobbleMBufs returned %d"), ret); // Once again User::After(KOneSecond * 2); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol")); while (nFree > 0) { ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); } Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetGobbleMBufs returned %d"), ret); // Once again User::After(KOneSecond * 2); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol")); while (nFree > 0) { ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); } // Once again User::After(KOneSecond * 2); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); Logger().WriteFormat(_L("Attempting to set KDummyOptionSetGobbleMBufs Option in Protocol")); while (nFree > 0) { ret = sock.SetOpt(KDummyOptionSetGobbleMBufs, 0, 0); sock.GetOpt(KDummyOptionGetMBufFreeSpace, 0, nFree); } // send packet 2 User::After(KOneSecond); TRequestStatus stat2; _LIT8(sendDataTwo, "Second Send"); Logger().WriteFormat(_L("Sending Data - Should never complete")); sock.Send(sendDataTwo,0,stat2); User::After(KOneSecond); Logger().WriteFormat(_L("Now cancel the Send")); sock.CancelSend(); User::WaitForRequest(stat2); TESTL(stat2 == KErrCancel); Logger().WriteFormat(_L("Receiving Data -- expected to pick up sendDataOne")); TBuf8<100> buf; TRequestStatus stat3; sock.Recv(buf, 0, stat3); User::After(KOneSecond); User::WaitForRequest(stat3); TESTL(buf.Compare(sendDataOne) == 0); // send packet 3 _LIT8(sendDataThree, "Third Send"); Logger().WriteFormat(_L("Sending Data ... again")); TRequestStatus stat4; sock.Send(sendDataThree,0,stat4); User::After(1000); // free memory Logger().WriteFormat(_L("Now free memory - should get send and receive completion")); Logger().WriteFormat(_L("Attempting to set KDummyOptionSetFreeMBufs Option in Protocol")); ret = sock.SetOpt(KDummyOptionSetFreeMBufs, 0, 0); Logger().WriteFormat(_L("Socket::SetOpt KDummyOptionSetFreeMBufs returned %d"), ret); TESTL(KErrNone == ret); Logger().WriteFormat(_L("Sending Data - Should now complete")); User::WaitForRequest(stat4); TESTL(stat4.Int() == KErrNone); // recieve data and compare contents to sent data Logger().WriteFormat(_L("Receiving Data")); sock.Recv(buf, 0, stat); User::WaitForRequest(stat); Logger().WriteFormat(_L("Recv has returned %d"), stat.Int()); TBuf<100> buf16; buf16.Copy(buf); if(buf.Compare(sendDataThree) == 0) { SetTestStepResult(EPass); } Logger().WriteFormat(_L("Data Recv'ed is '%S'"), &buf16); sock.Close(); ss.Close(); return TestStepResult(); }