#include "test.h"
#if INCLUDE_SELECT_TEST
enum
{
READ_FDS,
WRITE_FDS,
EXCEPT_FDS
};
#define UDP_PORT 51232
#define THIS_FILE "select_test"
int setcount[])
{
int i, n;
for (i=0; i<3; ++i) {
setcount[i] = 0;
}
&timeout);
if (n < 0)
return n;
if (n == 0)
return 0;
for (i=0; i<3; ++i) {
setcount[i]++;
setcount[i]++;
}
return n;
}
int select_test()
{
int status;
int setcount[3];
const char data[] = "hello";
const int datalen = 5;
char buf[10];
PJ_LOG(3, (THIS_FILE,
"...Testing simple UDP select()"));
app_perror("...error: unable to create socket", rc);
status=-10; goto on_return;
}
app_perror("...error: unable to create socket", rc);
status=-20; goto on_return;
}
status=-30; goto on_return;
}
sent = datalen;
rc =
pj_sock_sendto(udp1, data, &sent, 0, &udp_addr,
sizeof(udp_addr));
app_perror("...error: sendto() error", rc);
status=-40; goto on_return;
}
status = do_select(udp1, udp2, setcount);
if (status < 0) {
char errbuf[128];
PJ_LOG(1,(THIS_FILE,
"...error: %s", errbuf));
status=-50; goto on_return;
}
if (status == 0) {
status=-60; goto on_return;
}
if (setcount[READ_FDS] != 1) {
status=-70; goto on_return;
}
if (setcount[WRITE_FDS] != 0) {
if (setcount[WRITE_FDS] == 2) {
PJ_LOG(3,(THIS_FILE,
"...info: system reports writable sockets"));
} else {
status=-80; goto on_return;
}
} else {
"...info: system doesn't report writable sockets"));
}
if (setcount[EXCEPT_FDS] != 0) {
status=-90; goto on_return;
}
received = sizeof(buf);
status=-100; goto on_return;
}
status = 0;
setcount[0] = setcount[1] = setcount[2] = 0;
status = do_select(udp1, udp2, setcount);
if (status != 0 && status != setcount[WRITE_FDS]) {
PJ_LOG(3,(THIS_FILE,
"...error: expecting timeout but got %d sks set",
status));
PJ_LOG(3,(THIS_FILE,
" rdset: %d, wrset: %d, exset: %d",
setcount[0], setcount[1], setcount[2]));
status = -110; goto on_return;
}
if (setcount[READ_FDS] != 0) {
PJ_LOG(3,(THIS_FILE,
"...error: readable socket not expected"));
status = -120; goto on_return;
}
status = 0;
on_return:
return status;
}
#else
int dummy_select_test;
#endif
Assertion macro pj_assert().
long pj_ssize_t
Definition: types.h:64
long pj_sock_t
Definition: types.h:263
int pj_status_t
Definition: types.h:68
@ PJ_SUCCESS
Definition: types.h:93
#define PJ_LOG(level, arg)
Definition: log.h:106
const pj_str_t * pj_cstr(pj_str_t *str, const char *s)
Definition: string.h:100
void pj_bzero(void *dst, pj_size_t size)
Definition: string.h:762
void PJ_FD_SET(pj_sock_t fd, pj_fd_set_t *fdsetp)
void PJ_FD_ZERO(pj_fd_set_t *fdsetp)
pj_bool_t PJ_FD_ISSET(pj_sock_t fd, const pj_fd_set_t *fdsetp)
int pj_sock_select(int n, pj_fd_set_t *readfds, pj_fd_set_t *writefds, pj_fd_set_t *exceptfds, const pj_time_val *timeout)
pj_status_t pj_sock_bind(pj_sock_t sockfd, const pj_sockaddr_t *my_addr, int addrlen)
pj_status_t pj_sock_close(pj_sock_t sockfd)
#define pj_AF_INET()
Definition: sock.h:113
pj_status_t pj_sock_sendto(pj_sock_t sockfd, const void *buf, pj_ssize_t *len, unsigned flags, const pj_sockaddr_t *to, int tolen)
#define pj_SOCK_DGRAM()
Definition: sock.h:162
#define PJ_INVALID_SOCKET
Definition: sock.h:485
pj_in_addr pj_inet_addr(const pj_str_t *cp)
pj_status_t pj_sock_socket(int family, int type, int protocol, pj_sock_t *sock)
pj_status_t pj_sock_recv(pj_sock_t sockfd, void *buf, pj_ssize_t *len, unsigned flags)
pj_status_t pj_thread_sleep(unsigned msec)
#define PJ_IOQUEUE_MAX_HANDLES
Definition: config.h:681
pj_str_t pj_strerror(pj_status_t statcode, char *buf, pj_size_t bufsize)
pj_status_t pj_get_netos_error(void)
Definition: sock_select.h:56
pj_uint16_t sin_port
Definition: sock.h:541
pj_uint16_t sin_family
Definition: sock.h:539
pj_in_addr sin_addr
Definition: sock.h:542
long msec
Definition: types.h:402
long sec
Definition: types.h:399