Exemple #1
0
    int Ksock::Receive(Message& ioMessage)
    {
        /* valgrind believes that msgLen is uninitialised if Receive() returns 0;
         * this is, as far as I can tell, untrue, but I've added a spurious 
         * initialisation here to stop the complaints so I can concentrate on
         * more serious issues - rrw 2010-12-09
         */
        uint32_t msgLen(0);

        if (!ioMessage.IsEmpty())
            return Error::MessageIsNotEmpty;

        int rv = ioctl(mDevice.mFd, KBUS_IOC_NEXTMSG, &msgLen);
        if (rv < 0) return -errno;

        if (!msgLen)
        {
            // There was no next message.
            return 0;
        }


        ioMessage.mData.resize(msgLen);
        rv = SafeRead(mDevice.mFd, (uint8_t *)(&ioMessage.mData[0]), msgLen);
        if (rv  < 0) return rv;

        kbus_message_header *hdr = (kbus_message_header *)(&ioMessage.mData[0]);

        ioMessage.mName = std::string(kbus_msg_name_ptr(hdr), hdr->name_len);
        ioMessage.mIsEntire = true;
        ioMessage.mIsEmpty = false;
        ioMessage.mPointyData = NULL;
        ioMessage.mPointyLen = 0;
        return 1;
    }
//
// ExtractMsgLenL() (Static)
// Parses the msg header and length fields of the passed in descriptor.
// Returns the value of the msg length.
// 
TInt CReqstParser::ExtractMsgLenL(const TDesC8& aHeaderAndLen)
	{
	// Msg Length
	TUint msgLen(0);
	TLex8 lex(aHeaderAndLen.Right(KMaxMsgLenChars));
	lex.Val(msgLen);
	return msgLen;
	}
Exemple #3
0
static xmsg_handle_t
sendShortMsg(
    Msg m,
    SState *state )
{
    state->short_hdr.len = msgLen(m);
    xIfTrace(blastp, TR_DETAILED) {
	blast_phdr(&state->short_hdr);
    }
void CRpsMsg::ConstructL(const TDesC8& aMsgType, const TDesC8& aOpCode, const TUint aMsgNum, const CDesCArrayFlat& aArgArray) 
	{
	
	TUint numArgs(aArgArray.Count());
	iMsgDataArray = new (ELeave)CDesC8ArrayFlat(1);
	
	// Calc the total msg length
	TUint msgLen(KRqstLengthNoOpCodeNoArgsNoCommas + aOpCode.Length());
	for(TInt i(0); i < numArgs; ++i)
		{
		msgLen += aArgArray.MdcaPoint(i).Length();
		}
	// add commas to calculation
	msgLen += KRqstMsgElementsNoArgs + numArgs - 1;
	
	// Msg Type
	iMsgDataArray->AppendL(aMsgType);
	iMsgDataArray->AppendL(KComma);
	
	// Msg Len
	TBuf8<KMaxMsgLenChars> mlenString;
	mlenString.NumFixedWidth(msgLen, EDecimal, KMaxMsgLenChars);
	iMsgDataArray->AppendL(mlenString);
	iMsgDataArray->AppendL(KComma);
	
	// Msg Seq Num
	TBuf8<KMaxMsgNumChars> msnString;
	//msnString.Num(NextMsgNum());
	msnString.NumFixedWidth(aMsgNum, EDecimal, KMaxMsgNumChars);
	iMsgDataArray->AppendL(msnString);
	iMsgDataArray->AppendL(KComma);
	
	// OpCode
	iMsgDataArray->AppendL(aOpCode);
	iMsgDataArray->AppendL(KComma);
	
	// Arguments. Convert aArgArray data to 8-bit as we go.
	for(TInt i(0); i < numArgs; ++i)
		{
		TBuf8<KMaxElementSize> buf;
		buf.Copy(aArgArray.MdcaPoint(i));
		iMsgDataArray->AppendL(buf);
		iMsgDataArray->AppendL(KComma);
		}
		
	// EOM
	iMsgDataArray->AppendL(KEOM);
    }
// array to buf
// aBufOut is an uninstantiated buffer - caller assumes ownership on return
EXPORT_C void CRpsMsg::ExternalizeL(HBufC8*& aBufOut)
	{
	TUint msgLen(0);
	for(TInt i(0); i < iMsgDataArray->MdcaCount(); ++i)
		{
		msgLen += iMsgDataArray->MdcaPoint(i).Length();
		}
		
	aBufOut = HBufC8::NewL(msgLen);
	TPtr8 ptr = aBufOut->Des();
	
	for(TInt i(0); i < iMsgDataArray->MdcaCount(); ++i)
		{
		ptr.Append(iMsgDataArray->MdcaPoint(i));
		}	
	}
Exemple #6
0
// SendRequestL
// Creates the msg from the data elements passed in the descriptor array
// and sends over socket connection.
// Then waits until a response is received from the slave.
// Caller has to pass in empty HBufC8.
TInt CSender::SendRequestL(CRpsMsg& aRpsMsg, HBufC8** aResp)
	{
	
	// Generate request data buf
	HBufC8* msg = NULL;
	aRpsMsg.ExternalizeL(msg);
	CleanupStack::PushL(msg);

	// Send the msg over the socket
	TRequestStatus sendStatus;
	iSendSocket.Send(*msg, 0, sendStatus);
	User::WaitForRequest(sendStatus);
	CleanupStack::PopAndDestroy(msg);
	if(sendStatus != KErrNone)
		{
		RDEBUGPRINTLOGGER2(_L("CSender::SendRequestL Send error [%d]"),sendStatus.Int());
		return sendStatus.Int();
		}

	// Expect a response msg back from slave synchronously.
	// Return an error if resp not received in time-out.
	// Else pass the response msg up to the caller.

	// Expect the msg header+length
	TRequestStatus recvStatus;
	iBufferPreRead.Delete(0, iBufferPreRead.Length());
	iSendSocket.Recv(iBufferPreRead, 0, recvStatus);
	
	// ** TODO: check for error value in recvStatus (-191 returned if slave has crashed) **
	TInt ret = GetRequestOrTimeOut(recvStatus, KRespFromSlaveTimeout);
	if (recvStatus.Int() != KErrNone)
		{
		RDEBUGPRINTLOGGER2(_L("CSender::SendRequestL Recv error [%d]"),recvStatus.Int());
		}
		
	if(ret != KErrNone)
		{
		// We didn't receive a response within timelimit. 
		return ret;
		}
	 
	// Receive the rest of the msg.
	// Get msg length from pre-read
	TUint msgLen(0);
	TLex8 lex(iBufferPreRead.Right(KMaxMsgLenChars));
	lex.Val(msgLen);

	__ASSERT_ALWAYS(msgLen > KRespSocketPreReadSize, User::Panic(KPanicMsgFormat, 303)); // TODO - panic number?
	
	// Now read the rest of msg
	iBuffer.Close();
	iBuffer.CreateL(msgLen - KReqstSocketPreReadSize);
	// Recv operation should complete immediately if msg has been formatted correctly
	iSendSocket.Recv(iBuffer, 0, recvStatus);
	ret = GetRequestOrTimeOut(recvStatus, KRespFromSlaveTimeout);
	if(ret != KErrNone)
		{
		// We didn't receive a response within timelimit. 
		return ret;
		}
	// Check status of Recv operation
	if(recvStatus != KErrNone)
		{
		return recvStatus.Int();
		}
	
	iBufferAll.Close();
	iBufferAll.CreateL(msgLen);		// Give HandleRequestL the entire msg
	iBufferAll += iBufferPreRead;
	iBufferAll += iBuffer;
	
	// For debug ...
	RBuf16 buf;
	buf.CreateL(iBufferAll.Length());
	buf.Copy(iBufferAll);
	buf.Close();
	
	// Passing entire response msg to caller
	// Caller owns memory
	*aResp = iBufferAll.AllocL();
	
	iBufferPreRead.Delete(0, iBufferPreRead.Length());
	iBuffer.Close();
	iBufferAll.Close();

	return KErrNone;
	}