diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/include/endian.h | 60 | ||||
-rw-r--r-- | src/md5.c | 6 | ||||
-rw-r--r-- | src/proxyfunc.c | 31 |
4 files changed, 95 insertions, 4 deletions
@@ -23,7 +23,7 @@ PREFIX:= /usr/local BINDIR := $(DESTDIR)$(PREFIX)/sbin # For compilation dependencies -MODS := astmanproxy config config_perms common proxyfunc log +MODS := astmanproxy config config_perms common proxyfunc log ssl md5 HANDLERS := xml standard csv http SOBJS := $(HANDLERS:%=%.so) diff --git a/src/include/endian.h b/src/include/endian.h new file mode 100644 index 0000000..f5e20fb --- /dev/null +++ b/src/include/endian.h @@ -0,0 +1,60 @@ +/* + * Asterisk -- A telephony toolkit for Linux. + * + * Asterisk architecture endianess compatibility definitions + * + * Copyright (C) 1999 - 2005, Digium, Inc. + * + * Mark Spencer <markster@digium.com> + * + * This program is free software, distributed under the terms of + * the GNU Lesser General Public License. Other components of + * Asterisk are distributed under The GNU General Public License + * only. + */ + +#ifndef _ASTERISK_ENDIAN_H +#define _ASTERISK_ENDIAN_H + +/* + * Autodetect system endianess + */ + +#ifdef SOLARIS +#include "solaris-compat/compat.h" +#endif + +#ifndef __BYTE_ORDER +#ifdef __linux__ +#include <endian.h> +#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) +#if defined(__OpenBSD__) +#include <machine/types.h> +#endif /* __OpenBSD__ */ +#include <machine/endian.h> +#define __BYTE_ORDER BYTE_ORDER +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#define __BIG_ENDIAN BIG_ENDIAN +#else +#ifdef __LITTLE_ENDIAN__ +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif /* __LITTLE_ENDIAN */ + +#if defined(i386) || defined(__i386__) +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif /* defined i386 */ + +#if defined(sun) && defined(unix) && defined(sparc) +#define __BYTE_ORDER __BIG_ENDIAN +#endif /* sun unix sparc */ + +#endif /* linux */ + +#endif /* __BYTE_ORDER */ + +#ifndef __BYTE_ORDER +#error Need to know endianess +#endif /* __BYTE_ORDER */ + +#endif /* _ASTERISK_ENDIAN_H */ + @@ -18,9 +18,9 @@ * will fill a supplied 16-byte array with the digest. */ -#include "include/astmanproxy.h" -#include "include/endian.h" -#include "include/md5.h" +#include "astmanproxy.h" +#include "endian.h" +#include "md5.h" # if __BYTE_ORDER == __BIG_ENDIAN # define HIGHFIRST 1 diff --git a/src/proxyfunc.c b/src/proxyfunc.c index 99d6dbc..31094f8 100644 --- a/src/proxyfunc.c +++ b/src/proxyfunc.c @@ -332,3 +332,34 @@ void *SendError(struct mansession *s, char *errmsg) { return 0; } +/*! If you are calling ast_carefulwrite, it is assumed that you are calling + it on a file descriptor that _DOES_ have NONBLOCK set. This way, + there is only one system call made to do a write, unless we actually + have a need to wait. This way, we get better performance. */ +int ast_carefulwrite(int fd, char *s, int len, int timeoutms) +{ + /* Try to write string, but wait no more than ms milliseconds + before timing out */ + int res=0; + struct pollfd fds[1]; + while(len) { + res = m_send(fd, s, len); + if ((res < 0) && (errno != EAGAIN)) { + return -1; + } + if (res < 0) res = 0; + len -= res; + s += res; + res = 0; + if (len) { + fds[0].fd = get_real_fd(fd); + fds[0].events = POLLOUT; + /* Wait until writable again */ + res = poll(fds, 1, timeoutms); + if (res < 1) + return -1; + } + } + return res; +} + |