[_WIN32] (readv, writev, iovec): New. POSIX equivalents.

(ioq_makeiov, ioqtoiov): Compile unconditionally.
(io_output): Use POSIX code unconditionally.
[_WIN32] (ioq_makebuf): Remove.
This commit is contained in:
Ron Koenderink 2007-08-16 21:43:20 +00:00
parent a9c872f006
commit af64cfd491
5 changed files with 135 additions and 70 deletions

View file

@ -45,8 +45,8 @@
#include <fcntl.h>
#include <stdlib.h>
#include <sys/types.h>
#if !defined(_WIN32)
#include <sys/uio.h>
#if !defined(_WIN32)
#include <sys/file.h>
#endif
#include <sys/socket.h>
@ -166,11 +166,7 @@ io_outputwaiting(struct iop *iop)
int
io_output(struct iop *iop, int waitforoutput)
{
#if !defined(_WIN32)
struct iovec iov[16];
#else
char buf[IO_BUFSIZE];
#endif
int cc;
int n;
int remain;
@ -187,15 +183,10 @@ io_output(struct iop *iop, int waitforoutput)
if (iop->flags & IO_ERROR)
return -1;
#if !defined(_WIN32)
/* make the iov point to the data in the queue. */
/* I.E., each of the elements in the queue. */
/* returns the number of elements in the iov. */
n = ioq_makeiov(iop->output, iov, IO_BUFSIZE);
#else
/* Make a buffer containing the output to write. */
n = ioq_makebuf(iop->output, buf, sizeof(buf));
#endif
if (n <= 0) {
return 0;
@ -209,11 +200,7 @@ io_output(struct iop *iop, int waitforoutput)
}
/* Do the actual write. */
#if !defined(_WIN32)
cc = writev(iop->fd, iov, n);
#else
cc = write(iop->fd, buf, n);
#endif
/* if it failed.... */
if (cc < 0) {

View file

@ -42,17 +42,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if !defined(_WIN32)
#include <sys/uio.h>
#endif
#include "ioqueue.h"
#include "misc.h"
#include "queue.h"
static int ioqtocbuf(struct ioqueue *ioq, char *buf, int cc, int stopc);
#if !defined(_WIN32)
static int ioqtoiov(struct ioqueue *ioq, struct iovec *iov, int max);
#endif
static int ioqtobuf(struct ioqueue *ioq, char *buf, int cc);
static int appendcc(struct ioqueue *ioq, char *buf, int cc);
static int removecc(struct ioqueue *ioq, int cc);
@ -101,7 +97,6 @@ ioq_drain(struct ioqueue *ioq)
* iovec, but don't actually dequeue the data.
* return # of iovec initialized.
*/
#if !defined(_WIN32)
int
ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc)
{
@ -109,7 +104,6 @@ ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc)
return 0;
return ioqtoiov(ioq, iov, cc);
}
#endif
/*
* Copy the specified number of characters into the buffer
@ -247,7 +241,6 @@ ioqtocbuf(struct ioqueue *ioq, char *buf, int cc, int stopc)
* initialize an iovec to point at max bytes worth
* of data from the ioqueue.
*/
#if !defined(_WIN32)
static int
ioqtoiov(struct ioqueue *ioq, struct iovec *iov, int max)
{
@ -274,7 +267,6 @@ ioqtoiov(struct ioqueue *ioq, struct iovec *iov, int max)
}
return niov;
}
#endif
/*
* append a buffer to the end of the ioq.
@ -356,47 +348,3 @@ removecc(struct ioqueue *ioq, int cc)
ioq->cc -= nbytes;
return nbytes;
}
#if defined(_WIN32)
/*
* Make an (output) buffer up to the
* maximum size of the buffer.
*
* We don't free the bytes...
*/
int
ioq_makebuf(struct ioqueue *ioq, char *pBuf, int nBufLen)
{
struct io *io;
struct emp_qelem *qp;
struct emp_qelem *head;
int nbytes;
int nleft;
int ncopied;
char *offset;
ncopied = 0;
nleft = nBufLen;
offset = pBuf;
head = &ioq->list.queue;
for (qp = head->q_forw; (qp != head) && (nleft > 0); qp = qp->q_forw) {
io = (struct io *)qp;
nbytes = io->nbytes - io->offset;
if (nbytes < 0) {
/* Paranoid check for bad buffer. */
continue;
}
/* too many bytes, wait till next time. */
if (nbytes > nleft)
break;
memcpy(offset, io->data + io->offset, nbytes);
offset += nbytes;
nleft -= nbytes;
ncopied += nbytes;
}
return ncopied;
}
#endif /* _WIN32 */