Commit bafd19a4 authored by Per Cederqvist's avatar Per Cederqvist

Import of libisc 0.99.

parent b357b6d2
Topdir.make
Makefile
Makefile.in
aclocal.m4
config.cache
config.log
config.status
configure
isc-*
This package implements a library of functions that is intendend
to help creating client-server packages using TCP/IP or other
file descriptor based links.
This package implements a library of functions that was intendend to
help creating client-server packages using TCP/IP or other file
descriptor based links. Use of this package for development of new
software is not recommended.
Have a look at EXAMPLE.c for a example of how it can be used.
/Peter Eriksson (pen@lysator.liu.se)
Much of the documentation is probably outdated. Be sure to read the
file NEWS, and trust it more than the man pages. Trust doc/MANUAL.sv
even less than the man pages.
This code is distributed under the GNU General Public License, except
for src/printf.c. See that file for all the details. src/printf.c is
not used unless the deprecated --enable-isc-printf switch is used.
This is an interim release, that will be used as a baseline for tests
with incorporating this library in other code such as the LysKOM
server. You should expect isc-1.0 to be released within a few
man-days. (What that translates to in calendar days is totally
unknown.)
/Peter Eriksson <pen@lysator.liu.se> and
Per Cederqvist <ceder@lysator.liu.se>
* Use an autoconf check for the buggy inet_ntoa (search for __GNU__ in
src/isc_socket.c to see what I'm talking about).
* Get rid of isc/printf.c. Who uses it anyway? Ah, the lyskomd
server... What a pity.
* Anvnd ett IscMessage som sendbuffert
* Kolla upp s att inte tecken i sendbuf[] snds frn isc_flush() verkligen
......
INCDIRS=-I$(HOME)/include
LIBDIRS=-L$(HOME)/lib
SOURCES=tcp.c udp.c
CFLAGS= -g $(LIBDIRS) $(INCDIRS)
CC=gcc
# Makefile.in generated automatically by automake 1.3 from Makefile.am
tcp: tcp.c $(HOME)/include/isc.h $(HOME)/lib/libisc.a
gcc $(CFLAGS) -o tcp tcp.c -lisc -lansi
# Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
udp: udp.c $(HOME)/include/isc.h $(HOME)/lib/libisc.a
gcc $(CFLAGS) -o udp udp.c -lisc -lansi
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
clean:
rm -f *~ *.o a.out core tcp udp \#*\#
depend:
gmkdep $(INCDIRS) $(SOURCES)
SHELL = /bin/sh
# DO NOT DELETE THIS LINE -- mkdep uses it.
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
sbindir = @sbindir@
libexecdir = @libexecdir@
datadir = @datadir@
sysconfdir = @sysconfdir@
sharedstatedir = @sharedstatedir@
localstatedir = @localstatedir@
libdir = @libdir@
infodir = @infodir@
mandir = @mandir@
includedir = @includedir@
oldincludedir = /usr/include
DISTDIR =
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
ACLOCAL = @ACLOCAL@
AUTOCONF = @AUTOCONF@
AUTOMAKE = @AUTOMAKE@
AUTOHEADER = @AUTOHEADER@
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
transform = @program_transform_name@
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
CC = @CC@
CPP = @CPP@
LIBOBJS = @LIBOBJS@
MAKEINFO = @MAKEINFO@
PACKAGE = @PACKAGE@
RANLIB = @RANLIB@
U = @U@
VERSION = @VERSION@
EXTRA_DIST = mux.c mux.h tcp.c udp.c
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
DIST_COMMON = README Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
TAR = tar
GZIP = --best
all: Makefile
.SUFFIXES:
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps demo/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
tags: TAGS
TAGS:
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
subdir = demo
distdir: $(DISTFILES)
@for file in $(DISTFILES); do \
d=$(srcdir); \
test -f $(distdir)/$$file \
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file; \
done
info:
dvi:
check: all
$(MAKE)
installcheck:
install-exec:
@$(NORMAL_INSTALL)
install-data:
@$(NORMAL_INSTALL)
install: install-exec install-data all
@:
uninstall:
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' INSTALL_SCRIPT='$(INSTALL_PROGRAM)' install
installdirs:
mostlyclean-generic:
-test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES)
clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-rm -f Makefile $(DISTCLEANFILES)
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
-test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES)
-test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES)
mostlyclean: mostlyclean-generic
clean: clean-generic mostlyclean
distclean: distclean-generic clean
-rm -f config.status
maintainer-clean: maintainer-clean-generic distclean
@echo "This command is intended for maintainers to use;"
@echo "it deletes files that may require special tools to rebuild."
.PHONY: tags distdir info dvi installcheck install-exec install-data \
install uninstall all installdirs mostlyclean-generic distclean-generic \
clean-generic maintainer-clean-generic clean mostlyclean distclean \
maintainer-clean
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
......@@ -13,12 +13,6 @@
#ifndef __ISC_H__
#define __ISC_H__
#include <time.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
/*
** Give the poor user a chance to change it
......@@ -149,6 +143,7 @@ typedef enum
ISC_STATE_RUNNING,
ISC_STATE_DISABLED,
ISC_STATE_CLOSING,
ISC_STATE_CLOSING2, /* An ISC_EVENT_LOGOUT has been generated. */
ISC_STATE_LISTENING
} IscSessionState;
......@@ -268,7 +263,7 @@ IscSession
IscSessionState state;
int fd;
int mode;
int errno;
int isc_errno;
IscMsgQueue * rd_msg_q;
IscMsgQueue * wr_msg_q;
......@@ -365,6 +360,7 @@ IscEvent
IscEventType event;
IscSession * session;
IscMessage * msg;
IscSession * listen_session;
};
......@@ -463,6 +459,12 @@ isc_getnextevent(IscMaster * mcb,
/*
** Wait for pending connections.
*/
IscEvent *
isc_wait(IscMaster *mcb, long timeout);
/*
** This should be used to discard an event when it has been processed.
*/
......@@ -511,6 +513,11 @@ isc_putc(int chr,
#ifdef ISC_PRINTF_SUPPORT
# ifndef HAVE_STDARG_H
# error isc_printf is not available on systems that lack stdarg.h.
# else
/*
** Put a formatted string on the transmit queue
*/
......@@ -524,6 +531,8 @@ isc_vprintf(IscSession * scb,
const char * format,
va_list AP);
# endif
#endif
/*
......
......@@ -9,20 +9,23 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <time.h>
#include "isc.h"
#include "intern.h"
/*
** External function declarations
*/
extern int fprintf(FILE *, char *, ...);
#if defined(__sun__) && !defined(__stdlib_h)
extern void abort(void);
#endif
static void (*isc_abortfn)(const char *msg) = (void (*)(const char *))NULL;
static void (*isc_abortfn)(const char *msg) = NULL;
void
......
......@@ -8,9 +8,26 @@
** 910305 pen moved into separate file
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#ifndef NULL
# include <stdio.h>
#endif
#include "isc.h"
#include "intern.h"
......@@ -21,27 +38,12 @@
#define ISC_MAGIC_FREE 0xEE47A37F
/*
** External declarations
*/
#if defined(__sun__) && !defined(__stdlib_h)
extern void *malloc(size_t);
extern void *calloc(int, size_t);
extern void *realloc(void *, size_t);
extern void free(void *);
#endif
/*
** Pointers to functions to handle storage allocation
*/
static void * (*isc_mallocfn)(size_t size) =
(void * (*)(size_t)) NULL;
static void * (*isc_reallocfn)(void *bufp, size_t size) =
(void * (*)(void *, size_t)) NULL;
static void (*isc_freefn)(void *bufp) =
(void (*)(void *)) NULL;
static void * (*isc_mallocfn)(size_t size) = NULL;
static void * (*isc_reallocfn)(void *bufp, size_t size) = NULL;
static void (*isc_freefn)(void *bufp) = NULL;
/*
......@@ -62,14 +64,14 @@ isc_setallocfn(void * (*mallocfn)(size_t size),
void *
isc_malloc(size_t size)
{
unsigned int * buf;
unsigned long * buf;
if (isc_mallocfn)
buf = (unsigned int *) (*isc_mallocfn)(size + sizeof(unsigned int));
buf = (unsigned long *) (*isc_mallocfn)(size + sizeof(unsigned long));
else
{
buf = (unsigned int *) malloc(size + sizeof(unsigned int));
buf = (unsigned long *) malloc(size + sizeof(unsigned long));
if (!buf)
isc_abort("isc_malloc");
}
......@@ -83,33 +85,24 @@ isc_malloc(size_t size)
void *
isc_realloc(void *oldbuf, size_t size)
{
unsigned int *buf;
unsigned long *buf;
if (!oldbuf)
return isc_malloc(size);
buf = (unsigned int *) oldbuf;
switch (*--buf)
{
case ISC_MAGIC_ALLOC:
break;
case ISC_MAGIC_FREE:
isc_abort("isc_realloc");
default:
isc_abort("isc_realloc");
}
buf = (unsigned long *) oldbuf;
if (*--buf != ISC_MAGIC_ALLOC)
isc_abort("isc_realloc");
*buf = ISC_MAGIC_FREE;
if (isc_reallocfn)
buf = (unsigned int *) (*isc_reallocfn)((void *) buf,
size + sizeof(unsigned int));
buf = (unsigned long *) (*isc_reallocfn)((void *) buf,
size + sizeof(unsigned long));
else
{
buf = (void *) realloc((void *) buf, size + sizeof(unsigned int));
buf = (void *) realloc((void *) buf, size + sizeof(unsigned long));
if (!buf)
isc_abort("isc_realloc");
}
......@@ -123,24 +116,15 @@ isc_realloc(void *oldbuf, size_t size)
void
isc_free(void *buf)
{
unsigned int *ibuf;
unsigned long *ibuf;
if (!buf)
isc_abort("isc_free");
ibuf = (unsigned int *) buf;
switch (*--ibuf)
{
case ISC_MAGIC_ALLOC:
break;
case ISC_MAGIC_FREE:
isc_abort("isc_free");
default:
isc_abort("isc_free");
}
ibuf = (unsigned long *) buf;
if (*--ibuf != ISC_MAGIC_ALLOC)
isc_abort("isc_free");
*ibuf = ISC_MAGIC_FREE;
......
......@@ -15,31 +15,34 @@
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#ifdef TIME_WITH_SYS_TIME
# include <time.h>
#endif
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h> /* Needed on NetBSD1.1/SPARC due to select */
#endif
#ifdef HAVE_STRING_H
# include <string.h> /* Needed on NetBSD1.1/SPARC due to bzero */
#endif
#include "isc.h"
#include "intern.h"
/*
* External function declarations.
*/
extern void *bzero(void *buf, unsigned length);
extern time_t time(time_t *buf);
extern int select(int setsize,
fd_set *rs, fd_set *rw, fd_set *es,
struct timeval *wait);
IscEvent *
isc_getnextevent(IscMaster *mcb, long timeout)
{
......@@ -62,6 +65,7 @@ isc_getnextevent(IscMaster *mcb, long timeout)
ISC_XNEW(event);
event->msg = NULL;
event->session = NULL;
event->listen_session = NULL;
RETRY:
/* Set up the list of file descriptors to wait on */
......@@ -101,12 +105,15 @@ RETRY:
if (scb->fd == -1 || !isc_pollqueue(scb->wr_msg_q))
{
event->event = ISC_EVENT_LOGOUT;
scb->state = ISC_STATE_CLOSING2;
/* Move the session pointer to the next in the circular queue */
mcb->sessions = mcb->sessions->next;
return event;
}
else
event->session = NULL;
}
/*
......@@ -191,7 +198,7 @@ RETRY:
* Connect request failed
*/
scb->state = ISC_STATE_CLOSING;
scb->errno = errno;
scb->isc_errno = errno;
event->event = ISC_EVENT_REJECTED;
event->session = scb;
}
......@@ -259,7 +266,7 @@ RETRY:
else
{
scb->state = ISC_STATE_CLOSING;
scb->errno = errno;
scb->isc_errno = errno;
}
}
......@@ -290,6 +297,7 @@ RETRY:
/* Fill in the event info structure */
event->session = new_scb;
event->event = ISC_EVENT_LOGIN;
event->listen_session = scb;
/* Move the session pointer to the next in the circular queue */
mcb->sessions = mcb->sessions->next;
......@@ -323,7 +331,7 @@ RETRY:
break;
}
goto RETRY; /* This happens if/when only transmits where pending.. */
goto RETRY; /* This happens if/when only transmits were pending... */
}
......
......@@ -9,6 +9,12 @@
*/
#include <stdio.h>
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <time.h>
#include "isc.h"
#include "intern.h"
......
......@@ -9,9 +9,22 @@
*/
#include <errno.h>
#include <stdlib.h>
#include <stddef.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#include <sys/types.h>
#include <sys/file.h>
#include <sys/socket.h>
#ifndef NULL
# include <stdio.h>
#endif
#include "isc.h"
#include "intern.h"
......
......@@ -9,14 +9,25 @@
** 920102 pen added isc_copymsg()
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifndef NULL
# include <stdio.h>
#endif
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "isc.h"
#include "intern.h"
extern void *memcpy(void *, const void *, int);
IscMessage *
isc_allocmsg(size_t size)
......
......@@ -9,28 +9,35 @@
** 910310 pen added isc_send()
*/
#include <stdlib.h>
#include <stddef.h>
#ifdef HAVE_STDDEF_H
# include <stddef.h>
#endif
#ifdef HAVE_STDARG_H
# include <stdarg.h>
#endif
#include <errno.h>
#include <string.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#include <sys/file.h>
#include <errno.h>
#ifndef NULL
# include <stdio.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include "isc.h"
#include "intern.h"
/*
* External function declarations
*/
extern void *memcpy(void *, const void *, int);
extern char *strerror(int);
void isc_flush(IscSession *scb)
{
switch (scb->state)
{
case ISC_STATE_CLOSING:
case ISC_STATE_CLOSING2:
if (scb->wr_msg_q)
{
isc_killqueue(scb->wr_msg_q);
......@@ -71,7 +78,7 @@ void isc_oflush(IscSession *scb)
if (isc_sizequeue(scb->wr_msg_q) >= scb->cfg->max.queuedsize)
{
scb->state = ISC_STATE_CLOSING;
scb->errno = E2BIG;
scb->isc_errno = E2BIG;
scb->sendindex = 0; /* And lets fake a write */
return;
}
......@@ -85,7 +92,8 @@ void isc_oflush(IscSession *scb)
/* We only try to transmit messages for RUNNING or CLOSING sessions */
if ((scb->state != ISC_STATE_RUNNING &&
scb->state != ISC_STATE_CLOSING) || scb->fd == -1)
scb->state != ISC_STATE_CLOSING &&
scb->state != ISC_STATE_CLOSING2) || scb->fd == -1)
return;
/* Queued entries? Send as much as possible */
......@@ -106,12 +114,12 @@ void isc_oflush(IscSession *scb)
case EPIPE:
scb->state = ISC_STATE_CLOSING;
scb->errno = errno;
scb->isc_errno = errno;
return;
default:
scb->state = ISC_STATE_CLOSING;
scb->errno = errno;
scb->isc_errno = errno;