From b22117b182e372c6d1adc77c7da6a1de508e8594 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Fri, 6 Oct 1995 08:51:13 +0000 Subject: [PATCH] Added Write-buffer. --- Makefile | 10 ++++---- include/wrbuf.h | 48 +++++++++++++++++++++++++++++++++++++ server/seshigh.c | 9 +++---- util/Makefile | 4 ++-- util/wrbuf.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 include/wrbuf.h create mode 100644 util/wrbuf.c diff --git a/Makefile b/Makefile index ef18971..2c92740 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.24 1995-09-29 17:01:34 quinn Exp $ +# $Id: Makefile,v 1.25 1995-10-06 08:51:13 quinn Exp $ # Uncomment the lines below to enable mOSI communcation. -#ODEFS=-DUSE_XTIMOSI -#RFC1006=rfc1006 -#LIBMOSI=../../xtimosi/src/libmosi.a ../lib/librfc.a -#XMOSI=xmosi.o +ODEFS=-DUSE_XTIMOSI +RFC1006=rfc1006 +LIBMOSI=../../xtimosi/src/libmosi.a ../lib/librfc.a +XMOSI=xmosi.o CDEFS=$(ODEFS) #CC= diff --git a/include/wrbuf.h b/include/wrbuf.h new file mode 100644 index 0000000..a8bcceb --- /dev/null +++ b/include/wrbuf.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 1995, Index Data. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation, in whole or in part, for any purpose, is hereby granted, + * provided that: + * + * 1. This copyright and permission notice appear in all copies of the + * software and its documentation. Notices of copyright or attribution + * which appear at the beginning of any file must remain unchanged. + * + * 2. The names of Index Data or the individual authors may not be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND, + * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL, + * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR + * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + * + */ + +#ifndef WRBUF_H +#define WRBUF_H + +typedef struct wrbuf +{ + char *buf; + int pos; + int size; +} wrbuf, *WRBUF; + +WRBUF wrbuf_alloc(void); +void wrbuf_free(WRBUF b, int free_buf); +void wrbuf_rewind(WRBUF b); +int wrbuf_grow(WRBUF b, int minsize); +int wrbuf_write(WRBUF b, char *buf, int size); + +#define wrbuf_putc(b, c) \ + (((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \ + (b)->buf[(b)->pos++] = (c), 0) + +#endif diff --git a/server/seshigh.c b/server/seshigh.c index a3e3807..7e88771 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: seshigh.c,v $ - * Revision 1.47 1995-08-29 14:24:16 quinn + * Revision 1.48 1995-10-06 08:51:20 quinn + * Added Write-buffer. + * + * Revision 1.47 1995/08/29 14:24:16 quinn * Added second half of close-handshake * * Revision 1.46 1995/08/29 11:17:58 quinn @@ -20,8 +23,6 @@ * Updated External * * Revision 1.42 1995/08/15 11:16:50 quinn - * CV:e ---------------------------------------------------------------------- - * CV:e ---------------------------------------------------------------------- * * Revision 1.41 1995/08/02 10:23:06 quinn * Smallish @@ -584,7 +585,7 @@ static int process_response(association *assoc, request *req, Z_APDU *res) /* * Handle init request. - * At the moment, we don't check the protocol version or the options + * At the moment, we don't check the options * anywhere else in the code - we just try not to do anything that would * break a naive client. We'll toss 'em into the association block when * we need them there. diff --git a/util/Makefile b/util/Makefile index 6ed2b85..bd077ed 100644 --- a/util/Makefile +++ b/util/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.13 1995-06-25 10:53:59 quinn Exp $ +# $Id: Makefile,v 1.14 1995-10-06 08:51:24 quinn Exp $ SHELL=/bin/sh INCLUDE=-I../include -I. @@ -11,7 +11,7 @@ LIBINCLUDE=-L$(LIBDIR) DEFS=$(INCLUDE) LIB=$(LIBDIR)/libutil.a LIBS= -PO = options.o log.o marcdisp.o yaz-ccl.o pquery.o oid.o # dmalloc.o +PO = options.o log.o marcdisp.o yaz-ccl.o pquery.o oid.o wrbuf.o # dmalloc.o CPP=$(CC) -E RANLIB=ranlib diff --git a/util/wrbuf.c b/util/wrbuf.c new file mode 100644 index 0000000..446b6d5 --- /dev/null +++ b/util/wrbuf.c @@ -0,0 +1,69 @@ +/* + * Copyright (c) 1995, Index Data. + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: wrbuf.c,v $ + * Revision 1.1 1995-10-06 08:51:25 quinn + * Added Write-buffer. + * + * + */ + +/* + * Growing buffer for writing various stuff. + */ + +#include + +#include + +WRBUF wrbuf_alloc(void) +{ + WRBUF n; + + if (!(n = malloc(sizeof(*n)))) + abort(); + n->buf = 0; + n->size = 0; + n->pos = 0; + return n; +} + +void wrbuf_free(WRBUF b, int free_buf) +{ + if (free_buf && b->buf) + free(b->buf); + free(b); +} + +void wrbuf_rewind(WRBUF b) +{ + b->pos = 0; +} + +int wrbuf_grow(WRBUF b, int minsize) +{ + int togrow; + + if (!b->size) + togrow = 1024; + else + togrow = b->size; + if (togrow < minsize) + togrow = minsize; + if (b->size && !(b->buf = realloc(b->buf, b->size += togrow))) + abort(); + else if (!b->size && !(b->buf = malloc(b->size = togrow))) + abort(); + return 0; +} + +int wrbuf_write(WRBUF b, char *buf, int size) +{ + if (b->pos + size >= b->size) + wrbuf_grow(b, size); + memcpy(b->buf + b->pos, buf, size); + b->pos += size; + return 0; +} -- 1.7.10.4