summaryrefslogtreecommitdiff
path: root/pjlib/src/pjlib-test/ioq_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'pjlib/src/pjlib-test/ioq_tcp.c')
-rw-r--r--pjlib/src/pjlib-test/ioq_tcp.c142
1 files changed, 72 insertions, 70 deletions
diff --git a/pjlib/src/pjlib-test/ioq_tcp.c b/pjlib/src/pjlib-test/ioq_tcp.c
index 14813c79..22827942 100644
--- a/pjlib/src/pjlib-test/ioq_tcp.c
+++ b/pjlib/src/pjlib-test/ioq_tcp.c
@@ -38,37 +38,37 @@ static pj_ssize_t callback_read_size,
static pj_ioqueue_key_t *callback_read_key,
*callback_write_key,
*callback_accept_key,
- *callback_connect_key;
-static pj_ioqueue_op_key_t *callback_read_op,
- *callback_write_op,
+ *callback_connect_key;
+static pj_ioqueue_op_key_t *callback_read_op,
+ *callback_write_op,
*callback_accept_op;
-static void on_ioqueue_read(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_read(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_read)
{
- callback_read_key = key;
+ callback_read_key = key;
callback_read_op = op_key;
callback_read_size = bytes_read;
}
-static void on_ioqueue_write(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_write(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_ssize_t bytes_written)
{
- callback_write_key = key;
+ callback_write_key = key;
callback_write_op = op_key;
callback_write_size = bytes_written;
}
-static void on_ioqueue_accept(pj_ioqueue_key_t *key,
- pj_ioqueue_op_key_t *op_key,
+static void on_ioqueue_accept(pj_ioqueue_key_t *key,
+ pj_ioqueue_op_key_t *op_key,
pj_sock_t sock,
int status)
{
PJ_UNUSED_ARG(sock);
- callback_accept_key = key;
+ callback_accept_key = key;
callback_accept_op = op_key;
callback_accept_status = status;
}
@@ -96,31 +96,31 @@ static int send_recv_test(pj_ioqueue_t *ioque,
pj_timestamp *t_elapsed)
{
pj_status_t status;
- pj_ssize_t bytes;
+ pj_ssize_t bytes;
pj_time_val timeout;
pj_timestamp t1, t2;
- int pending_op = 0;
+ int pending_op = 0;
pj_ioqueue_op_key_t read_op, write_op;
- // Start reading on the server side.
+ // Start reading on the server side.
bytes = bufsize;
status = pj_ioqueue_recv(skey, &read_op, recv_buf, &bytes, 0);
- if (status != PJ_SUCCESS && status != PJ_EPENDING) {
+ if (status != PJ_SUCCESS && status != PJ_EPENDING) {
app_perror("...pj_ioqueue_recv error", status);
return -100;
}
-
+
if (status == PJ_EPENDING)
- ++pending_op;
- else {
- /* Does not expect to return error or immediate data. */
- return -115;
+ ++pending_op;
+ else {
+ /* Does not expect to return error or immediate data. */
+ return -115;
}
// Randomize send buffer.
pj_create_random_string((char*)send_buf, bufsize);
- // Starts send on the client side.
+ // Starts send on the client side.
bytes = bufsize;
status = pj_ioqueue_send(ckey, &write_op, send_buf, &bytes, 0);
if (status != PJ_SUCCESS && bytes != PJ_EPENDING) {
@@ -135,12 +135,12 @@ static int send_recv_test(pj_ioqueue_t *ioque,
// Reset indicators
callback_read_size = callback_write_size = 0;
- callback_read_key = callback_write_key = NULL;
+ callback_read_key = callback_write_key = NULL;
callback_read_op = callback_write_op = NULL;
// Poll the queue until we've got completion event in the server side.
status = 0;
- while (pending_op > 0) {
+ while (pending_op > 0) {
timeout.sec = 1; timeout.msec = 0;
status = pj_ioqueue_poll(ioque, &timeout);
if (status > 0) {
@@ -148,32 +148,32 @@ static int send_recv_test(pj_ioqueue_t *ioque,
if (callback_read_size != bufsize)
return -160;
if (callback_read_key != skey)
- return -161;
- if (callback_read_op != &read_op)
+ return -161;
+ if (callback_read_op != &read_op)
return -162;
}
if (callback_write_size) {
if (callback_write_key != ckey)
- return -163;
- if (callback_write_op != &write_op)
+ return -163;
+ if (callback_write_op != &write_op)
return -164;
}
pending_op -= status;
- }
- if (status == 0) {
- PJ_LOG(3,("", "...error: timed out"));
+ }
+ if (status == 0) {
+ PJ_LOG(3,("", "...error: timed out"));
}
if (status < 0) {
return -170;
}
}
-
- // Pending op is zero.
- // Subsequent poll should yield zero too.
- timeout.sec = timeout.msec = 0;
- status = pj_ioqueue_poll(ioque, &timeout);
- if (status != 0)
- return -173;
+
+ // Pending op is zero.
+ // Subsequent poll should yield zero too.
+ timeout.sec = timeout.msec = 0;
+ status = pj_ioqueue_poll(ioque, &timeout);
+ if (status != 0)
+ return -173;
// End time.
pj_get_timestamp(&t2);
@@ -200,7 +200,7 @@ static int compliance_test_0(void)
pj_pool_t *pool = NULL;
char *send_buf, *recv_buf;
pj_ioqueue_t *ioque = NULL;
- pj_ioqueue_key_t *skey, *ckey0, *ckey1;
+ pj_ioqueue_key_t *skey, *ckey0, *ckey1;
pj_ioqueue_op_key_t accept_op;
int bufsize = BUF_MIN_SIZE;
pj_ssize_t status = -1;
@@ -265,7 +265,7 @@ static int compliance_test_0(void)
// Server socket accept()
client_addr_len = sizeof(pj_sockaddr_in);
- status = pj_ioqueue_accept(skey, &accept_op, &csock0,
+ status = pj_ioqueue_accept(skey, &accept_op, &csock0,
&client_addr, &rmt_addr, &client_addr_len);
if (status != PJ_EPENDING) {
app_perror("...ERROR in pj_ioqueue_accept()", rc);
@@ -297,7 +297,7 @@ static int compliance_test_0(void)
callback_read_key = callback_write_key =
callback_accept_key = callback_connect_key = NULL;
- callback_accept_op = callback_read_op = callback_write_op = NULL;
+ callback_accept_op = callback_read_op = callback_write_op = NULL;
while (pending_op) {
pj_time_val timeout = {1, 0};
@@ -310,10 +310,10 @@ static int compliance_test_0(void)
}
if (callback_accept_key != skey) {
status=-42; goto on_error;
- }
- if (callback_accept_op != &accept_op) {
- status=-43; goto on_error;
- }
+ }
+ if (callback_accept_op != &accept_op) {
+ status=-43; goto on_error;
+ }
callback_accept_status = -2;
}
@@ -323,7 +323,7 @@ static int compliance_test_0(void)
}
if (callback_connect_key != ckey1) {
status=-51; goto on_error;
- }
+ }
callback_connect_status = -2;
}
@@ -334,16 +334,16 @@ static int compliance_test_0(void)
}
}
}
-
- // There's no pending operation.
- // When we poll the ioqueue, there must not be events.
- if (pending_op == 0) {
- pj_time_val timeout = {1, 0};
- status = pj_ioqueue_poll(ioque, &timeout);
- if (status != 0) {
- status=-60; goto on_error;
- }
- }
+
+ // There's no pending operation.
+ // When we poll the ioqueue, there must not be events.
+ if (pending_op == 0) {
+ pj_time_val timeout = {1, 0};
+ status = pj_ioqueue_poll(ioque, &timeout);
+ if (status != 0) {
+ status=-60; goto on_error;
+ }
+ }
// Check accepted socket.
if (csock0 == PJ_INVALID_SOCKET) {
@@ -363,7 +363,7 @@ static int compliance_test_0(void)
// Test send and receive.
t_elapsed.u32.lo = 0;
- status = send_recv_test(ioque, ckey0, ckey1, send_buf,
+ status = send_recv_test(ioque, ckey0, ckey1, send_buf,
recv_buf, bufsize, &t_elapsed);
if (status != 0) {
goto on_error;
@@ -468,17 +468,17 @@ static int compliance_test_1(void)
}
}
}
-
- // There's no pending operation.
- // When we poll the ioqueue, there must not be events.
- if (pending_op == 0) {
- pj_time_val timeout = {1, 0};
- status = pj_ioqueue_poll(ioque, &timeout);
- if (status != 0) {
- status=-60; goto on_error;
- }
- }
-
+
+ // There's no pending operation.
+ // When we poll the ioqueue, there must not be events.
+ if (pending_op == 0) {
+ pj_time_val timeout = {1, 0};
+ status = pj_ioqueue_poll(ioque, &timeout);
+ if (status != 0) {
+ status=-60; goto on_error;
+ }
+ }
+
// Success
status = 0;
@@ -495,12 +495,14 @@ int tcp_ioqueue_test()
{
int status;
- PJ_LOG(3, (THIS_FILE, "..compliance test 0 (success scenario)"));
+ PJ_LOG(3, (THIS_FILE, "..%s compliance test 0 (success scenario)",
+ pj_ioqueue_name()));
if ((status=compliance_test_0()) != 0) {
PJ_LOG(1, (THIS_FILE, "....FAILED (status=%d)\n", status));
return status;
}
- PJ_LOG(3, (THIS_FILE, "..compliance test 1 (failed scenario)"));
+ PJ_LOG(3, (THIS_FILE, "..%s compliance test 1 (failed scenario)",
+ pj_ioqueue_name()));
if ((status=compliance_test_1()) != 0) {
PJ_LOG(1, (THIS_FILE, "....FAILED (status=%d)\n", status));
return status;