[interfacekit] Re: BSession(NG)

Hi Adi.



>I am waiting a seccond reply from you, now that I've sent you the source code.



I had a look last night and it works fine as a BSession. However, it's too 
complex to change it
into a multi-protocol (SESSION, PORT_LINK) class. (See later).



>>Also, never split the message into two port calls.

>No. I'm sorry, I will never agree with you on this one!



If you don't split the message you don't need the packetlist BList structure, 
and the code is much
simpler because you don't need to re-assemble the message or use multiple 
buffers.



In BSessionNG::WriteData(), the call is not re-startable because the client 
doesn't know how much
data was sent or left behind. I prefer atomic API calls - either it worked 
completely, or it
didn't at all. But it really doesn't matter since we would abandon the session 
completely.



However, if the client decides to abort during building the message there is no 
going back because
the half built message may have already been sent. BSessionNG called 
PrivateSync() behind our
back.



On the receiving end, StartReadMessage() calls EnsureComplete() so there is no 
advantage in
sending half the beginning of a message because it still waits for the complete 
message. Infact,
it would mean two read_port() calls instead of one.



Also the user of the class has to try and decide what is the optimal buffer 
size to avoid
excessive fragmentation but not waste memory. This is hard to guess. If we say 
it is the size of
the largest message, then a small message in the beginning of the buffer will 
cause the end of the
large message to end up in the next message. It's partly implementation 
dependant so I think the
decision should be done by the class.



There is the advantage of not having a maximum message size limited by the 
kernel port
implementation, but we were actually optimizing for small messages. Also on 
receiving,
EnsureCompleteMessage() allocates memory for the full message so limits should 
be enforced
somewhere.



ReadData() and WriteData() would have been simple pointer maths and a memcpy(), 
but now it's a
while loop with 'slot' management or write_port() inside. I was just going to 
steal the code from
PortMessage/PortLink.


If you consider adding DetachCurrent(PortMesssage *) or DetachCurrent(BMessage 
*) you will realise
you again it would be simpler without multiple buffer slots to memcpy() or 
Unflatten() from.

One way around it is to declare the size of the complete incoming multipart 
message so you can
pre-allocate a right-sized buffer. But with partial messages being 
PrivateSync()'ed out before
EndWriteMessage() you can't.


>>I only had time to scribble a brief interface. I haven't seen your source but 
>>I was thinking of
one class handling SESSION and PORT_LINK, and BMESSAGE, for both reading and 
writing. Infact, it
would know how to mix the three protocols.

>PortLink and BSession can be replaced by this.



Good, then the code would be the same for SESSION and PORT_LINK we would just 
comment out some
Flush() calls to turn PORT_LINK into SESSION and vice versa.



Merging them means maybe we want to change the size variables from int16 (32Kb) 
to int32.


>BMessage was never on my "supported features list". I see no reason to add 
>BMessage support.

>I must repeat myself: This is not a general purpose messaging system! This is 
>used internaly by
the Interface Kit. It covers our needs. I *do not* want to make this a BIG 
messaging system for
everyone to use it; BMessage/BLooper system is EXCELENT! I want to keep 
BSessionNG at its
simpliest form with all necesities that app_server team needs to have its work 
done.



I agree, no bloat. However, I don't understand how BMessage::ConvertToMessage() 
will be used.
There is a lot of SESSION to BMessage conversion in the interfacekit. So I'm 
wondering can we
reduce it? Perhaps at some point we want to send a BMessage over the same port? 
Or forward a
BMessage? I don't know yet.


Cheers,

Paul.




        
                
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

Other related posts: