#include <libmail/mail.H>
class myCallback : public mail::callback {
public:
void success(std::string msg);
void fail(std::string msg);
};
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
mail::account::function( parameter list,
myCallback &callback)
for (;;)
{
int fd_max;
fd_set r, w;
struct timeval tv;
FD_ZERO(&r);
FD_ZERO(&w);
tv=timeout;
if (myCallback.completed())
break;
if (select(fd_max, &r, &w, NULL, &tv) < 0)
{
error();
}
}
This function processes all pending events for all opened mail accounts. Most mail requests are not immediately processed (some are, but most aren't). A mail request usually includes a mail::callback-derived object as one of its arguments. When the mail request completes the success or fail method (some mail::callback subclasses use additional or alternative methods) is invoked. If the mail request cannot be completed immediately, mail::account::function still returns right away. mail::account::process handles any pending events for all outstanding mail requests. The success or fail method will be invoked for all completed requests.
r, w, and tv are designed to be used directly as the corresponding arguments to the select(2) system call, and must be initialized by the application before invoking mail::account::process. tv should be initialized to indicate the time until the application's next expected event. If mail::account::process expects an event to occur earlier, the timeout in tv is reset appropriately. tv is never increased by mail::account::process, only decreased. If the application does not have an expected timeout before next event, tv must be initialized to a reasonably-long interval, such as one hour.
mail::account::process sets the appropriate bits in r and w for all file descriptors that have I/O pending, and returns the number of the highest file descriptor plus one. The timeout interval specified tv is reduced accordingly.
NOTE: | Not every file descriptor opened by libmail may have pending I/O, so the return code cannot be used to determine the highest opened file descirptor. |
The application should not invoke mail::account::process again until select(2) is invoked to wait for pending I/O, or until the application makes another mail request. The application may add additional file descriptors to r and w, adjusting the highest file descriptor number accordingly.
<<< Previous | Home | Next >>> |
mail::account::open | Up | mail::account::readMessageAttributes |