On Tue, 14 Sep 2004, Brian Redman wrote:
What's the recommended way to guard against trying to access a message via msgno that's greater than nmsgs.

Keep track of all mm_exists() and mm_expunged() events. That will guarantee that at all times you know the number of messages in the mailbox. Never send msgno 0 or a number greater than the number of messages.


I currently check myStream->nmsgs but occasionally when I mail_fetchenvelope(myStream, msgno) I get the fatal error anyway.

You must be doing something wrong; because if you did that you would not have the problem. Between the time you checked myStream->nmsgs and called mail_fetchenvelope() you must have gotten a mm_expunged() event. mm_expunged() events happen only at well-defined points.


Are you sure that you aren't doing something like:
        if (msgno <= myStream->nmsgs) {
                . . .
          mail_ping (myStream);
                . . .
          env = mail_fetchenvelope (myStream,msgno);

the point being that you called some other mail_xxxxxx() function between your test and calling mail_fetchenvelope().

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.
Si vis pacem, para bellum.

Reply via email to