×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    416

    RSocket::Read and HBufC8

    Hi,

    I know the size of the message coming from a client at runtime. So I create a buffer:

    Code:
    iDynBuffer = HBufC8::NewL(dataSize);
    ... enabled writing:
    Code:
                  
    TPtr8 dynBufferPtr(NULL,dataSize);
    dynBufferPtr.Set(iDynBuffer->Des());
    ... fill the descriptor to its maximum length
    Code:
    iConnectedSocket.Read(dynBufferPtr, iStatus);
    ... the issuing of a request
    Code:
    SetActive();
    The problem is with HBufC8. You can read in the SDK documentation: ... the resulting maximum length of the descriptor, may be larger than requested due to the way memory is allocated in Symbian OS.

    So instead of 10 bytes Read is trying to fill 12 bytes. I understand this approach, but what is the correct one when using Read/Send functions?

    update: Interesting post, and the second one
    Last edited by elviin; 2008-10-27 at 07:17.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: RSocket::Read and HBufC8

    That is true, using simple HBufC8:es for RSocket::Read is a trap. However you have almost found a solution: there is an other TPtr8::Set method, where you can specify maxlength. Unfortunately this TPtr8::Set expects a TUint8* rendering the whole thing a bit ugly (in fact after doing that you do not benefit from using HBufC8, you could simply User::Alloc/L instead), and also remember that this descriptor has to be a member variable (since it is involved in an asynchronous request). And because TPtr8 has no default constructor on the target device, you have to initialize it in your own constructor (with NULL,0 for example). So it is not that nice after all.
    An other common approach is using RecvOneOrMore, collecting the data in some buffer, and checking if everything has arrived. If yes, handle the data, if no, issue RecvOneOrMore again.

  3. #3
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    416

    Re: RSocket::Read and HBufC8

    As always thank you Wizard for the reply. My solution which seems to be working for me:

    Code:
                       RBuf8 iDynBuffer2;
                        iDynBuffer2.CreateL(dataSize);
                        iDynBuffer2.FillZ();
                        
                        iConnectedSocket.Read(iDynBuffer2, iStatus);

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: RSocket::Read and HBufC8

    Oh, you are right. I always forget about the existence of RBuf :-S

  5. #5
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    416

    Re: RSocket::Read and HBufC8

    As I have begun with the Symbian development more then one month ago, I must say that the descriptors and handling text is the most annoying thing. But i must learn to live with that. Is there any proposed solution to make the descriptor handling and the api a bit more homogeneous?

  6. #6
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    416

    Re: RSocket::Read and HBufC8

    I would like to know the way how to convert properly Unicode string received in
    Code:
    RBuf8 iDynBuffer2
    ; to RBuf16, so that I can display it using e.g. CAknInformationNote::ExecuteLD(const TDesC &aPrompt)

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: RSocket::Read and HBufC8

    8 and 16 bit descriptors can be Copy-ed back and forth.
    Or you can use CnvUtfConverter::ConvertToUnicodeFromUtf8L, which does the conversion in one step, and it also decodes UTF-8 encoded characters if your 8-bit descriptor happens to use that encoding.

  8. #8
    Nokia Developer Champion
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    1,572

    Re: RSocket::Read and HBufC8

    as said by wiz,

    if your text contains English/latin or just 8 bit characters only, you could use a copy.

    However, I would prefer a CnvUtfConverter::ConvertToUnicodeFromUtf8L as this would work with japanese, chinese, or any other script as well, and I guess the penalty is not much, until you plan to do a thousand conversions in a second
    Amit Kankani
    Nokia Developer Champion

  9. #9
    Registered User
    Join Date
    Dec 2005
    Posts
    1,236

    Re: RSocket::Read and HBufC8

    Hi,

    You could check section 4.3 in this document on descriptors
    Regards,
    Sriky

Similar Threads

  1. Problem in using RSocket::Read() Recv()
    By rensijie in forum Symbian Networking & Messaging (Closed)
    Replies: 5
    Last Post: 2006-08-12, 15:58

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×