diff options
author | Benny Prijono <bennylp@teluu.com> | 2005-11-07 18:14:08 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2005-11-07 18:14:08 +0000 |
commit | 8b3f0c56c5c885134f3865539a7257a7ebb90387 (patch) | |
tree | 0388183e5ca1c7973c0b830bdbd0bedd58a9c315 /pjlib | |
parent | e25a988d098a075f5519090c24237c3b97bc1323 (diff) |
UDP echo testing in Linux
git-svn-id: http://svn.pjsip.org/repos/pjproject/main@19 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r-- | pjlib/build/Makefile | 8 | ||||
-rw-r--r-- | pjlib/build/os-linux.mak | 2 | ||||
-rw-r--r-- | pjlib/include/pj/ioqueue.h | 8 | ||||
-rw-r--r-- | pjlib/src/pj/config.c | 5 | ||||
-rw-r--r-- | pjlib/src/pj/file_access_unistd.c | 96 | ||||
-rw-r--r-- | pjlib/src/pj/ioqueue_epoll.c | 12 | ||||
-rw-r--r-- | pjlib/src/pj/ioqueue_select.c | 30 | ||||
-rw-r--r-- | pjlib/src/pj/ioqueue_winnt.c | 676 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/echo_clt.c | 14 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/test.c | 28 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/test.h | 26 | ||||
-rw-r--r-- | pjlib/src/pjlib-test/udp_echo_srv_sync.c | 120 |
12 files changed, 587 insertions, 438 deletions
diff --git a/pjlib/build/Makefile b/pjlib/build/Makefile index e6a1bd9f..4a0db783 100644 --- a/pjlib/build/Makefile +++ b/pjlib/build/Makefile @@ -84,13 +84,13 @@ export PJLIB_CFLAGS += $(_CFLAGS) # Defines for building test application # export TEST_SRCDIR = ../src/pjlib-test -export TEST_OBJS += atomic.o echo_clt.o echo_srv.o errno.o exception.o \ - fifobuf.o \ +export TEST_OBJS += atomic.o echo_clt.o errno.o exception.o \ + fifobuf.o file.o \ ioq_perf.o ioq_udp.o ioq_tcp.o \ list.o mutex.o os.o pool.o pool_perf.o rand.o rbtree.o \ select.o sleep.o sock.o sock_perf.o \ string.o test.o thread.o timer.o timestamp.o \ - udp_echo_srv_sync.o \ + udp_echo_srv_sync.o udp_echo_srv_ioqueue.o \ util.o xml.o export TEST_CFLAGS += $(_CFLAGS) export TEST_LDFLAGS += $(_LDFLAGS) @@ -113,7 +113,7 @@ print: $(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib print_lib $(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test print_bin -depend: +depend: ../include/pj/config_site.h $(MAKE) -f $(RULES_MAK) APP=PJLIB app=pjlib depend $(MAKE) -f $(RULES_MAK) APP=TEST app=pjlib-test depend echo '$(TEST_EXE): $(PJLIB_LIB)' >> .pjlib-test-$(MACHINE_NAME)-$(OS_NAME)-$(CC_NAME).depend diff --git a/pjlib/build/os-linux.mak b/pjlib/build/os-linux.mak index ab220411..a705d4cd 100644 --- a/pjlib/build/os-linux.mak +++ b/pjlib/build/os-linux.mak @@ -17,6 +17,8 @@ export PJLIB_OBJS += addr_resolv_sock.o guid_simple.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. diff --git a/pjlib/include/pj/ioqueue.h b/pjlib/include/pj/ioqueue.h index 303df162..1ecec1b4 100644 --- a/pjlib/include/pj/ioqueue.h +++ b/pjlib/include/pj/ioqueue.h @@ -110,7 +110,6 @@ PJ_BEGIN_DECL */ - /** * This structure describes operation specific key to be submitted to * I/O Queue when performing the asynchronous operation. This key will @@ -219,6 +218,13 @@ typedef enum pj_ioqueue_operation_e # define PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL (16) #endif +/** + * Return the name of the ioqueue implementation. + * + * @return Implementation name. + */ +PJ_DECL(const char*) pj_ioqueue_name(void); + /** * Create a new I/O Queue framework. diff --git a/pjlib/src/pj/config.c b/pjlib/src/pj/config.c index 3354f133..7923088d 100644 --- a/pjlib/src/pj/config.c +++ b/pjlib/src/pj/config.c @@ -2,6 +2,7 @@ */ #include <pj/config.h> #include <pj/log.h> +#include <pj/ioqueue.h> static const char *id = "config.c"; const char *PJ_VERSION = "0.3.0-pre4"; @@ -23,7 +24,9 @@ PJ_DEF(void) pj_dump_config(void) PJ_LOG(3, (id, " PJ_HAS_SEMAPHORE : %d", PJ_HAS_SEMAPHORE)); PJ_LOG(3, (id, " PJ_HAS_EVENT_OBJ : %d", PJ_HAS_EVENT_OBJ)); PJ_LOG(3, (id, " PJ_HAS_HIGH_RES_TIMER : %d", PJ_HAS_HIGH_RES_TIMER)); - PJ_LOG(3, (id, " PJ_(endianness) : %s", (PJ_IS_BIG_ENDIAN?"big-endian":"little-endian"))); + PJ_LOG(3, (id, " PJ_(endianness) : %s", + (PJ_IS_BIG_ENDIAN?"big-endian":"little-endian"))); + PJ_LOG(3, (id, " ioqueue type : %s", pj_ioqueue_name())); PJ_LOG(3, (id, " PJ_IOQUEUE_MAX_HANDLES : %d", PJ_IOQUEUE_MAX_HANDLES)); } diff --git a/pjlib/src/pj/file_access_unistd.c b/pjlib/src/pj/file_access_unistd.c new file mode 100644 index 00000000..8e46e0ed --- /dev/null +++ b/pjlib/src/pj/file_access_unistd.c @@ -0,0 +1,96 @@ +/* $Id$ */ +#include <pj/file_access.h> +#include <pj/assert.h> +#include <pj/errno.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <stdio.h> /* rename() */ +#include <errno.h> + +/* + * pj_file_exists() + */ +PJ_DEF(pj_bool_t) pj_file_exists(const char *filename) +{ + struct stat buf; + + PJ_ASSERT_RETURN(filename, 0); + + if (stat(filename, &buf) != 0) + return 0; + + return PJ_TRUE; +} + + +/* + * pj_file_size() + */ +PJ_DEF(pj_off_t) pj_file_size(const char *filename) +{ + struct stat buf; + + PJ_ASSERT_RETURN(filename, -1); + + if (stat(filename, &buf) != 0) + return -1; + + return buf.st_size; +} + + +/* + * pj_file_delete() + */ +PJ_DEF(pj_status_t) pj_file_delete(const char *filename) +{ + PJ_ASSERT_RETURN(filename, PJ_EINVAL); + + if (unlink(filename)!=0) { + return PJ_RETURN_OS_ERROR(errno); + } + return PJ_SUCCESS; +} + + +/* + * pj_file_move() + */ +PJ_DEF(pj_status_t) pj_file_move( const char *oldname, const char *newname) +{ + PJ_ASSERT_RETURN(oldname && newname, PJ_EINVAL); + + if (rename(oldname, newname) != 0) { + return PJ_RETURN_OS_ERROR(errno); + } + return PJ_SUCCESS; +} + + +/* + * pj_file_getstat() + */ +PJ_DEF(pj_status_t) pj_file_getstat(const char *filename, + pj_file_stat *statbuf) +{ + struct stat buf; + + PJ_ASSERT_RETURN(filename && statbuf, PJ_EINVAL); + + if (stat(filename, &buf) != 0) { + return PJ_RETURN_OS_ERROR(errno); + } + + statbuf->size = buf.st_size; + statbuf->ctime.sec = buf.st_ctime; + statbuf->ctime.msec = 0; + statbuf->mtime.sec = buf.st_mtime; + statbuf->mtime.msec = 0; + statbuf->atime.sec = buf.st_atime; + statbuf->atime.msec = 0; + + return PJ_SUCCESS; +} + diff --git a/pjlib/src/pj/ioqueue_epoll.c b/pjlib/src/pj/ioqueue_epoll.c index aa012531..140bd130 100644 --- a/pjlib/src/pj/ioqueue_epoll.c +++ b/pjlib/src/pj/ioqueue_epoll.c @@ -159,6 +159,18 @@ struct pj_ioqueue_t #include "ioqueue_common_abs.c" /* + * pj_ioqueue_name() + */ +PJ_DEF(const char*) pj_ioqueue_name(void) +{ +#if defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL!=0 + return "epoll-kernel"; +#else + return "epoll"; +#endif +} + +/* * pj_ioqueue_create() * * Create select ioqueue. diff --git a/pjlib/src/pj/ioqueue_select.c b/pjlib/src/pj/ioqueue_select.c index 886c3cda..09318d4e 100644 --- a/pjlib/src/pj/ioqueue_select.c +++ b/pjlib/src/pj/ioqueue_select.c @@ -66,15 +66,15 @@ PJ_DECL(pj_size_t) PJ_FD_COUNT(const pj_fd_set_t *fdsetp); /* * During debugging build, VALIDATE_FD_SET is set. * This will check the validity of the fd_sets. - */
+ */ /* #if defined(PJ_DEBUG) && PJ_DEBUG != 0 # define VALIDATE_FD_SET 1 #else # define VALIDATE_FD_SET 0 #endif -*/
-#define VALIDATE_FD_SET 0
+*/ +#define VALIDATE_FD_SET 0 /* * This describes each key. @@ -106,6 +106,14 @@ struct pj_ioqueue_t #include "ioqueue_common_abs.c" /* + * pj_ioqueue_name() + */ +PJ_DEF(const char*) pj_ioqueue_name(void) +{ + return "select"; +} + +/* * pj_ioqueue_create() * * Create select ioqueue. @@ -273,14 +281,14 @@ static void validate_sets(const pj_ioqueue_t *ioqueue, const pj_fd_set_t *xfdset) { pj_ioqueue_key_t *key; -
- /*
- * This basicly would not work anymore.
- * We need to lock key before performing the check, but we can't do
- * so because we're holding ioqueue mutex. If we acquire key's mutex
- * now, the will cause deadlock.
- */
- pj_assert(0);
+ + /* + * This basicly would not work anymore. + * We need to lock key before performing the check, but we can't do + * so because we're holding ioqueue mutex. If we acquire key's mutex + * now, the will cause deadlock. + */ + pj_assert(0); key = ioqueue->key_list.next; while (key != &ioqueue->key_list) { diff --git a/pjlib/src/pj/ioqueue_winnt.c b/pjlib/src/pj/ioqueue_winnt.c index 32a74666..7944953f 100644 --- a/pjlib/src/pj/ioqueue_winnt.c +++ b/pjlib/src/pj/ioqueue_winnt.c @@ -22,28 +22,28 @@ # include <mswsock.h> #endif -
-/* The address specified in AcceptEx() must be 16 more than the size of
- * SOCKADDR (source: MSDN).
+ +/* The address specified in AcceptEx() must be 16 more than the size of + * SOCKADDR (source: MSDN). */ #define ACCEPT_ADDR_LEN (sizeof(pj_sockaddr_in)+16) -
-typedef struct generic_overlapped
-{
- WSAOVERLAPPED overlapped;
- pj_ioqueue_operation_e operation;
-} generic_overlapped;
-
+ +typedef struct generic_overlapped +{ + WSAOVERLAPPED overlapped; + pj_ioqueue_operation_e operation; +} generic_overlapped; + /* * OVERLAPPPED structure for send and receive. */ typedef struct ioqueue_overlapped { - WSAOVERLAPPED overlapped;
+ WSAOVERLAPPED overlapped; pj_ioqueue_operation_e operation; - WSABUF wsabuf;
- pj_sockaddr_in dummy_addr;
- int dummy_addrlen;
+ WSABUF wsabuf; + pj_sockaddr_in dummy_addr; + int dummy_addrlen; } ioqueue_overlapped; #if PJ_HAS_TCP @@ -52,7 +52,7 @@ typedef struct ioqueue_overlapped */ typedef struct ioqueue_accept_rec { - WSAOVERLAPPED overlapped;
+ WSAOVERLAPPED overlapped; pj_ioqueue_operation_e operation; pj_sock_t newsock; pj_sock_t *newsock_ptr; @@ -62,35 +62,35 @@ typedef struct ioqueue_accept_rec char accept_buf[2 * ACCEPT_ADDR_LEN]; } ioqueue_accept_rec; #endif -
-/*
- * Structure to hold pending operation key.
- */
-union operation_key
-{
- generic_overlapped generic;
- ioqueue_overlapped overlapped;
-#if PJ_HAS_TCP
- ioqueue_accept_rec accept;
-#endif
-};
-
-/* Type of handle in the key. */
-enum handle_type
-{
- HND_IS_UNKNOWN,
- HND_IS_FILE,
- HND_IS_SOCKET,
-};
+ +/* + * Structure to hold pending operation key. + */ +union operation_key +{ + generic_overlapped generic; + ioqueue_overlapped overlapped; +#if PJ_HAS_TCP + ioqueue_accept_rec accept; +#endif +}; + +/* Type of handle in the key. */ +enum handle_type +{ + HND_IS_UNKNOWN, + HND_IS_FILE, + HND_IS_SOCKET, +}; /* * Structure for individual socket. */ struct pj_ioqueue_key_t -{
+{ pj_ioqueue_t *ioqueue; HANDLE hnd; - void *user_data;
+ void *user_data; enum handle_type hnd_type; #if PJ_HAS_TCP int connecting; @@ -136,13 +136,13 @@ static void ioqueue_on_accept_complete(ioqueue_accept_rec *accept_overlapped) &local, &locallen, &remote, - &remotelen);
+ &remotelen); if (*accept_overlapped->addrlen > locallen) { pj_memcpy(accept_overlapped->local, local, locallen); - pj_memcpy(accept_overlapped->remote, remote, locallen);
- } else {
- pj_memset(accept_overlapped->local, 0, *accept_overlapped->addrlen);
- pj_memset(accept_overlapped->remote, 0, *accept_overlapped->addrlen);
+ pj_memcpy(accept_overlapped->remote, remote, locallen); + } else { + pj_memset(accept_overlapped->local, 0, *accept_overlapped->addrlen); + pj_memset(accept_overlapped->remote, 0, *accept_overlapped->addrlen); } *accept_overlapped->addrlen = locallen; if (accept_overlapped->newsock_ptr) @@ -211,7 +211,7 @@ static pj_ioqueue_key_t *check_connecting( pj_ioqueue_t *ioqueue, WSAEnumNetworkEvents((pj_sock_t)key->hnd, ioqueue->connecting_handles[pos], &net_events); - *connect_err =
+ *connect_err = PJ_STATUS_FROM_OS(net_events.iErrorCode[FD_CONNECT_BIT]); /* Erase socket from pending connect. */ @@ -223,8 +223,16 @@ static pj_ioqueue_key_t *check_connecting( pj_ioqueue_t *ioqueue, } #endif -/*
- * pj_ioqueue_create()
+/* + * pj_ioqueue_name() + */ +PJ_DEF(const char*) pj_ioqueue_name(void) +{ + return "iocp"; +} + +/* + * pj_ioqueue_create() */ PJ_DEF(pj_status_t) pj_ioqueue_create( pj_pool_t *pool, pj_size_t max_fd, @@ -235,12 +243,12 @@ PJ_DEF(pj_status_t) pj_ioqueue_create( pj_pool_t *pool, PJ_UNUSED_ARG(max_fd); PJ_ASSERT_RETURN(pool && p_ioqueue, PJ_EINVAL); -
- rc = sizeof(union operation_key);
-
- /* Check that sizeof(pj_ioqueue_op_key_t) makes sense. */
- PJ_ASSERT_RETURN(sizeof(pj_ioqueue_op_key_t)-sizeof(void*) >=
- sizeof(union operation_key), PJ_EBUG);
+ + rc = sizeof(union operation_key); + + /* Check that sizeof(pj_ioqueue_op_key_t) makes sense. */ + PJ_ASSERT_RETURN(sizeof(pj_ioqueue_op_key_t)-sizeof(void*) >= + sizeof(union operation_key), PJ_EBUG); ioqueue = pj_pool_zalloc(pool, sizeof(*ioqueue)); ioqueue->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); @@ -260,9 +268,9 @@ PJ_DEF(pj_status_t) pj_ioqueue_create( pj_pool_t *pool, PJ_LOG(4, ("pjlib", "WinNT IOCP I/O Queue created (%p)", ioqueue)); return PJ_SUCCESS; } -
-/*
- * pj_ioqueue_destroy()
+ +/* + * pj_ioqueue_destroy() */ PJ_DEF(pj_status_t) pj_ioqueue_destroy( pj_ioqueue_t *ioqueue ) { @@ -278,16 +286,16 @@ PJ_DEF(pj_status_t) pj_ioqueue_destroy( pj_ioqueue_t *ioqueue ) ioqueue->event_count = 0; if (CloseHandle(ioqueue->iocp) != TRUE) - return PJ_RETURN_OS_ERROR(GetLastError());
-
- if (ioqueue->auto_delete_lock)
- pj_lock_destroy(ioqueue->lock);
-
+ return PJ_RETURN_OS_ERROR(GetLastError()); + + if (ioqueue->auto_delete_lock) + pj_lock_destroy(ioqueue->lock); + return PJ_SUCCESS; } -
-/*
- * pj_ioqueue_set_lock()
+ +/* + * pj_ioqueue_set_lock() */ PJ_DEF(pj_status_t) pj_ioqueue_set_lock( pj_ioqueue_t *ioqueue, pj_lock_t *lock, @@ -304,9 +312,9 @@ PJ_DEF(pj_status_t) pj_ioqueue_set_lock( pj_ioqueue_t *ioqueue, return PJ_SUCCESS; } -
-/*
- * pj_ioqueue_register_sock()
+ +/* + * pj_ioqueue_register_sock() */ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool, pj_ioqueue_t *ioqueue, @@ -316,27 +324,27 @@ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool, pj_ioqueue_key_t **key ) { HANDLE hioq; - pj_ioqueue_key_t *rec;
+ pj_ioqueue_key_t *rec; u_long value; - int rc;
+ int rc; PJ_ASSERT_RETURN(pool && ioqueue && cb && key, PJ_EINVAL); -
+ /* Build the key for this socket. */ - rec = pj_pool_zalloc(pool, sizeof(pj_ioqueue_key_t));
+ rec = pj_pool_zalloc(pool, sizeof(pj_ioqueue_key_t)); rec->ioqueue = ioqueue; - rec->hnd = (HANDLE)sock;
+ rec->hnd = (HANDLE)sock; rec->hnd_type = HND_IS_SOCKET; rec->user_data = user_data; pj_memcpy(&rec->cb, cb, sizeof(pj_ioqueue_callback)); -
- /* Set socket to nonblocking. */
- value = 1;
- rc = ioctlsocket(sock, FIONBIO, &value);
- if (rc != 0) {
- return PJ_RETURN_OS_ERROR(WSAGetLastError());
- }
-
+ + /* Set socket to nonblocking. */ + value = 1; + rc = ioctlsocket(sock, FIONBIO, &value); + if (rc != 0) { + return PJ_RETURN_OS_ERROR(WSAGetLastError()); + } + /* Associate with IOCP */ hioq = CreateIoCompletionPort((HANDLE)sock, ioqueue->iocp, (DWORD)rec, 0); if (!hioq) { @@ -346,9 +354,9 @@ PJ_DEF(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool, *key = rec; return PJ_SUCCESS; } -
+ /* - * pj_ioqueue_unregister()
+ * pj_ioqueue_unregister() */ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key ) { @@ -357,9 +365,9 @@ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key ) #if PJ_HAS_TCP if (key->connecting) { unsigned pos; - pj_ioqueue_t *ioqueue;
-
- ioqueue = key->ioqueue;
+ pj_ioqueue_t *ioqueue; + + ioqueue = key->ioqueue; /* Erase from connecting_handles */ pj_lock_acquire(ioqueue->lock); @@ -369,43 +377,43 @@ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key ) break; } } - key->connecting = 0;
+ key->connecting = 0; pj_lock_release(ioqueue->lock); } -#endif
- if (key->hnd_type == HND_IS_FILE) {
- CloseHandle(key->hnd);
+#endif + if (key->hnd_type == HND_IS_FILE) { + CloseHandle(key->hnd); } return PJ_SUCCESS; } -
-/*
- * pj_ioqueue_get_user_data()
+ +/* + * pj_ioqueue_get_user_data() */ PJ_DEF(void*) pj_ioqueue_get_user_data( pj_ioqueue_key_t *key ) { PJ_ASSERT_RETURN(key, NULL); return key->user_data; } -
-/*
- * pj_ioqueue_set_user_data()
- */
-PJ_DEF(pj_status_t) pj_ioqueue_set_user_data( pj_ioqueue_key_t *key,
- void *user_data,
- void **old_data )
-{
- PJ_ASSERT_RETURN(key, PJ_EINVAL);
-
- if (old_data)
- *old_data = key->user_data;
-
- key->user_data = user_data;
- return PJ_SUCCESS;
-}
-
-/*
- * pj_ioqueue_poll()
+ +/* + * pj_ioqueue_set_user_data() + */ +PJ_DEF(pj_status_t) pj_ioqueue_set_user_data( pj_ioqueue_key_t *key, + void *user_data, + void **old_data ) +{ + PJ_ASSERT_RETURN(key, PJ_EINVAL); + + if (old_data) + *old_data = key->user_data; + + key->user_data = user_data; + return PJ_SUCCESS; +} + +/* + * pj_ioqueue_poll() * * Poll for events. */ @@ -450,7 +458,7 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout) case PJ_IOQUEUE_OP_RECV_FROM: pOv->operation = 0; if (key->cb.on_read_complete) - key->cb.on_read_complete(key, (pj_ioqueue_op_key_t*)pOv,
+ key->cb.on_read_complete(key, (pj_ioqueue_op_key_t*)pOv, size_status); break; case PJ_IOQUEUE_OP_WRITE: @@ -458,19 +466,19 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout) case PJ_IOQUEUE_OP_SEND_TO: pOv->operation = 0; if (key->cb.on_write_complete) - key->cb.on_write_complete(key, (pj_ioqueue_op_key_t*)pOv,
+ key->cb.on_write_complete(key, (pj_ioqueue_op_key_t*)pOv, size_status); break; #if PJ_HAS_TCP case PJ_IOQUEUE_OP_ACCEPT: /* special case for accept. */ ioqueue_on_accept_complete((ioqueue_accept_rec*)pOv); - if (key->cb.on_accept_complete) {
+ if (key->cb.on_accept_complete) { ioqueue_accept_rec *accept_rec = (ioqueue_accept_rec*)pOv; - key->cb.on_accept_complete(key,
- (pj_ioqueue_op_key_t*)pOv,
+ key->cb.on_accept_complete(key, + (pj_ioqueue_op_key_t*)pOv, accept_rec->newsock, - PJ_SUCCESS);
+ PJ_SUCCESS); } break; case PJ_IOQUEUE_OP_CONNECT: @@ -495,74 +503,74 @@ PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioqueue, const pj_time_val *timeout) } return -1; } -
+ /* * pj_ioqueue_recv() * * Initiate overlapped WSARecv() operation. */ -PJ_DEF(pj_status_t) pj_ioqueue_recv( pj_ioqueue_key_t *key,
+PJ_DEF(pj_status_t) pj_ioqueue_recv( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, void *buffer, pj_ssize_t *length, unsigned flags ) -{
- /*
- * Ideally we should just call pj_ioqueue_recvfrom() with NULL addr and
- * addrlen here. But unfortunately it generates EINVAL... :-(
- * -bennylp
- */
- int rc;
- DWORD bytesRead;
- DWORD dwFlags = 0;
- union operation_key *op_key_rec;
-
- PJ_CHECK_STACK();
- PJ_ASSERT_RETURN(key && op_key && buffer && length, PJ_EINVAL);
-
- op_key_rec = (union operation_key*)op_key->internal__;
- op_key_rec->overlapped.wsabuf.buf = buffer;
- op_key_rec->overlapped.wsabuf.len = *length;
-
- dwFlags = flags;
-
- /* Try non-overlapped received first to see if data is
- * immediately available.
- */
- rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1,
- &bytesRead, &dwFlags, NULL, NULL);
- if (rc == 0) {
- *length = bytesRead;
- return PJ_SUCCESS;
- } else {
- DWORD dwError = WSAGetLastError();
- if (dwError != WSAEWOULDBLOCK) {
- *length = -1;
- return PJ_RETURN_OS_ERROR(dwError);
- }
- }
-
- /*
- * No immediate data available.
- * Register overlapped Recv() operation.
- */
- pj_memset(&op_key_rec->overlapped.overlapped, 0,
- sizeof(op_key_rec->overlapped.overlapped));
- op_key_rec->overlapped.operation = PJ_IOQUEUE_OP_RECV;
-
- rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1,
- &bytesRead, &dwFlags,
- &op_key_rec->overlapped.overlapped, NULL);
- if (rc == SOCKET_ERROR) {
- DWORD dwStatus = WSAGetLastError();
- if (dwStatus!=WSA_IO_PENDING) {
- *length = -1;
- return PJ_STATUS_FROM_OS(dwStatus);
- }
- }
-
- /* Pending operation has been scheduled. */
- return PJ_EPENDING;
+{ + /* + * Ideally we should just call pj_ioqueue_recvfrom() with NULL addr and + * addrlen here. But unfortunately it generates EINVAL... :-( + * -bennylp + */ + int rc; + DWORD bytesRead; + DWORD dwFlags = 0; + union operation_key *op_key_rec; + + PJ_CHECK_STACK(); + PJ_ASSERT_RETURN(key && op_key && buffer && length, PJ_EINVAL); + + op_key_rec = (union operation_key*)op_key->internal__; + op_key_rec->overlapped.wsabuf.buf = buffer; + op_key_rec->overlapped.wsabuf.len = *length; + + dwFlags = flags; + + /* Try non-overlapped received first to see if data is + * immediately available. + */ + rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesRead, &dwFlags, NULL, NULL); + if (rc == 0) { + *length = bytesRead; + return PJ_SUCCESS; + } else { + DWORD dwError = WSAGetLastError(); + if (dwError != WSAEWOULDBLOCK) { + *length = -1; + return PJ_RETURN_OS_ERROR(dwError); + } + } + + /* + * No immediate data available. + * Register overlapped Recv() operation. + */ + pj_memset(&op_key_rec->overlapped.overlapped, 0, + sizeof(op_key_rec->overlapped.overlapped)); + op_key_rec->overlapped.operation = PJ_IOQUEUE_OP_RECV; + + rc = WSARecv((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesRead, &dwFlags, + &op_key_rec->overlapped.overlapped, NULL); + if (rc == SOCKET_ERROR) { + DWORD dwStatus = WSAGetLastError(); + if (dwStatus!=WSA_IO_PENDING) { + *length = -1; + return PJ_STATUS_FROM_OS(dwStatus); + } + } + + /* Pending operation has been scheduled. */ + return PJ_EPENDING; } /* @@ -570,7 +578,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_recv( pj_ioqueue_key_t *key, * * Initiate overlapped RecvFrom() operation. */ -PJ_DEF(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key,
+PJ_DEF(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, void *buffer, pj_ssize_t *length, @@ -578,57 +586,57 @@ PJ_DEF(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key, pj_sockaddr_t *addr, int *addrlen) { - int rc;
- DWORD bytesRead;
- DWORD dwFlags = 0;
- union operation_key *op_key_rec;
-
- PJ_CHECK_STACK();
- PJ_ASSERT_RETURN(key && op_key && buffer, PJ_EINVAL);
-
- op_key_rec = (union operation_key*)op_key->internal__;
- op_key_rec->overlapped.wsabuf.buf = buffer;
- op_key_rec->overlapped.wsabuf.len = *length;
-
- dwFlags = flags;
-
- /* Try non-overlapped received first to see if data is
- * immediately available.
- */
- rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1,
- &bytesRead, &dwFlags, addr, addrlen, NULL, NULL);
- if (rc == 0) {
- *length = bytesRead;
- return PJ_SUCCESS;
- } else {
- DWORD dwError = WSAGetLastError();
- if (dwError != WSAEWOULDBLOCK) {
- *length = -1;
- return PJ_RETURN_OS_ERROR(dwError);
- }
- }
-
- /*
- * No immediate data available.
- * Register overlapped Recv() operation.
- */
- pj_memset(&op_key_rec->overlapped.overlapped, 0,
- sizeof(op_key_rec->overlapped.overlapped));
- op_key_rec->overlapped.operation = PJ_IOQUEUE_OP_RECV;
-
- rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1,
- &bytesRead, &dwFlags, addr, addrlen,
- &op_key_rec->overlapped.overlapped, NULL);
- if (rc == SOCKET_ERROR) {
- DWORD dwStatus = WSAGetLastError();
- if (dwStatus!=WSA_IO_PENDING) {
- *length = -1;
- return PJ_STATUS_FROM_OS(dwStatus);
- }
- }
-
- /* Pending operation has been scheduled. */
- return PJ_EPENDING;
+ int rc; + DWORD bytesRead; + DWORD dwFlags = 0; + union operation_key *op_key_rec; + + PJ_CHECK_STACK(); + PJ_ASSERT_RETURN(key && op_key && buffer, PJ_EINVAL); + + op_key_rec = (union operation_key*)op_key->internal__; + op_key_rec->overlapped.wsabuf.buf = buffer; + op_key_rec->overlapped.wsabuf.len = *length; + + dwFlags = flags; + + /* Try non-overlapped received first to see if data is + * immediately available. + */ + rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesRead, &dwFlags, addr, addrlen, NULL, NULL); + if (rc == 0) { + *length = bytesRead; + return PJ_SUCCESS; + } else { + DWORD dwError = WSAGetLastError(); + if (dwError != WSAEWOULDBLOCK) { + *length = -1; + return PJ_RETURN_OS_ERROR(dwError); + } + } + + /* + * No immediate data available. + * Register overlapped Recv() operation. + */ + pj_memset(&op_key_rec->overlapped.overlapped, 0, + sizeof(op_key_rec->overlapped.overlapped)); + op_key_rec->overlapped.operation = PJ_IOQUEUE_OP_RECV; + + rc = WSARecvFrom((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesRead, &dwFlags, addr, addrlen, + &op_key_rec->overlapped.overlapped, NULL); + if (rc == SOCKET_ERROR) { + DWORD dwStatus = WSAGetLastError(); + if (dwStatus!=WSA_IO_PENDING) { + *length = -1; + return PJ_STATUS_FROM_OS(dwStatus); + } + } + + /* Pending operation has been scheduled. */ + return PJ_EPENDING; } /* @@ -636,7 +644,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key, * * Initiate overlapped Send operation. */ -PJ_DEF(pj_status_t) pj_ioqueue_send( pj_ioqueue_key_t *key,
+PJ_DEF(pj_status_t) pj_ioqueue_send( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, const void *data, pj_ssize_t *length, @@ -651,64 +659,64 @@ PJ_DEF(pj_status_t) pj_ioqueue_send( pj_ioqueue_key_t *key, * * Initiate overlapped SendTo operation. */ -PJ_DEF(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_key_t *key,
+PJ_DEF(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, const void *data, pj_ssize_t *length, unsigned flags, const pj_sockaddr_t *addr, int addrlen) -{
- int rc;
- DWORD bytesWritten;
- DWORD dwFlags;
- union operation_key *op_key_rec;
-
- PJ_CHECK_STACK();
- PJ_ASSERT_RETURN(key && op_key && data, PJ_EINVAL);
-
- op_key_rec = (union operation_key*)op_key->internal__;
-
- dwFlags = flags;
-
- /*
- * First try blocking write.
- */
- op_key_rec->overlapped.wsabuf.buf = (void*)data;
- op_key_rec->overlapped.wsabuf.len = *length;
-
- rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1,
- &bytesWritten, dwFlags, addr, addrlen,
- NULL, NULL);
- if (rc == 0) {
- *length = bytesWritten;
- return PJ_SUCCESS;
- } else {
- DWORD dwStatus = WSAGetLastError();
- if (dwStatus != WSAEWOULDBLOCK) {
- *length = -1;
- return PJ_RETURN_OS_ERROR(dwStatus);
- }
- }
-
- /*
- * Data can't be sent immediately.
- * Schedule asynchronous WSASend().
- */
- pj_memset(&op_key_rec->overlapped.overlapped, 0,
- sizeof(op_key_rec->overlapped.overlapped));
- op_key_rec->overlapped.operation = PJ_IOQUEUE_OP_SEND;
-
- rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1,
- &bytesWritten, dwFlags, addr, addrlen,
- &op_key_rec->overlapped.overlapped, NULL);
- if (rc == SOCKET_ERROR) {
- DWORD dwStatus = WSAGetLastError();
- if (dwStatus!=WSA_IO_PENDING)
- return PJ_STATUS_FROM_OS(dwStatus);
- }
-
- /* Asynchronous operation successfully submitted. */
+{ + int rc; + DWORD bytesWritten; + DWORD dwFlags; + union operation_key *op_key_rec; + + PJ_CHECK_STACK(); + PJ_ASSERT_RETURN(key && op_key && data, PJ_EINVAL); + + op_key_rec = (union operation_key*)op_key->internal__; + + dwFlags = flags; + + /* + * First try blocking write. + */ + op_key_rec->overlapped.wsabuf.buf = (void*)data; + op_key_rec->overlapped.wsabuf.len = *length; + + rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesWritten, dwFlags, addr, addrlen, + NULL, NULL); + if (rc == 0) { + *length = bytesWritten; + return PJ_SUCCESS; + } else { + DWORD dwStatus = WSAGetLastError(); + if (dwStatus != WSAEWOULDBLOCK) { + *length = -1; + return PJ_RETURN_OS_ERROR(dwStatus); + } + } + + /* + * Data can't be sent immediately. + * Schedule asynchronous WSASend(). + */ + pj_memset(&op_key_rec->overlapped.overlapped, 0, + sizeof(op_key_rec->overlapped.overlapped)); + op_key_rec->overlapped.operation = PJ_IOQUEUE_OP_SEND; + + rc = WSASendTo((SOCKET)key->hnd, &op_key_rec->overlapped.wsabuf, 1, + &bytesWritten, dwFlags, addr, addrlen, + &op_key_rec->overlapped.overlapped, NULL); + if (rc == SOCKET_ERROR) { + DWORD dwStatus = WSAGetLastError(); + if (dwStatus!=WSA_IO_PENDING) + return PJ_STATUS_FROM_OS(dwStatus); + } + + /* Asynchronous operation successfully submitted. */ return PJ_EPENDING; } @@ -719,69 +727,69 @@ PJ_DEF(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_key_t *key, * * Initiate overlapped accept() operation. */ -PJ_DEF(pj_status_t) pj_ioqueue_accept( pj_ioqueue_key_t *key,
+PJ_DEF(pj_status_t) pj_ioqueue_accept( pj_ioqueue_key_t *key, pj_ioqueue_op_key_t *op_key, pj_sock_t *new_sock, pj_sockaddr_t *local, pj_sockaddr_t *remote, int *addrlen) { - BOOL rc;
+ BOOL rc; DWORD bytesReceived; - pj_status_t status;
- union operation_key *op_key_rec;
+ pj_status_t status; + union operation_key *op_key_rec; SOCKET sock; PJ_CHECK_STACK(); PJ_ASSERT_RETURN(key && op_key && new_sock, PJ_EINVAL); -
- /*
- * See if there is a new connection immediately available.
- */
- sock = WSAAccept((SOCKET)key->hnd, remote, addrlen, NULL, 0);
- if (sock != INVALID_SOCKET) {
- /* Yes! New socket is available! */
- int status;
-
- status = getsockname(sock, local, addrlen);
- if (status != 0) {
- DWORD dwError = WSAGetLastError();
- closesocket(sock);
- return PJ_RETURN_OS_ERROR(dwError);
- }
-
- *new_sock = sock;
- return PJ_SUCCESS;
-
- } else {
- DWORD dwError = WSAGetLastError();
- if (dwError != WSAEWOULDBLOCK) {
- return PJ_RETURN_OS_ERROR(dwError);
- }
- }
-
- /*
- * No connection is immediately available.
- * Must schedule an asynchronous operation.
- */
- op_key_rec = (union operation_key*)op_key->internal__;
+ + /* + * See if there is a new connection immediately available. + */ + sock = WSAAccept((SOCKET)key->hnd, remote, addrlen, NULL, 0); + if (sock != INVALID_SOCKET) { + /* Yes! New socket is available! */ + int status; + + status = getsockname(sock, local, addrlen); + if (status != 0) { + DWORD dwError = WSAGetLastError(); + closesocket(sock); + return PJ_RETURN_OS_ERROR(dwError); + } + + *new_sock = sock; + return PJ_SUCCESS; + + } else { + DWORD dwError = WSAGetLastError(); + if (dwError != WSAEWOULDBLOCK) { + return PJ_RETURN_OS_ERROR(dwError); + } + } + + /* + * No connection is immediately available. + * Must schedule an asynchronous operation. + */ + op_key_rec = (union operation_key*)op_key->internal__; - status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0,
+ status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, &op_key_rec->accept.newsock); if (status != PJ_SUCCESS) return status; -
- /* On WinXP or later, use SO_UPDATE_ACCEPT_CONTEXT so that socket
- * addresses can be obtained with getsockname() and getpeername().
- */
- status = setsockopt(op_key_rec->accept.newsock, SOL_SOCKET,
- SO_UPDATE_ACCEPT_CONTEXT,
- (char*)&key->hnd, sizeof(SOCKET));
- /* SO_UPDATE_ACCEPT_CONTEXT is for WinXP or later.
- * So ignore the error status.
- */
-
- op_key_rec->accept.operation = PJ_IOQUEUE_OP_ACCEPT;
+ + /* On WinXP or later, use SO_UPDATE_ACCEPT_CONTEXT so that socket + * addresses can be obtained with getsockname() and getpeername(). + */ + status = setsockopt(op_key_rec->accept.newsock, SOL_SOCKET, + SO_UPDATE_ACCEPT_CONTEXT, + (char*)&key->hnd, sizeof(SOCKET)); + /* SO_UPDATE_ACCEPT_CONTEXT is for WinXP or later. + * So ignore the error status. + */ + + op_key_rec->accept.operation = PJ_IOQUEUE_OP_ACCEPT; op_key_rec->accept.addrlen = addrlen; op_key_rec->accept.local = local; op_key_rec->accept.remote = remote; @@ -802,9 +810,9 @@ PJ_DEF(pj_status_t) pj_ioqueue_accept( pj_ioqueue_key_t *key, DWORD dwStatus = WSAGetLastError(); if (dwStatus!=WSA_IO_PENDING) return PJ_STATUS_FROM_OS(dwStatus); - }
-
- /* Asynchronous Accept() has been submitted. */
+ } + + /* Asynchronous Accept() has been submitted. */ return PJ_EPENDING; } @@ -819,11 +827,11 @@ PJ_DEF(pj_status_t) pj_ioqueue_connect( pj_ioqueue_key_t *key, const pj_sockaddr_t *addr, int addrlen ) { - HANDLE hEvent;
+ HANDLE hEvent; pj_ioqueue_t *ioqueue; PJ_CHECK_STACK(); - PJ_ASSERT_RETURN(key && addr && addrlen, PJ_EINVAL);
+ PJ_ASSERT_RETURN(key && addr && addrlen, PJ_EINVAL); /* Initiate connect() */ if (connect((pj_sock_t)key->hnd, addr, addrlen) != 0) { @@ -836,8 +844,8 @@ PJ_DEF(pj_status_t) pj_ioqueue_connect( pj_ioqueue_key_t *key, /* Connect has completed immediately! */ return PJ_SUCCESS; } -
- ioqueue = key->ioqueue;
+ + ioqueue = key->ioqueue; /* Add to the array of connecting socket to be polled */ pj_lock_acquire(ioqueue->lock); diff --git a/pjlib/src/pjlib-test/echo_clt.c b/pjlib/src/pjlib-test/echo_clt.c index 169b6dc2..737a1f59 100644 --- a/pjlib/src/pjlib-test/echo_clt.c +++ b/pjlib/src/pjlib-test/echo_clt.c @@ -41,6 +41,9 @@ static int echo_client_thread(void *arg) pj_sockaddr_in addr; pj_str_t s; pj_status_t rc; + pj_uint32_t buffer_id; + pj_uint32_t buffer_counter; + pj_uint32_t timeout_counter=0, invalid_counter=0; struct client *client = arg; pj_status_t last_recv_err = PJ_SUCCESS, last_send_err = PJ_SUCCESS; unsigned counter = 0; @@ -77,14 +80,24 @@ static int echo_client_thread(void *arg) //PJ_LOG(3,("", "...thread %p running", pj_thread_this())); + buffer_id = (pj_uint32_t) pj_thread_this(); + buffer_counter = 0; + + *(pj_uint32_t*)send_buf = buffer_id; + for (;;) { int rc; pj_ssize_t bytes; + pj_uint32_t *p_buffer_id, *p_buffer_counter; ++counter; + while (wait_socket(sock,0) > 0) + ; + /* Send a packet. */ bytes = BUF_SIZE; + *(pj_uint32_t*)(send_buf+4) = ++buffer_counter; rc = pj_sock_send(sock, send_buf, &bytes, 0); if (rc != PJ_SUCCESS || bytes != BUF_SIZE) { if (rc != last_send_err) { @@ -100,6 +113,7 @@ static int echo_client_thread(void *arg) if (rc == 0) { PJ_LOG(3,("", "...timeout")); bytes = 0; + timeout_counter++; } else if (rc < 0) { rc = pj_get_netos_error(); app_perror("...select() error", rc); diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c index b65fa9e7..52ed0617 100644 --- a/pjlib/src/pjlib-test/test.c +++ b/pjlib/src/pjlib-test/test.c @@ -30,10 +30,10 @@ int test_inner(void) int rc = 0; mem = &caching_pool.factory; -
- pj_log_set_level(3);
- pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME |
- PJ_LOG_HAS_MICRO_SEC);
+ + pj_log_set_level(3); + pj_log_set_decor(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_TIME | + PJ_LOG_HAS_MICRO_SEC); rc = pj_init(); if (rc != 0) { @@ -123,14 +123,14 @@ int test_inner(void) #if PJ_HAS_TCP && INCLUDE_TCP_IOQUEUE_TEST DO_TEST( tcp_ioqueue_test() ); #endif -
-#if INCLUDE_IOQUEUE_PERF_TEST
- DO_TEST( ioqueue_perf_test() );
-#endif
-
-#if INCLUDE_FILE_TEST
- DO_TEST( file_test() );
-#endif
+ +#if INCLUDE_IOQUEUE_PERF_TEST + DO_TEST( ioqueue_perf_test() ); +#endif + +#if INCLUDE_FILE_TEST + DO_TEST( file_test() ); +#endif #if INCLUDE_XML_TEST DO_TEST( xml_test() ); @@ -138,8 +138,8 @@ int test_inner(void) #if INCLUDE_ECHO_SERVER //echo_server(); - //echo_srv_sync();
- udp_echo_srv_ioqueue();
+ //echo_srv_sync(); + udp_echo_srv_ioqueue(); #elif INCLUDE_ECHO_CLIENT if (param_echo_sock_type == 0) diff --git a/pjlib/src/pjlib-test/test.h b/pjlib/src/pjlib-test/test.h index b16aff69..b6da599d 100644 --- a/pjlib/src/pjlib-test/test.h +++ b/pjlib/src/pjlib-test/test.h @@ -8,8 +8,8 @@ #define GROUP_LIBC 0 #define GROUP_OS 0 #define GROUP_DATA_STRUCTURE 0 -#define GROUP_NETWORK 0
-#define GROUP_FILE 1 +#define GROUP_NETWORK 0 +#define GROUP_FILE 0 #define GROUP_EXTRA 0 #define INCLUDE_ERRNO_TEST GROUP_LIBC @@ -31,16 +31,16 @@ #define INCLUDE_SOCK_PERF_TEST GROUP_NETWORK #define INCLUDE_SELECT_TEST GROUP_NETWORK #define INCLUDE_UDP_IOQUEUE_TEST GROUP_NETWORK -#define INCLUDE_TCP_IOQUEUE_TEST GROUP_NETWORK
-#define INCLUDE_IOQUEUE_PERF_TEST GROUP_NETWORK
+#define INCLUDE_TCP_IOQUEUE_TEST GROUP_NETWORK +#define INCLUDE_IOQUEUE_PERF_TEST GROUP_NETWORK #define INCLUDE_FILE_TEST GROUP_FILE #define INCLUDE_XML_TEST GROUP_EXTRA -#define INCLUDE_ECHO_SERVER 0 +#define INCLUDE_ECHO_SERVER 1 #define INCLUDE_ECHO_CLIENT 0 -
-#define ECHO_SERVER_MAX_THREADS 4 + +#define ECHO_SERVER_MAX_THREADS 2 #define ECHO_SERVER_START_PORT 65000 #define ECHO_SERVER_ADDRESS "compaq.home" #define ECHO_SERVER_DURATION_MSEC (60*60*1000) @@ -68,17 +68,17 @@ extern int sock_test(void); extern int sock_perf_test(void); extern int select_test(void); extern int udp_ioqueue_test(void); -extern int tcp_ioqueue_test(void);
-extern int ioqueue_perf_test(void);
+extern int tcp_ioqueue_test(void); +extern int ioqueue_perf_test(void); extern int file_test(void); extern int xml_test(void); extern int echo_server(void); extern int echo_client(int sock_type, const char *server, int port); -
-extern int echo_srv_sync(void);
-extern int udp_echo_srv_ioqueue(void);
-extern int echo_srv_common_loop(pj_atomic_t *bytes_counter);
+ +extern int echo_srv_sync(void); +extern int udp_echo_srv_ioqueue(void); +extern int echo_srv_common_loop(pj_atomic_t *bytes_counter); extern pj_pool_factory *mem; diff --git a/pjlib/src/pjlib-test/udp_echo_srv_sync.c b/pjlib/src/pjlib-test/udp_echo_srv_sync.c index 19ee702c..7f371709 100644 --- a/pjlib/src/pjlib-test/udp_echo_srv_sync.c +++ b/pjlib/src/pjlib-test/udp_echo_srv_sync.c @@ -3,7 +3,7 @@ #include "test.h" #include <pjlib.h> -static pj_atomic_t *total_bytes;
+static pj_atomic_t *total_bytes; static int worker_thread(void *arg) { @@ -47,7 +47,7 @@ int echo_srv_sync(void) pj_pool_t *pool; pj_sock_t sock; pj_thread_t *thread[ECHO_SERVER_MAX_THREADS]; - pj_status_t rc;
+ pj_status_t rc; int i; pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); @@ -60,7 +60,7 @@ int echo_srv_sync(void) return -6; } - rc = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, ECHO_SERVER_START_PORT, &sock); + rc = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM,0, ECHO_SERVER_START_PORT, &sock); if (rc != PJ_SUCCESS) { app_perror("...socket error", rc); return -10; @@ -80,64 +80,64 @@ int echo_srv_sync(void) ECHO_SERVER_MAX_THREADS, ECHO_SERVER_START_PORT)); PJ_LOG(3,("", "...Press Ctrl-C to abort")); - echo_srv_common_loop(total_bytes);
+ echo_srv_common_loop(total_bytes); return 0; } -int echo_srv_common_loop(pj_atomic_t *bytes_counter)
-{
- pj_highprec_t last_received, avg_bw, highest_bw;
- pj_time_val last_print;
- unsigned count;
-
- last_received = 0;
- pj_gettimeofday(&last_print);
- avg_bw = highest_bw = 0;
- count = 0;
-
- for (;;) {
- pj_highprec_t received, cur_received, bw;
- unsigned msec;
- pj_time_val now, duration;
-
- pj_thread_sleep(1000);
-
- received = cur_received = pj_atomic_get(bytes_counter);
- cur_received = cur_received - last_received;
-
- pj_gettimeofday(&now);
- duration = now;
- PJ_TIME_VAL_SUB(duration, last_print);
- msec = PJ_TIME_VAL_MSEC(duration);
-
- bw = cur_received;
- pj_highprec_mul(bw, 1000);
- pj_highprec_div(bw, msec);
-
- last_print = now;
- last_received = received;
-
- avg_bw = avg_bw + bw;
- count++;
-
- PJ_LOG(3,("", "Synchronous UDP (%d threads): %u KB/s (avg=%u KB/s) %s",
- ECHO_SERVER_MAX_THREADS,
- (unsigned)(bw / 1000),
- (unsigned)(avg_bw / count / 1000),
- (count==20 ? "<ses avg>" : "")));
-
- if (count==20) {
- if (avg_bw/count > highest_bw)
- highest_bw = avg_bw/count;
-
- count = 0;
- avg_bw = 0;
-
- PJ_LOG(3,("", "Highest average bandwidth=%u KB/s",
- (unsigned)(highest_bw/1000)));
- }
- }
-}
-
-
+int echo_srv_common_loop(pj_atomic_t *bytes_counter) +{ + pj_highprec_t last_received, avg_bw, highest_bw; + pj_time_val last_print; + unsigned count; + + last_received = 0; + pj_gettimeofday(&last_print); + avg_bw = highest_bw = 0; + count = 0; + + for (;;) { + pj_highprec_t received, cur_received, bw; + unsigned msec; + pj_time_val now, duration; + + pj_thread_sleep(1000); + + received = cur_received = pj_atomic_get(bytes_counter); + cur_received = cur_received - last_received; + + pj_gettimeofday(&now); + duration = now; + PJ_TIME_VAL_SUB(duration, last_print); + msec = PJ_TIME_VAL_MSEC(duration); + + bw = cur_received; + pj_highprec_mul(bw, 1000); + pj_highprec_div(bw, msec); + + last_print = now; + last_received = received; + + avg_bw = avg_bw + bw; + count++; + + PJ_LOG(3,("", "Synchronous UDP (%d threads): %u KB/s (avg=%u KB/s) %s", + ECHO_SERVER_MAX_THREADS, + (unsigned)(bw / 1000), + (unsigned)(avg_bw / count / 1000), + (count==20 ? "<ses avg>" : ""))); + + if (count==20) { + if (avg_bw/count > highest_bw) + highest_bw = avg_bw/count; + + count = 0; + avg_bw = 0; + + PJ_LOG(3,("", "Highest average bandwidth=%u KB/s", + (unsigned)(highest_bw/1000))); + } + } +} + + |