OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/nntp.c versions 1.25 and 1.26
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/nntp.c 1.25 -> 1.26

--- nntp.c       2001/09/11 13:38:07     1.25
+++ nntp.c       2001/10/09 12:08:59     1.26
@@ -63,66 +63,44 @@
 } nntp_readline_t;
 
 struct nntp_st {
-    int             rfd;
-    int             wfd;
     nntp_io_t       io;
     nntp_readline_t rl; 
     struct timeval  tv;
     int             kludgeinn441dup;
 };
 
-static int nntp_select(void *ctx, int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
+ssize_t nntp_fd_read(void *_ctx, void *buf, size_t buflen)
 {
-    return select(nfds, rfds, wfds, efds, tv);
+    nntp_fd_t *ctx = (nntp_fd_t *)_ctx;
+    return read(ctx->fd, buf, buflen);
 }
 
-static ssize_t nntp_read(void *ctx, int fd, void *buf, size_t buflen)
+ssize_t nntp_fd_write(void *_ctx, const void *buf, size_t buflen)
 {
-    return read(fd, buf, buflen);
+    nntp_fd_t *ctx = (nntp_fd_t *)_ctx;
+    return write(ctx->fd, buf, buflen);
 }
 
-static ssize_t nntp_write(void *ctx, int fd, const void *buf, size_t buflen)
-{
-    return write(fd, buf, buflen);
-}
-
-nntp_t *nntp_create(int rfd, int wfd, nntp_io_t *io)
+nntp_t *nntp_create(nntp_io_t *io)
 {
     nntp_t *nntp;
 
     if ((nntp = (nntp_t *)malloc(sizeof(nntp_t))) == NULL) 
         return NULL;
 
-    if (io == NULL) {
-        nntp->io.ctx    = NULL;
-        nntp->io.select = nntp_select;
-        nntp->io.read   = nntp_read;
-        nntp->io.write  = nntp_write;
-    } else {
-        nntp->io.ctx    = io->ctx;
-        nntp->io.select = io->select ? io->select : nntp_select;
-        nntp->io.read   = io->read   ? io->read   : nntp_read;
-        nntp->io.write  = io->write  ? io->write  : nntp_write;
-    }
-
-    nntp->rfd = rfd;
-    nntp->wfd = wfd;
+    if (io == NULL) 
+        return NULL;
+    nntp->io.ctx    = io->ctx;
+    nntp->io.read   = io->read;
+    nntp->io.write  = io->write;
     nntp->rl.rl_cnt = 0;
     nntp->rl.rl_bufptr = NULL;
     nntp->rl.rl_buf[0] = NUL;
-    nntp_timeout(nntp, 3);
     nntp->kludgeinn441dup = FALSE;
 
     return nntp;
 }
 
-nntp_rc_t nntp_timeout(nntp_t *nntp, long timeout)
-{
-    nntp->tv.tv_sec = timeout;
-    nntp->tv.tv_usec = 0;
-    return NNTP_OK;
-}
-
 nntp_rc_t nntp_init(nntp_t *nntp)
 {
     nntp_rc_t rc;
@@ -182,9 +160,6 @@
     size_t n;
     char c;
     nntp_readline_t *rl = &nntp->rl;
-    struct timeval tv;
-    fd_set fds;
-    int rc;
 
     if (nntp == NULL)
         return NNTP_ERR_ARG;
@@ -192,17 +167,8 @@
 
         /* fetch one character (but read more) */
         if (rl->rl_cnt <= 0) {
-            FD_ZERO(&fds);
-            FD_SET(nntp->rfd, &fds);
-            tv.tv_sec  = nntp->tv.tv_sec;
-            tv.tv_usec = nntp->tv.tv_usec;
-            rc = nntp->io.select(nntp->io.ctx, nntp->rfd + 1, &fds, NULL, NULL, &tv);
-            if (rc == 0)
-                return NNTP_TIMEOUT;
-            else if (rc == -1)
-                return NNTP_ERR_SYSTEM;
             do {
-                rl->rl_cnt = nntp->io.read(nntp->io.ctx, nntp->rfd, rl->rl_buf, NNTP_LINE_MAXLEN);
+                rl->rl_cnt = nntp->io.read(nntp->io.ctx, rl->rl_buf, NNTP_LINE_MAXLEN);
             } while (rl->rl_cnt == -1 && errno == EINTR);
             if (rl->rl_cnt == -1)
                 return NNTP_ERR_SYSTEM;
@@ -235,7 +201,7 @@
         return NNTP_ERR_ARG;
     strncpy(tmp, buf, NNTP_LINE_MAXLEN-3);
     strcat(tmp, "\r\n");
-    if (nntp->io.write(nntp->io.ctx, nntp->wfd, tmp, strlen(tmp)) < 0)
+    if (nntp->io.write(nntp->io.ctx, tmp, strlen(tmp)) < 0)
         return NNTP_ERR_SYSTEM;
     return NNTP_OK;
 }
@@ -350,7 +316,7 @@
         return NNTP_ERR_DELIVERY;
 
     do {
-        rc = nntp->io.write(nntp->io.ctx, nntp->wfd, msg->cpMsg, strlen(msg->cpMsg));
+        rc = nntp->io.write(nntp->io.ctx, msg->cpMsg, strlen(msg->cpMsg));
     } while (rc == -1 && errno == EINTR);
     if (rc == -1)
         return NNTP_ERR_SYSTEM;
@@ -417,7 +383,7 @@
         return NNTP_ERR_DELIVERY;
 
     do {
-        rc = nntp->io.write(nntp->io.ctx, nntp->wfd, msg->cpMsg, strlen(msg->cpMsg));
+        rc = nntp->io.write(nntp->io.ctx, msg->cpMsg, strlen(msg->cpMsg));
     } while (rc == -1 && errno == EINTR);
     if (rc == -1)
         return NNTP_ERR_SYSTEM;
@@ -440,7 +406,6 @@
                                       str = "NNTP: errorcode has no description";
     if      (rc == NNTP_OK          ) str = "NNTP: no error";
     else if (rc == NNTP_EOF         ) str = "NNTP: end of file";
-    else if (rc == NNTP_TIMEOUT     ) str = "NNTP: timeout";
     else if (rc == NNTP_DEFER       ) str = "NNTP: transmission deferred";
     else if (rc == NNTP_FAKE        ) str = "NNTP: fake status not real";
     else if (rc == NNTP_ERR_SYSTEM  ) str = "NNTP: see errno";

CVSTrac 2.0.1