> Hello!
> A couple weeks ago we had a talk about BSession and its flaws. I
> said then that I had an idea to make it better. Now... I think I did,
Great! I was worried you would be too busy with University.
> what remains to be seen is if you think so too. Also, I did not managed
> to resolve the de-synchronization part, and here I need help.
>
> >> So we need it, but can we get rid of its flaws?
> >>
> >> a) de-synchronization
> I need help here... I cannot think of a way to do that with a single
> port. Do you have any ideas? I was thinking numbering each "frame" to be
> sent and keeping track on the receive end. If the next "frame" number is
> not the one expected, quit the thread which is running the receive loop.
> Even I don't like this, but I cannot think of something else...
The problem is not losing an entire port message. This problem is caused by
not knowing the
message end if we don't recognize the 'what'.
Solution: add the size of the message as the first field.
Buffer:
[size] <-- message 1
[what]
[reserved]
[...]
[size] <-- message 2
[what]
[reserved]
[...]
Also, never split the message into two port calls. Then BSessionNG will know
how to skip to the
next message.
> I attached the source code. Look at it and please tell me what you think.
Sorry my list settings are messed up... can you e-mail it to me?
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.
status_t GetNext(int32 *what, int32 *protocol = NULL, ssize_t *size = NULL);
template <class Type>status_t Read(Type *data);
status_t ReadString(char **s);
status_t DetachCurrent(BMessage *); //only works if protocol is BMESSAGE
status_t DetachCurrent(PortMessage *); //works for both SESSION and PORT_LINK
status_t BeginMessage(int32 what);
template <class Type>status_t Attach(Type *data);
status_t AttachString(char *s);
status_t Attach(PortMessage *pmsg);
status_t Flush();
status_t Flush(bigtime_t timeout);
status_t FlushWithReply(PortMessage *msg);
void Close();
SendBMessage(BMessage *msg); //will Flush() and send using BMESSAGE protocol
SendPortMessage(PortMessage *pmsg); //will Flush() and send using PORT_LINK
protocol
The class will switch to SESSION if BeginMessage() is called before Flush()ing
the current buffer.
Otherwise it will use PORT_LINK.
You can therefore use this class and mix and match SESSION and PORT_LINK
without the client code
needing to know the protocol of each message. You can find out in the GetNext()
call.
The buffer would be re-used like in BSession but resized if needed.
Cheers,
Paul.
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover