diff options
27 files changed, 400 insertions, 34 deletions
diff --git a/build/m-powerpc.mak b/build/m-powerpc.mak new file mode 100644 index 00000000..6a8d4483 --- /dev/null +++ b/build/m-powerpc.mak @@ -0,0 +1,4 @@ +export M_CFLAGS := $(CC_DEF)PJ_M_POWERPC=1 +export M_CXXFLAGS := +export M_LDFLAGS := +export M_SOURCES := diff --git a/build/os-darwinos.mak b/build/os-darwinos.mak new file mode 100644 index 00000000..c9ab026f --- /dev/null +++ b/build/os-darwinos.mak @@ -0,0 +1,9 @@ +export OS_CFLAGS := $(CC_DEF)PJ_DARWINOS=1 + +export OS_CXXFLAGS := + +export OS_LDFLAGS := $(CC_LIB)pthread$(LIBEXT2) + +export OS_SOURCES := + + @@ -3,7 +3,7 @@ # # Detect machine # -MACHINE=`uname -m` +MACHINE=`uname -p` if echo $MACHINE | grep sun4u > /dev/null; then MACHINE_NAME=sparc @@ -11,8 +11,10 @@ elif echo $MACHINE | grep i.86 > /dev/null; then MACHINE_NAME=i386 elif echo $MACHINE | grep alpha > /dev/null; then MACHINE_NAME=alpha +elif echo $MACHINE | grep powerpc > /dev/null; then + MACHINE_NAME=powerpc else - echo "Unable to detect processor type ('uname -m' == '$MACHINE')" + echo "Unable to detect processor type ('uname -p' == '$MACHINE')" exit 1 fi @@ -44,6 +46,9 @@ elif echo $SYSTEM | grep -i mingw > /dev/null; then elif echo $SYSTEM | grep -i cygwin > /dev/null; then OS_NAME=win32 HOST_NAME=mingw +elif echo $SYSTEM | grep -i darwin > /dev/null; then + OS_NAME=darwinos + HOST_NAME=unix else echo "Unable to detect system type ('uname -s' == '$SYSTEM')" exit 1 diff --git a/pjlib/build/Makefile b/pjlib/build/Makefile index 54f71bca..0faadc15 100644 --- a/pjlib/build/Makefile +++ b/pjlib/build/Makefile @@ -22,7 +22,7 @@ export _LDFLAGS := $(subst /,$(HOST_PSEP),$(PJLIB_LIB)) \ export PJLIB_SRCDIR = ../src/pj export PJLIB_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \ array.o config.o ctype.o errno.o except.o fifobuf.o guid.o \ - hash.o list.o lock.o log.o \ + hash.o list.o lock.o log.o os_time_common.o \ pool.o pool_caching.o rand.o \ rbtree.o string.o timer.o \ types.o symbols.o diff --git a/pjlib/build/os-darwinos.mak b/pjlib/build/os-darwinos.mak new file mode 100644 index 00000000..fe1940ac --- /dev/null +++ b/pjlib/build/os-darwinos.mak @@ -0,0 +1,37 @@ +# +# PJLIB OS specific configuration for Darwin/MacOSX target. +# + +# +# PJLIB_OBJS specified here are object files to be included in PJLIB +# (the library) for this specific operating system. Object files common +# to all operating systems should go in Makefile instead. +# +export PJLIB_OBJS += addr_resolv_sock.o guid_simple.o \ + log_writer_stdout.o os_core_unix.o \ + os_error_unix.o os_time_unix.o \ + os_timestamp_common.o os_timestamp_linux.o \ + pool_policy_malloc.o sock_bsd.o sock_select.o + +export PJLIB_OBJS += ioqueue_select.o +#export PJLIB_OBJS += ioqueue_epoll.o + +export PJLIB_OBJS += file_access_unistd.o file_io_ansi.o + +# +# TEST_OBJS are operating system specific object files to be included in +# the test application. +# +export TEST_OBJS += main.o + +# +# Additional LDFLAGS for pjlib-test +# +export TEST_LDFLAGS += -lm + +# +# TARGETS are make targets in the Makefile, to be executed for this given +# operating system. +# +export TARGETS = pjlib pjlib-test + diff --git a/pjlib/build/os-linux.mak b/pjlib/build/os-linux.mak index 80801edf..568d1a18 100644 --- a/pjlib/build/os-linux.mak +++ b/pjlib/build/os-linux.mak @@ -9,7 +9,7 @@ # export PJLIB_OBJS += addr_resolv_sock.o guid_simple.o \ log_writer_stdout.o os_core_unix.o \ - os_error_unix.o os_time_ansi.o \ + os_error_unix.o os_time_unix.o \ os_timestamp_common.o os_timestamp_linux.o \ os_time_ansi.o \ pool_policy_malloc.o sock_bsd.o sock_select.o diff --git a/pjlib/build/os-sunos.mak b/pjlib/build/os-sunos.mak index 81ab64da..22931059 100644 --- a/pjlib/build/os-sunos.mak +++ b/pjlib/build/os-sunos.mak @@ -9,7 +9,7 @@ # export PJLIB_OBJS += addr_resolv_sock.o guid_simple.o \ log_writer_stdout.o os_core_unix.o \ - os_error_unix.o os_time_ansi.o \ + os_error_unix.o os_time_unix.o \ os_timestamp_common.o os_timestamp_linux.o \ os_time_ansi.o \ pool_policy_malloc.o sock_bsd.o sock_select.o diff --git a/pjlib/include/pj/compat/errno.h b/pjlib/include/pj/compat/errno.h index 8c86daa9..a385efc8 100644 --- a/pjlib/include/pj/compat/errno.h +++ b/pjlib/include/pj/compat/errno.h @@ -26,9 +26,7 @@ # define pj_get_native_os_error() GetLastError() # define pj_get_native_netos_error() WSAGetLastError() -#elif (defined(PJ_LINUX) && PJ_LINUX != 0) || \ - (defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0) || \ - (defined(PJ_SUNOS) && PJ_SUNOS != 0) +#elif defined(PJ_HAS_ERRNO_VAR) && PJ_HAS_ERRNO_VAR!= 0 typedef int pj_os_err_type; # define pj_get_native_os_error() (errno) @@ -36,7 +34,7 @@ #else -# error "Please define pj_os_err_type for this platform here!" +# error "Please define how to get errno for this platform here!" #endif diff --git a/pjlib/include/pj/compat/m_powerpc.h b/pjlib/include/pj/compat/m_powerpc.h new file mode 100644 index 00000000..49a9208c --- /dev/null +++ b/pjlib/include/pj/compat/m_powerpc.h @@ -0,0 +1,35 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJ_COMPAT_M_POWERPC_H__ +#define __PJ_COMPAT_M_POWERPC_H__ + +/** + * @file m_ppc.h + * @brief Describes PowerPC family processor specifics. + */ + +#define PJ_M_NAME "powerpc" + +#define PJ_HAS_PENTIUM 0 +#define PJ_IS_LITTLE_ENDIAN 0 +#define PJ_IS_BIG_ENDIAN 1 + + +#endif /* __PJ_COMPAT_M_POWERPC_H__ */ + diff --git a/pjlib/include/pj/compat/os_darwinos.h b/pjlib/include/pj/compat/os_darwinos.h new file mode 100644 index 00000000..9a0f90b0 --- /dev/null +++ b/pjlib/include/pj/compat/os_darwinos.h @@ -0,0 +1,110 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJ_COMPAT_OS_DARWINOS_H__ +#define __PJ_COMPAT_OS_DARWINOS_H__ + +/** + * @file os_darwinos.h + * @brief Describes Darwin/MacOSX operating system specifics. + */ + +#define PJ_OS_NAME "darwin" + +#define PJ_HAS_ARPA_INET_H 1 +#define PJ_HAS_ASSERT_H 1 +#define PJ_HAS_CTYPE_H 1 +#define PJ_HAS_ERRNO_H 1 +#define PJ_HAS_LINUX_SOCKET_H 0 +#define PJ_HAS_MALLOC_H 0 +#define PJ_HAS_NETDB_H 1 +#define PJ_HAS_NETINET_IN_H 1 +#define PJ_HAS_SETJMP_H 1 +#define PJ_HAS_STDARG_H 1 +#define PJ_HAS_STDDEF_H 1 +#define PJ_HAS_STDIO_H 1 +#define PJ_HAS_STDLIB_H 1 +#define PJ_HAS_STRING_H 1 +#define PJ_HAS_SYS_IOCTL_H 1 +#define PJ_HAS_SYS_SELECT_H 1 +#define PJ_HAS_SYS_SOCKET_H 1 +#define PJ_HAS_SYS_TIME_H 1 +#define PJ_HAS_SYS_TIMEB_H 1 +#define PJ_HAS_SYS_TYPES_H 1 +#define PJ_HAS_TIME_H 1 +#define PJ_HAS_UNISTD_H 1 + +#define PJ_HAS_MSWSOCK_H 0 +#define PJ_HAS_WINSOCK_H 0 +#define PJ_HAS_WINSOCK2_H 0 + +/* Is errno a good way to retrieve OS errors? + */ +#define PJ_HAS_ERRNO_VAR 1 + +/* Has inet_aton() ? + */ +#define PJ_SOCK_HAS_INET_ATON 1 + +/* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return + * the status of non-blocking connect() operation. + */ +#define PJ_HAS_SO_ERROR 1 + +/* This value specifies the value set in errno by the OS when a non-blocking + * socket recv() can not return immediate daata. + */ +#define PJ_BLOCKING_ERROR_VAL EWOULDBLOCK + +/* This value specifies the value set in errno by the OS when a non-blocking + * socket connect() can not get connected immediately. + */ +#define PJ_BLOCKING_CONNECT_ERROR_VAL EINPROGRESS + +/* Default threading is enabled, unless it's overridden. */ +#ifndef PJ_HAS_THREADS +# define PJ_HAS_THREADS (1) +#endif + +#define PJ_HAS_HIGH_RES_TIMER 1 +#define PJ_HAS_MALLOC 1 +#ifndef PJ_OS_HAS_CHECK_STACK +# define PJ_OS_HAS_CHECK_STACK 0 +#endif +#define PJ_NATIVE_STRING_IS_UNICODE 0 + +#define PJ_ATOMIC_VALUE_TYPE long + +/* + * Socket related + */ +typedef int socklen_t; +#define PJ_SOCKADDR_HAS_LEN 1 + +/* + * gcc complains that it can not use precompiled header because + * the value of FD_SETSIZE that we declare in pj/config.h is + * different than the value in /usr/include/sys/types.h. + * + * This changes the default value for Darwin. + */ +#define PJ_IOQUEUE_MAX_HANDLES 1024 + + +#endif /* __PJ_COMPAT_OS_DARWINOS_H__ */ + diff --git a/pjlib/include/pj/compat/os_linux.h b/pjlib/include/pj/compat/os_linux.h index 24faa228..fe3a29dd 100644 --- a/pjlib/include/pj/compat/os_linux.h +++ b/pjlib/include/pj/compat/os_linux.h @@ -43,6 +43,7 @@ #define PJ_HAS_SYS_IOCTL_H 1 #define PJ_HAS_SYS_SELECT_H 1 #define PJ_HAS_SYS_SOCKET_H 1 +#define PJ_HAS_SYS_TIME_H 0 #define PJ_HAS_SYS_TIMEB_H 1 #define PJ_HAS_SYS_TYPES_H 1 #define PJ_HAS_TIME_H 1 @@ -53,6 +54,11 @@ #define PJ_HAS_WINSOCK2_H 0 #define PJ_SOCK_HAS_INET_ATON 1 +#define PJ_SOCKADDR_HAS_LEN 0 + +/* Is errno a good way to retrieve OS errors? + */ +#define PJ_HAS_ERRNO_VAR 1 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return * the status of non-blocking connect() operation. diff --git a/pjlib/include/pj/compat/os_linux_kernel.h b/pjlib/include/pj/compat/os_linux_kernel.h index 502d5aa8..e481248d 100644 --- a/pjlib/include/pj/compat/os_linux_kernel.h +++ b/pjlib/include/pj/compat/os_linux_kernel.h @@ -43,6 +43,7 @@ #define PJ_HAS_SYS_IOCTL_H 0 #define PJ_HAS_SYS_SELECT_H 0 #define PJ_HAS_SYS_SOCKET_H 0 +#define PJ_HAS_SYS_TIME_H 0 #define PJ_HAS_SYS_TIMEB_H 0 #define PJ_HAS_SYS_TYPES_H 0 #define PJ_HAS_TIME_H 0 @@ -53,6 +54,7 @@ #define PJ_HAS_WINSOCK2_H 0 #define PJ_SOCK_HAS_INET_ATON 0 +#define PJ_SOCKADDR_HAS_LEN 0 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return * the status of non-blocking connect() operation. diff --git a/pjlib/include/pj/compat/os_palmos.h b/pjlib/include/pj/compat/os_palmos.h index e97cd66a..478e8715 100644 --- a/pjlib/include/pj/compat/os_palmos.h +++ b/pjlib/include/pj/compat/os_palmos.h @@ -52,6 +52,11 @@ #define PJ_HAS_WINSOCK2_H 0 #define PJ_SOCK_HAS_INET_ATON 0 +#define PJ_SOCKADDR_HAS_LEN 0 + +/* Is errno a good way to retrieve OS errors? + */ +#define PJ_HAS_ERRNO_VAR 0 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return * the status of non-blocking connect() operation. diff --git a/pjlib/include/pj/compat/os_sunos.h b/pjlib/include/pj/compat/os_sunos.h index bbe7a759..389d66c2 100644 --- a/pjlib/include/pj/compat/os_sunos.h +++ b/pjlib/include/pj/compat/os_sunos.h @@ -43,6 +43,7 @@ #define PJ_HAS_SYS_IOCTL_H 1 #define PJ_HAS_SYS_SELECT_H 1 #define PJ_HAS_SYS_SOCKET_H 1 +#define PJ_HAS_SYS_TIME_H 0 #define PJ_HAS_SYS_TIMEB_H 1 #define PJ_HAS_SYS_TYPES_H 1 #define PJ_HAS_TIME_H 1 @@ -53,6 +54,11 @@ #define PJ_HAS_WINSOCK2_H 0 #define PJ_SOCK_HAS_INET_ATON 0 +#define PJ_SOCKADDR_HAS_LEN 0 + +/* Is errno a good way to retrieve OS errors? + */ +#define PJ_HAS_ERRNO_VAR 1 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return * the status of non-blocking connect() operation. diff --git a/pjlib/include/pj/compat/os_win32.h b/pjlib/include/pj/compat/os_win32.h index 2a617640..5abfc89d 100644 --- a/pjlib/include/pj/compat/os_win32.h +++ b/pjlib/include/pj/compat/os_win32.h @@ -49,6 +49,7 @@ #define PJ_HAS_SYS_IOCTL_H 0 #define PJ_HAS_SYS_SELECT_H 0 #define PJ_HAS_SYS_SOCKET_H 0 +#define PJ_HAS_SYS_TIME_H 0 #define PJ_HAS_SYS_TIMEB_H 1 #define PJ_HAS_SYS_TYPES_H 1 #define PJ_HAS_TIME_H 1 @@ -59,6 +60,11 @@ #define PJ_HAS_WINSOCK2_H 1 #define PJ_SOCK_HAS_INET_ATON 0 +#define PJ_SOCKADDR_HAS_LEN 0 + +/* Is errno a good way to retrieve OS errors? (No) + */ +#define PJ_HAS_ERRNO_VAR 0 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return * the status of non-blocking connect() operation. diff --git a/pjlib/include/pj/compat/os_win32_wince.h b/pjlib/include/pj/compat/os_win32_wince.h index 05b89187..f6d46e89 100644 --- a/pjlib/include/pj/compat/os_win32_wince.h +++ b/pjlib/include/pj/compat/os_win32_wince.h @@ -47,6 +47,7 @@ #define PJ_HAS_SYS_IOCTL_H 0 #define PJ_HAS_SYS_SELECT_H 0 #define PJ_HAS_SYS_SOCKET_H 0 +#define PJ_HAS_SYS_TIME_H 0 #define PJ_HAS_SYS_TIMEB_H 0 /* Doesn't have sys/timeb.h */ #define PJ_HAS_SYS_TYPES_H 0 /* Doesn't have sys/types.h */ #define PJ_HAS_TIME_H 1 @@ -57,6 +58,11 @@ #define PJ_HAS_WINSOCK2_H 1 #define PJ_SOCK_HAS_INET_ATON 0 +#define PJ_SOCKADDR_HAS_LEN 0 + +/* Is errno a good way to retrieve OS errors? (no) + */ +#define PJ_HAS_ERRNO_VAR 0 /* When this macro is set, getsockopt(SOL_SOCKET, SO_ERROR) will return * the status of non-blocking connect() operation. @@ -97,3 +103,4 @@ #define PJ_NATIVE_STRING_IS_UNICODE 1 #endif /* __PJ_COMPAT_OS_WIN32_WINCE_H__ */ + diff --git a/pjlib/include/pj/compat/time.h b/pjlib/include/pj/compat/time.h index 2a2bc397..3ec73a7d 100644 --- a/pjlib/include/pj/compat/time.h +++ b/pjlib/include/pj/compat/time.h @@ -28,9 +28,14 @@ # include <time.h> #endif +#if defined(PJ_HAS_SYS_TIME_H) && PJ_HAS_SYS_TIME_H != 0 +# include <sys/time.h> +#endif + #if defined(PJ_HAS_SYS_TIMEB_H) && PJ_HAS_SYS_TIMEB_H != 0 # include <sys/timeb.h> #endif #endif /* __PJ_COMPAT_TIME_H__ */ + diff --git a/pjlib/include/pj/config.h b/pjlib/include/pj/config.h index 607bf261..2e6995da 100644 --- a/pjlib/include/pj/config.h +++ b/pjlib/include/pj/config.h @@ -51,6 +51,8 @@ # include <pj/compat/os_palmos.h> #elif defined(PJ_SUNOS) && PJ_SUNOS!=0 # include <pj/compat/os_sunos.h> +#elif defined(PJ_DARWINOS) && PJ_DARWINOS!=0 +# include <pj/compat/os_darwinos.h> #else # error "Please specify target os." #endif @@ -69,6 +71,8 @@ # include <pj/compat/m_sparc.h> #elif defined (PJ_M_ARMV4) && PJ_M_ARMV4 != 0 # include <pj/compat/m_armv4.h> +#elif defined (PJ_M_POWERPC) && PJ_M_POWERPC != 0 +# include <pj/compat/m_powerpc.h> #else # error "Please specify target machine." #endif @@ -246,7 +250,8 @@ * maximum number of socket handles passed to select() (i.e. FD_SETSIZE will * be set to this value). * - * Default: 256 (64 for WinCE) + * Default: if FD_SETSIZE is defined and the value is greather than 256, + * then it will be used. Otherwise 256 (64 for WinCE). */ #ifndef PJ_IOQUEUE_MAX_HANDLES # if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0 diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h index cd15913a..3e3307ab 100644 --- a/pjlib/include/pj/sock.h +++ b/pjlib/include/pj/sock.h @@ -156,10 +156,20 @@ typedef enum pj_socket_sd_type /** * Structure describing a generic socket address. + * If PJ_SOCKADDR_HAS_LEN is not zero, then sa_zero_len member is added + * to this struct. As far the application is concerned, the value of + * this member will always be zero. Internally, PJLIB may modify the value + * before calling OS socket API, and reset the value back to zero before + * returning the struct to application. */ typedef struct pj_sockaddr { +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + pj_uint8_t sa_zero_len; + pj_uint8_t sa_family; +#else pj_uint16_t sa_family; /**< Common data: address family. */ +#endif char sa_data[14]; /**< Address data. */ } pj_sockaddr; @@ -175,10 +185,20 @@ typedef struct pj_in_addr /** * This structure describes Internet socket address. + * If PJ_SOCKADDR_HAS_LEN is not zero, then sin_zero_len member is added + * to this struct. As far the application is concerned, the value of + * this member will always be zero. Internally, PJLIB may modify the value + * before calling OS socket API, and reset the value back to zero before + * returning the struct to application. */ struct pj_sockaddr_in { +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + pj_uint8_t sin_zero_len; /**< Just ignore this. */ + pj_uint8_t sin_family; /**< Address family. */ +#else pj_uint16_t sin_family; /**< Address family. */ +#endif pj_uint16_t sin_port; /**< Transport layer port number. */ pj_in_addr sin_addr; /**< IP address. */ char sin_zero[8]; /**< Padding. */ @@ -212,10 +232,20 @@ typedef struct pj_in6_addr /** * This structure describes IPv6 socket address. + * If PJ_SOCKADDR_HAS_LEN is not zero, then sin_zero_len member is added + * to this struct. As far the application is concerned, the value of + * this member will always be zero. Internally, PJLIB may modify the value + * before calling OS socket API, and reset the value back to zero before + * returning the struct to application. */ typedef struct pj_sockaddr_in6 { +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + pj_uint8_t sin_zero_len; /**< Just ignore this. */ + pj_uint8_t sin_family; /**< Address family. */ +#else pj_uint16_t sin6_family; /**< Address family */ +#endif pj_uint16_t sin6_port; /**< Transport layer port number. */ pj_uint32_t sin6_flowinfo; /**< IPv6 flow information */ pj_in6_addr sin6_addr; /**< IPv6 address. */ diff --git a/pjlib/src/pj/guid_simple.c b/pjlib/src/pj/guid_simple.c index 300abace..9e179925 100644 --- a/pjlib/src/pj/guid_simple.c +++ b/pjlib/src/pj/guid_simple.c @@ -20,7 +20,6 @@ #include <pj/os.h> #include <pj/rand.h> #include <pj/string.h> -#include <pj/compat/sprintf.h> const unsigned PJ_GUID_STRING_LENGTH=20; diff --git a/pjlib/src/pj/os_core_unix.c b/pjlib/src/pj/os_core_unix.c index b9fd0be7..ad9f6143 100644 --- a/pjlib/src/pj/os_core_unix.c +++ b/pjlib/src/pj/os_core_unix.c @@ -24,7 +24,6 @@ #include <pj/rand.h> #include <pj/string.h> #include <pj/guid.h> -#include <pj/compat/sprintf.h> #include <pj/except.h> #include <pj/errno.h> @@ -204,9 +203,9 @@ PJ_DEF(pj_status_t) pj_thread_register ( const char *cstr_thread_name, thread->thread = pthread_self(); if(cstr_thread_name && pj_strlen(&thread_name) < sizeof(thread->obj_name)-1) - pj_sprintf(thread->obj_name, cstr_thread_name, thread->thread); + pj_ansi_sprintf(thread->obj_name, cstr_thread_name, thread->thread); else - pj_sprintf(thread->obj_name, "thr%p", (void*)thread->thread); + pj_ansi_sprintf(thread->obj_name, "thr%p", (void*)thread->thread); rc = pj_thread_local_set(thread_tls_id, thread); if (rc != PJ_SUCCESS) @@ -314,7 +313,7 @@ PJ_DEF(pj_status_t) pj_thread_create( pj_pool_t *pool, thread_name = "thr%p"; if (strchr(thread_name, '%')) { - pj_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec); + pj_ansi_snprintf(rec->obj_name, PJ_MAX_OBJ_NAME, thread_name, rec); } else { strncpy(rec->obj_name, thread_name, PJ_MAX_OBJ_NAME); rec->obj_name[PJ_MAX_OBJ_NAME-1] = '\0'; @@ -804,7 +803,7 @@ static pj_status_t init_mutex(pj_mutex_t *mutex, const char *name, int type) name = "mtx%p"; } if (strchr(name, '%')) { - pj_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex); + pj_ansi_snprintf(mutex->obj_name, PJ_MAX_OBJ_NAME, name, mutex); } else { strncpy(mutex->obj_name, name, PJ_MAX_OBJ_NAME); mutex->obj_name[PJ_MAX_OBJ_NAME-1] = '\0'; @@ -1125,7 +1124,7 @@ PJ_DEF(pj_status_t) pj_sem_create( pj_pool_t *pool, name = "sem%p"; } if (strchr(name, '%')) { - pj_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem); + pj_ansi_snprintf(sem->obj_name, PJ_MAX_OBJ_NAME, name, sem); } else { strncpy(sem->obj_name, name, PJ_MAX_OBJ_NAME); sem->obj_name[PJ_MAX_OBJ_NAME-1] = '\0'; diff --git a/pjlib/src/pj/os_time_bsd.c b/pjlib/src/pj/os_time_bsd.c new file mode 100644 index 00000000..b9918f18 --- /dev/null +++ b/pjlib/src/pj/os_time_bsd.c @@ -0,0 +1,35 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <pj/os.h> +#include <pj/compat/time.h> + +/////////////////////////////////////////////////////////////////////////////// + +PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv) +{ + struct timeb tb; + + PJ_CHECK_STACK(); + + ftime(&tb); + tv->sec = tb.time; + tv->msec = tb.millitm; + return PJ_SUCCESS; +} + diff --git a/pjlib/src/pj/os_time_ansi.c b/pjlib/src/pj/os_time_common.c index c0cb9f51..3d470a27 100644 --- a/pjlib/src/pj/os_time_ansi.c +++ b/pjlib/src/pj/os_time_common.c @@ -21,18 +21,6 @@ /////////////////////////////////////////////////////////////////////////////// -PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv) -{ - struct timeb tb; - - PJ_CHECK_STACK(); - - ftime(&tb); - tv->sec = tb.time; - tv->msec = tb.millitm; - return PJ_SUCCESS; -} - PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt) { struct tm *local_time; diff --git a/pjlib/src/pj/os_time_unix.c b/pjlib/src/pj/os_time_unix.c new file mode 100644 index 00000000..b5733b64 --- /dev/null +++ b/pjlib/src/pj/os_time_unix.c @@ -0,0 +1,39 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <pj/os.h> +#include <pj/compat/time.h> + +#if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H!=0 +# include <unistd.h> +#endif + +/////////////////////////////////////////////////////////////////////////////// + +PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *p_tv) +{ + struct timeval tv; + + PJ_CHECK_STACK(); + + gettimeofday(&tv, NULL); + p_tv->sec = tv.tv_sec; + p_tv->msec = tv.tv_usec / 1000; + return PJ_SUCCESS; +} + diff --git a/pjlib/src/pj/pool_caching.c b/pjlib/src/pj/pool_caching.c index 6114160e..324ad05d 100644 --- a/pjlib/src/pj/pool_caching.c +++ b/pjlib/src/pj/pool_caching.c @@ -57,7 +57,7 @@ PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp, cp->factory.release_pool = &cpool_release_pool; cp->factory.dump_status = &cpool_dump_status; - cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 128, + cp->pool = pj_pool_create_int(&cp->factory, "cachingpool", 256, 0, NULL); i = pj_mutex_create_simple(cp->pool, "cachingpool", &cp->mutex); } diff --git a/pjlib/src/pj/sock_bsd.c b/pjlib/src/pj/sock_bsd.c index df59a742..09b362ad 100644 --- a/pjlib/src/pj/sock_bsd.c +++ b/pjlib/src/pj/sock_bsd.c @@ -82,6 +82,15 @@ const pj_uint16_t PJ_SO_RCVBUF = SO_RCVBUF; const pj_uint16_t PJ_SO_SNDBUF = SO_SNDBUF; +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 +# define SET_LEN(addr,len) (((pj_sockaddr*)(addr))->sa_zero_len=(len)) +# define RESET_LEN(addr) (((pj_sockaddr*)(addr))->sa_zero_len=0) +#else +# define SET_LEN(addr,len) +# define RESET_LEN(addr) +#endif + + /* * Convert 16-bit value from network byte order to host byte order. */ @@ -190,6 +199,7 @@ PJ_DEF(pj_status_t) pj_sockaddr_in_set_str_addr( pj_sockaddr_in *addr, PJ_ASSERT_RETURN(!str_addr || str_addr->slen < PJ_MAX_HOSTNAME, (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL)); + RESET_LEN(addr); addr->sin_family = AF_INET; if (str_addr && str_addr->slen) { @@ -226,6 +236,7 @@ PJ_DEF(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr, { PJ_ASSERT_RETURN(addr, (addr->sin_addr.s_addr=PJ_INADDR_NONE, PJ_EINVAL)); + RESET_LEN(addr); addr->sin_family = PJ_AF_INET; pj_sockaddr_in_set_port(addr, port); return pj_sockaddr_in_set_str_addr(addr, str_addr); @@ -346,6 +357,7 @@ PJ_DEF(pj_status_t) pj_sock_bind_in( pj_sock_t sock, PJ_CHECK_STACK(); + SET_LEN(&addr, sizeof(pj_sockaddr_in)); addr.sin_family = PJ_AF_INET; addr.sin_addr.s_addr = pj_htonl(addr32); addr.sin_port = pj_htons(port); @@ -385,8 +397,10 @@ PJ_DEF(pj_status_t) pj_sock_getpeername( pj_sock_t sock, PJ_CHECK_STACK(); if (getpeername(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + RESET_LEN(addr); return PJ_SUCCESS; + } } /* @@ -399,8 +413,10 @@ PJ_DEF(pj_status_t) pj_sock_getsockname( pj_sock_t sock, PJ_CHECK_STACK(); if (getsockname(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + RESET_LEN(addr); return PJ_SUCCESS; + } } /* @@ -483,8 +499,10 @@ PJ_DEF(pj_status_t) pj_sock_recvfrom(pj_sock_t sock, if (*len < 0) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + RESET_LEN(from); return PJ_SUCCESS; + } } /* @@ -574,11 +592,25 @@ PJ_DEF(pj_status_t) pj_sock_accept( pj_sock_t serverfd, PJ_CHECK_STACK(); PJ_ASSERT_RETURN(newsock != NULL, PJ_EINVAL); +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + if (addr) { + SET_LEN(addr, *addrlen); + } +#endif + *newsock = accept(serverfd, (struct sockaddr*)addr, (socklen_t*)addrlen); if (*newsock==PJ_INVALID_SOCKET) return PJ_RETURN_OS_ERROR(pj_get_native_netos_error()); - else + else { + +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 + if (addr) { + RESET_LEN(addr); + } +#endif + return PJ_SUCCESS; + } } #endif /* PJ_HAS_TCP */ diff --git a/pjlib/src/pj/sock_select.c b/pjlib/src/pj/sock_select.c index c2d0fcf8..59950e62 100644 --- a/pjlib/src/pj/sock_select.c +++ b/pjlib/src/pj/sock_select.c @@ -26,6 +26,10 @@ # include <string.h> #endif +#if defined(PJ_HAS_SYS_TIME_H) && PJ_HAS_SYS_TIME_H!=0 +# include <sys/time.h> +#endif + #ifdef _MSC_VER # pragma warning(disable: 4018) // Signed/unsigned mismatch in FD_* # pragma warning(disable: 4389) // Signed/unsigned mismatch in FD_* |