TInt RecvLine(RTest &aTest, TDes8 &aBuf, RSocket &aSock) { TInt offset=0; TText ch=0; do { TPtr8 ptr(NULL, 0); TSockXfrLength len; TRequestStatus stat; ptr.Set((TUint8 *)aBuf.Ptr()+offset, aBuf.Length()-offset, aBuf.Length()-offset); aSock.RecvOneOrMore(ptr,0,stat,len); User::WaitForRequest(stat); aTest(stat==KErrNone); TInt length=len(); TInt n=0; while (length--) { ch = *(ptr.Ptr()+n); if (ch=='\r' || ch=='\n') break; ++offset; ++n; } } while (ch!='\r' && ch!='\n' ); aBuf.SetLength(offset); return offset; }
HX_RESULT HXSymbianTCPReader::Read(RSocket& socket, UINT16 uSize) { HX_RESULT res = HXR_FAILED; if (m_pParent) { res = HXSymbianSocketHelper::ResizeOrCreate(m_pCCF, uSize, m_pBuffer); if (HXR_OK == res) { IHXTimeStampedBuffer* pTSBuffer = 0; if(HXR_OK == m_pBuffer->QueryInterface(IID_IHXTimeStampedBuffer, (void **)&pTSBuffer)) { pTSBuffer->SetTimeStamp(HX_GET_TICKCOUNT()); HX_RELEASE(pTSBuffer); } m_bufDes.Set(m_pBuffer->GetBuffer(), 0, m_pBuffer->GetSize()); iStatus = KRequestPending; socket.RecvOneOrMore(m_bufDes, 0, iStatus, m_amountRead); SetActive(); } } return res; }
int ILibSocketWrapper_recv(int socketObject, char *buffer, int bufferLength) { RSocket *s = (RSocket*)SocketArray[socketObject]; RBuf8 *buf = new RBuf8(); TRequestStatus status; TSockXfrLength aLen; int RetVal=0; if(buf->Create(bufferLength)==KErrNone) { s->RecvOneOrMore(*buf,0,status,aLen); User::WaitForRequest(status); if(status!=KErrNone) { RetVal = 0; } else { RetVal = aLen(); Mem::Copy(buffer,(void*)buf->Ptr(),RetVal); } } buf->Close(); delete buf; return(RetVal); }
TInt ReadIntoBuffer() { TRequestStatus status; TPtr8 ptr8((TUint8*)buffer, sizeof(buffer), sizeof(buffer)); TSockXfrLength tlen; socket.RecvOneOrMore(ptr8, 0, status, tlen); User::WaitForRequest(status); bufferTop = tlen(); bufferBottom = 0; return status.Int(); }
void CTcpConn::StartReceiving() { DEBUG_INFO("TcpConn(%p) StartReceiving\n", this); /* Clear buffer */ iBufRx.Zero(); receiving = true; iSocket.RecvOneOrMore(iBufRx, 0, iStatus, iLen); SetActive(); }
TVerdict CPPPMinMaxMMU::doTestStepL() { const TInt KMaxMMU = 4000; const TInt KMinMMU = 1; TBuf8<KMaxMMU> *sendBuf = new(ELeave) TBuf8<KMaxMMU>(); CleanupStack::PushL(sendBuf); TBuf8<KMaxMMU> *recvBuf = new(ELeave) TBuf8<KMaxMMU>(); CleanupStack::PushL(recvBuf); TBuf8<KMaxMMU> *recvBuf2 = new(ELeave) TBuf8<KMaxMMU>(); CleanupStack::PushL(recvBuf2); //initialize COMM //CommInitL(EFalse); //Start Comms server // _LIT(KPhbkSyncCMI, "phbsync.cmi"); // (void)StartC32WithCMISuppressions(KPhbkSyncCMI); SetTestStepResult(EPass); INFO_PRINTF1(_L("Starting: Socket Server\n")); RSocketServ ss; // Start the socket server TEST(KErrNone == ss.Connect()); RSocket sock; TRequestStatus sta; INFO_PRINTF1(_L("Open a socket\n")); // Get the test address TInetAddr RemAddr(7); TPtrC testAddr; TEST(GetStringFromConfig(_L("AddressInfo"), _L("TestPPPIPAddr"), testAddr)); if(testAddr.Length()) { RemAddr.Input(testAddr); } else { INFO_PRINTF1(_L("Test FAILED\nMissing address information in config file: ")); return EFail; } // Open a socket TEST(KErrNone == sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp)); INFO_PRINTF1(_L("Connecting Socket to:")); TBuf<30> printAddr; RemAddr.Output(printAddr); INFO_PRINTF1(printAddr); // Connect a socket sock.Connect(RemAddr,sta); // Wait for Connect to complete User::WaitForRequest(sta); TEST(sta.Int() == 0); TInt iterEnd; GetIntFromConfig(_L("MMUInfo"), _L("TestPPPmaxMMU"), iterEnd); if (iterEnd > KMaxMMU) iterEnd = KMaxMMU; TInt iterStart; GetIntFromConfig(_L("MMUInfo"), _L("TestPPPminMMU"), iterStart); if (iterStart < KMinMMU) iterStart = KMinMMU; TInt i,j; TSockXfrLength recvLen; INFO_PRINTF1(_L("Send/Recv frames")); for(j=iterStart;j<=iterEnd;j++) { sendBuf->Zero(); for (i=0;i<j;i++) sendBuf->Append(Math::Random() & 0x7f); INFO_PRINTF2(_L("Sending Packet of Size: %d"),j); // Send data to echo port sock.Write(*sendBuf,sta); User::WaitForRequest(sta); TEST(sta.Int() == 0); i=0; recvBuf->Zero(); while(i<j) { // Receive data from echo port sock.RecvOneOrMore(*recvBuf2,0,sta,recvLen); User::WaitForRequest(sta); TEST(sta.Int() == 0); i += recvBuf2->Length(); recvBuf->Append(*recvBuf2); } TEST(KErrNone == recvBuf->Compare(*sendBuf)); INFO_PRINTF1(_L(" Received echoed Packet")); } sock.Shutdown(RSocket::EStopOutput,sta); User::WaitForRequest(sta); TEST(sta.Int() == 0); sock.Close(); ss.Close(); CleanupStack::PopAndDestroy(3); return TestStepResult(); }
enum TVerdict CTestStepLoopback::doTestStepL() { SetTestStepResult(EFail); // const TUid KPktTxKey = {0x104045dd}; // const TUid KPktRxKey = {0x104045de}; // const TUid KMeUid = {0x101F529F}; // TSecurityPolicy readPolicy(ECapability_None); // TSecurityPolicy writePolicy(ECapability_None); // TInt result = RProperty::Define(KMeUid, KPktTxKey .iUid, RProperty::EInt, readPolicy, writePolicy); // result = RProperty::Define(KMeUid, KPktRxKey .iUid, RProperty::EInt, readPolicy, writePolicy); RSocketServ ss; CleanupClosePushL(ss); Logger().WriteFormat(_L("Start: creating + starting connection")); User::LeaveIfError(ss.Connect()); RConnection conn; CleanupClosePushL(conn); User::LeaveIfError(conn.Open(ss)); User::LeaveIfError(conn.Start()); TInt srvPort; if(!GetIntFromConfig(_L("TcpLoop"), _L("Port"), srvPort)) { srvPort = 5002; } Logger().WriteFormat(_L("Start: creating server socket listening on %d"), srvPort); RSocket srv; CleanupClosePushL(srv); User::LeaveIfError(srv.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn)); TInetAddr srvAddr(KAfInet); srvAddr.SetPort(srvPort); User::LeaveIfError(srv.Bind(srvAddr)); User::LeaveIfError(srv.Listen(5)); RSocket acc; CleanupClosePushL(acc); User::LeaveIfError(acc.Open(ss)); TRequestStatus accStat; srv.Accept(acc, accStat); Logger().WriteFormat(_L("Start: connecting client socket")); RSocket cli; CleanupClosePushL(cli); User::LeaveIfError(cli.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn)); srvAddr.SetAddress(0xC0A80707); TRequestStatus cliStat; cli.Connect(srvAddr, cliStat); User::WaitForRequest(cliStat, accStat); User::WaitForRequest(cliStat, accStat); User::LeaveIfError(cliStat.Int()); User::LeaveIfError(accStat.Int()); //_LIT8(KTest, "jackdaws love my big sphinx of quartz"); TInt xferSize = 0; if(!GetIntFromConfig(_L("TcpLoop"), _L("xferSize"), xferSize)) { xferSize = 1 * 1000 * 1000; } TInt fc = User::FastCounter(); TInt txSize = 0; TInt txCnt = 0; TRequestStatus txStat(KErrNone); TBuf8<4096> txBuf; txBuf.SetMax(); TInt rxSize = 0; TInt rxCnt = -1; TRequestStatus rxStat(KErrNone); TBuf8<4096> rxBuf; Logger().WriteFormat(_L("Transferring %d bytes"), xferSize); while(rxSize < xferSize) { fc = User::FastCounter(); if(txStat.Int() != KRequestPending) { RDebug::Printf("tx status:%d, ", txStat.Int()); cli.Send(txBuf, 0, txStat); ++txCnt; txSize += txBuf.Length(); RDebug::Printf("tx #%d, %d, +%d\n", txCnt, fc, txBuf.Length()); } if(rxStat.Int() != KRequestPending) { RDebug::Printf("rx status:%d, ", rxStat.Int()); ++rxCnt; rxSize += rxBuf.Length(); RDebug::Printf("rx #%d, %d, +%d\n", rxCnt, fc, rxBuf.Length()); TSockXfrLength dummy; acc.RecvOneOrMore(rxBuf, 0, rxStat, dummy); } User::WaitForRequest(rxStat, txStat); } Logger().WriteFormat(_L("Transferred; %d writes, %d reads"), txCnt, rxCnt); // RProperty::Get(KUidSystemCategory, KPktTxKey .iUid, txCnt); // RProperty::Define(KUidSystemCategory, KPktRxKey .iUid, rxCnt); // Logger().WriteFormat(_L("Packet counts; %d sends, %d processes"), txCnt, rxCnt); CleanupStack::PopAndDestroy(5, &ss); SetTestStepResult(EPass); return TestStepResult(); };