--- lmtp.c 2001/09/04 09:46:06 1.21
+++ lmtp.c 2001/09/07 15:02:08 1.22
@@ -70,6 +70,21 @@
int wfd; /* file descriptor for writing */
};
+static int lmtp_select(void *ctx, int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
+{
+ return select(nfds, rfds, wfds, efds, tv);
+}
+
+static ssize_t lmtp_read(void *ctx, int fd, void *buf, size_t buflen)
+{
+ return read(fd, buf, buflen);
+}
+
+static ssize_t lmtp_write(void *ctx, int fd, const void *buf, size_t buflen)
+{
+ return write(fd, buf, buflen);
+}
+
static int verbindex(lmtp_t *lmtp, char *verb)
{
/* returns the index of the verb or -1 if verb not registered */
@@ -110,13 +125,15 @@
return NULL;
if (io == NULL) {
- lmtp->io.select = select;
- lmtp->io.read = read;
- lmtp->io.write = write;
+ lmtp->io.ctx = NULL;
+ lmtp->io.select = lmtp_select;
+ lmtp->io.read = lmtp_read;
+ lmtp->io.write = lmtp_write;
} else {
- lmtp->io.select = io->select ? io->select : select;
- lmtp->io.read = io->read ? io->read : read;
- lmtp->io.write = io->write ? io->write : write;
+ lmtp->io.ctx = io->ctx;
+ lmtp->io.select = io->select ? io->select : lmtp_select;
+ lmtp->io.read = io->read ? io->read : lmtp_read;
+ lmtp->io.write = io->write ? io->write : lmtp_write;
}
lmtp->rl.rl_cnt = 0;
@@ -164,7 +181,7 @@
/* fetch one character (but read more) */
if (rl->rl_cnt <= 0) {
do {
- rl->rl_cnt = lmtp->io.read(lmtp->rfd, rl->rl_buf, LMTP_LINE_MAXLEN);
+ rl->rl_cnt = lmtp->io.read(lmtp->io.ctx, lmtp->rfd, rl->rl_buf, LMTP_LINE_MAXLEN);
} while (rl->rl_cnt == -1 && errno == EINTR);
if (rl->rl_cnt == -1)
return LMTP_ERR_SYSTEM;
@@ -353,7 +370,7 @@
formatbuf[len++] = '\r';
formatbuf[len++] = '\n';
do {
- rv = lmtp->io.write(lmtp->wfd, formatbuf, len);
+ rv = lmtp->io.write(lmtp->io.ctx, lmtp->wfd, formatbuf, len);
} while (rv == -1 && errno == EINTR);
if (rv == -1)
return LMTP_ERR_SYSTEM;
|