Indented with src/scripts/indent-emp.
This commit is contained in:
parent
5f263a7753
commit
9b7adfbecc
437 changed files with 52211 additions and 51052 deletions
|
@ -42,9 +42,9 @@
|
|||
#include "ioqueue.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef struct iovec {
|
||||
char *iov_base;
|
||||
int iov_len;
|
||||
typedef struct iovec {
|
||||
char *iov_base;
|
||||
int iov_len;
|
||||
} iovec_t;
|
||||
#endif
|
||||
|
||||
|
@ -62,15 +62,15 @@ void free();
|
|||
|
||||
void
|
||||
ioq_init(ioq, bsize)
|
||||
struct ioqueue *ioq;
|
||||
int bsize;
|
||||
struct ioqueue *ioq;
|
||||
int bsize;
|
||||
{
|
||||
extern s_char num_teles[];
|
||||
extern s_char num_teles[];
|
||||
|
||||
initque(&ioq->queue);
|
||||
ioq->cc = 0;
|
||||
ioq->bsize = bsize;
|
||||
*num_teles = '\0';
|
||||
initque(&ioq->queue);
|
||||
ioq->cc = 0;
|
||||
ioq->bsize = bsize;
|
||||
*num_teles = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -80,13 +80,13 @@ ioq_init(ioq, bsize)
|
|||
*/
|
||||
int
|
||||
ioq_peekiov(ioq, iov, max)
|
||||
struct ioqueue *ioq;
|
||||
struct iovec *iov;
|
||||
int max;
|
||||
struct ioqueue *ioq;
|
||||
struct iovec *iov;
|
||||
int max;
|
||||
{
|
||||
if (ioq->cc <= 0)
|
||||
return 0;
|
||||
return ioqtoiov(ioq, iov, max);
|
||||
if (ioq->cc <= 0)
|
||||
return 0;
|
||||
return ioqtoiov(ioq, iov, max);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -96,91 +96,91 @@ ioq_peekiov(ioq, iov, max)
|
|||
*/
|
||||
int
|
||||
ioq_peek(ioq, buf, cc)
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
{
|
||||
return ioqtobuf(ioq, buf, cc);
|
||||
return ioqtobuf(ioq, buf, cc);
|
||||
}
|
||||
|
||||
int
|
||||
ioq_dequeue(ioq, cc)
|
||||
struct ioqueue *ioq;
|
||||
int cc;
|
||||
struct ioqueue *ioq;
|
||||
int cc;
|
||||
{
|
||||
if (dequeuecc(ioq, cc) != cc)
|
||||
return 0;
|
||||
return cc;
|
||||
if (dequeuecc(ioq, cc) != cc)
|
||||
return 0;
|
||||
return cc;
|
||||
}
|
||||
|
||||
int
|
||||
ioq_read(ioq, buf, cc)
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
{
|
||||
int n;
|
||||
int n;
|
||||
|
||||
n = ioqtobuf(ioq, buf, cc);
|
||||
if (n > 0)
|
||||
dequeuecc(ioq, n);
|
||||
return n;
|
||||
n = ioqtobuf(ioq, buf, cc);
|
||||
if (n > 0)
|
||||
dequeuecc(ioq, n);
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
ioq_write(ioq, buf, cc)
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
{
|
||||
enqueuecc(ioq, buf, cc);
|
||||
enqueuecc(ioq, buf, cc);
|
||||
}
|
||||
|
||||
int
|
||||
ioq_qsize(ioq)
|
||||
struct ioqueue *ioq;
|
||||
struct ioqueue *ioq;
|
||||
{
|
||||
return ioq->cc;
|
||||
return ioq->cc;
|
||||
}
|
||||
|
||||
void
|
||||
ioq_drain(ioq)
|
||||
struct ioqueue *ioq;
|
||||
struct ioqueue *ioq;
|
||||
{
|
||||
struct io *io;
|
||||
struct qelem *qp;
|
||||
struct io *io;
|
||||
struct qelem *qp;
|
||||
|
||||
while ((qp = ioq->queue.q_forw) != &ioq->queue) {
|
||||
io = (struct io *) qp;
|
||||
free(io->data);
|
||||
(void) remque(&io->queue);
|
||||
(void) free(io);
|
||||
}
|
||||
ioq->cc = 0;
|
||||
while ((qp = ioq->queue.q_forw) != &ioq->queue) {
|
||||
io = (struct io *)qp;
|
||||
free(io->data);
|
||||
(void)remque(&io->queue);
|
||||
(void)free(io);
|
||||
}
|
||||
ioq->cc = 0;
|
||||
}
|
||||
|
||||
s_char *
|
||||
ioq_gets(ioq, buf, cc)
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
{
|
||||
register s_char *p;
|
||||
register s_char *end;
|
||||
int nbytes;
|
||||
register s_char *p;
|
||||
register s_char *end;
|
||||
int nbytes;
|
||||
|
||||
nbytes = ioqtobuf(ioq, buf, cc);
|
||||
if (nbytes < cc)
|
||||
cc = nbytes;
|
||||
end = &buf[cc];
|
||||
for (p = buf; p < end && *p; p++) {
|
||||
if (*p == '\n') {
|
||||
*p = '\0';
|
||||
dequeuecc(ioq, (p - buf) + 1);
|
||||
return buf;
|
||||
}
|
||||
nbytes = ioqtobuf(ioq, buf, cc);
|
||||
if (nbytes < cc)
|
||||
cc = nbytes;
|
||||
end = &buf[cc];
|
||||
for (p = buf; p < end && *p; p++) {
|
||||
if (*p == '\n') {
|
||||
*p = '\0';
|
||||
dequeuecc(ioq, (p - buf) + 1);
|
||||
return buf;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -194,36 +194,36 @@ ioq_gets(ioq, buf, cc)
|
|||
* left for a higher level.
|
||||
*/
|
||||
static
|
||||
int
|
||||
int
|
||||
ioqtobuf(ioq, buf, cc)
|
||||
register struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
register struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
{
|
||||
register struct io *io;
|
||||
struct qelem *qp;
|
||||
s_char *offset;
|
||||
int nbytes;
|
||||
int nleft;
|
||||
register struct io *io;
|
||||
struct qelem *qp;
|
||||
s_char *offset;
|
||||
int nbytes;
|
||||
int nleft;
|
||||
|
||||
nleft = cc;
|
||||
offset = buf;
|
||||
for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) {
|
||||
io = (struct io *) qp;
|
||||
if ((nbytes = io->nbytes - io->offset) < 0) {
|
||||
fprintf(stderr, "ioqtobuf: offset %d nbytes %d\n",
|
||||
io->offset, io->nbytes);
|
||||
continue;
|
||||
}
|
||||
if (nbytes > 0) {
|
||||
if (nleft < nbytes)
|
||||
nbytes = nleft;
|
||||
bcopy(io->data + io->offset, offset, nbytes);
|
||||
offset += nbytes;
|
||||
nleft -= nbytes;
|
||||
}
|
||||
nleft = cc;
|
||||
offset = buf;
|
||||
for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) {
|
||||
io = (struct io *)qp;
|
||||
if ((nbytes = io->nbytes - io->offset) < 0) {
|
||||
fprintf(stderr, "ioqtobuf: offset %d nbytes %d\n",
|
||||
io->offset, io->nbytes);
|
||||
continue;
|
||||
}
|
||||
return offset - buf;
|
||||
if (nbytes > 0) {
|
||||
if (nleft < nbytes)
|
||||
nbytes = nleft;
|
||||
bcopy(io->data + io->offset, offset, nbytes);
|
||||
offset += nbytes;
|
||||
nleft -= nbytes;
|
||||
}
|
||||
}
|
||||
return offset - buf;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -235,31 +235,31 @@ ioqtobuf(ioq, buf, cc)
|
|||
* of a full ioqueue still be quick.
|
||||
*/
|
||||
static
|
||||
int
|
||||
int
|
||||
ioqtoiov(ioq, iov, max)
|
||||
register struct ioqueue *ioq;
|
||||
register struct iovec *iov;
|
||||
register int max;
|
||||
register struct ioqueue *ioq;
|
||||
register struct iovec *iov;
|
||||
register int max;
|
||||
{
|
||||
register struct io *io;
|
||||
register int cc;
|
||||
register int niov;
|
||||
struct qelem *qp;
|
||||
register struct io *io;
|
||||
register int cc;
|
||||
register int niov;
|
||||
struct qelem *qp;
|
||||
|
||||
cc = 0;
|
||||
niov = 0;
|
||||
qp = ioq->queue.q_forw;
|
||||
for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) {
|
||||
io = (struct io *) qp;
|
||||
if (niov >= MAXIOV || cc >= max)
|
||||
break;
|
||||
iov->iov_base = io->data + io->offset;
|
||||
iov->iov_len = io->nbytes - io->offset;
|
||||
cc += io->nbytes - io->offset;
|
||||
niov++;
|
||||
iov++;
|
||||
}
|
||||
return niov;
|
||||
cc = 0;
|
||||
niov = 0;
|
||||
qp = ioq->queue.q_forw;
|
||||
for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) {
|
||||
io = (struct io *)qp;
|
||||
if (niov >= MAXIOV || cc >= max)
|
||||
break;
|
||||
iov->iov_base = io->data + io->offset;
|
||||
iov->iov_len = io->nbytes - io->offset;
|
||||
cc += io->nbytes - io->offset;
|
||||
niov++;
|
||||
iov++;
|
||||
}
|
||||
return niov;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -267,18 +267,18 @@ ioqtoiov(ioq, iov, max)
|
|||
*/
|
||||
static void
|
||||
enqueuecc(ioq, buf, cc)
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
struct ioqueue *ioq;
|
||||
s_char *buf;
|
||||
int cc;
|
||||
{
|
||||
struct io *io;
|
||||
struct io *io;
|
||||
|
||||
io = (struct io *) malloc(sizeof(*io));
|
||||
io->nbytes = cc;
|
||||
io->offset = 0;
|
||||
io->data = buf;
|
||||
insque(&io->queue, ioq->queue.q_back);
|
||||
ioq->cc += cc;
|
||||
io = (struct io *)malloc(sizeof(*io));
|
||||
io->nbytes = cc;
|
||||
io->offset = 0;
|
||||
io->data = buf;
|
||||
insque(&io->queue, ioq->queue.q_back);
|
||||
ioq->cc += cc;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -287,36 +287,36 @@ enqueuecc(ioq, buf, cc)
|
|||
* which are no longer used.
|
||||
*/
|
||||
static
|
||||
int
|
||||
int
|
||||
dequeuecc(ioq, cc)
|
||||
register struct ioqueue *ioq;
|
||||
register int cc;
|
||||
register struct ioqueue *ioq;
|
||||
register int cc;
|
||||
{
|
||||
register struct io *io;
|
||||
register struct qelem *qp;
|
||||
register int nbytes;
|
||||
register int there;
|
||||
register struct io *io;
|
||||
register struct qelem *qp;
|
||||
register int nbytes;
|
||||
register int there;
|
||||
|
||||
nbytes = 0;
|
||||
while ((qp = ioq->queue.q_forw) != &ioq->queue) {
|
||||
io = (struct io *) qp;
|
||||
there = io->nbytes - io->offset;
|
||||
if (there < 0) {
|
||||
fprintf(stderr, "dequeuecc: nbytes %d, offset %d\n",
|
||||
io->nbytes, io->offset);
|
||||
continue;
|
||||
}
|
||||
if (cc > there) {
|
||||
cc -= there;
|
||||
nbytes += there;
|
||||
(void) remque(&io->queue);
|
||||
free(io->data);
|
||||
} else {
|
||||
io->offset += cc;
|
||||
nbytes += cc;
|
||||
break;
|
||||
}
|
||||
nbytes = 0;
|
||||
while ((qp = ioq->queue.q_forw) != &ioq->queue) {
|
||||
io = (struct io *)qp;
|
||||
there = io->nbytes - io->offset;
|
||||
if (there < 0) {
|
||||
fprintf(stderr, "dequeuecc: nbytes %d, offset %d\n",
|
||||
io->nbytes, io->offset);
|
||||
continue;
|
||||
}
|
||||
ioq->cc -= nbytes;
|
||||
return nbytes;
|
||||
if (cc > there) {
|
||||
cc -= there;
|
||||
nbytes += there;
|
||||
(void)remque(&io->queue);
|
||||
free(io->data);
|
||||
} else {
|
||||
io->offset += cc;
|
||||
nbytes += cc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ioq->cc -= nbytes;
|
||||
return nbytes;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue