diff options
Diffstat (limited to 'pjlib/src')
-rw-r--r-- | pjlib/src/pj/guid_simple.c | 1 | ||||
-rw-r--r-- | pjlib/src/pj/os_core_unix.c | 11 | ||||
-rw-r--r-- | pjlib/src/pj/os_time_bsd.c | 35 | ||||
-rw-r--r-- | pjlib/src/pj/os_time_common.c (renamed from pjlib/src/pj/os_time_ansi.c) | 12 | ||||
-rw-r--r-- | pjlib/src/pj/os_time_unix.c | 39 | ||||
-rw-r--r-- | pjlib/src/pj/pool_caching.c | 2 | ||||
-rw-r--r-- | pjlib/src/pj/sock_bsd.c | 40 | ||||
-rw-r--r-- | pjlib/src/pj/sock_select.c | 4 |
8 files changed, 120 insertions, 24 deletions
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_* |