summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/tests/socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/tests/socket.c')
-rw-r--r--nsprpub/pr/tests/socket.c1162
1 files changed, 563 insertions, 599 deletions
diff --git a/nsprpub/pr/tests/socket.c b/nsprpub/pr/tests/socket.c
index 92f019d01..a4925350c 100644
--- a/nsprpub/pr/tests/socket.c
+++ b/nsprpub/pr/tests/socket.c
@@ -44,36 +44,32 @@ static int test_cancelio = 0;
char *TEST_DIR = "prdir";
char *SMALL_FILE_NAME = "prsmallf";
char *LARGE_FILE_NAME = "prlargef";
-#elif defined(SYMBIAN)
-char *TEST_DIR = "c:\\data\\prsocket";
-char *SMALL_FILE_NAME = "c:\\data\\prsocket\\small_file";
-char *LARGE_FILE_NAME = "c:\\data\\prsocket\\large_file";
#else
char *TEST_DIR = "/tmp/prsocket_test_dir";
char *SMALL_FILE_NAME = "/tmp/prsocket_test_dir/small_file";
char *LARGE_FILE_NAME = "/tmp/prsocket_test_dir/large_file";
#endif
-#define SMALL_FILE_SIZE (3 * 1024) /* 3 KB */
-#define SMALL_FILE_OFFSET_1 (512)
-#define SMALL_FILE_LEN_1 (1 * 1024) /* 1 KB */
-#define SMALL_FILE_OFFSET_2 (75)
-#define SMALL_FILE_LEN_2 (758)
-#define SMALL_FILE_OFFSET_3 (1024)
-#define SMALL_FILE_LEN_3 (SMALL_FILE_SIZE - SMALL_FILE_OFFSET_3)
-#define SMALL_FILE_HEADER_SIZE (64) /* 64 bytes */
-#define SMALL_FILE_TRAILER_SIZE (128) /* 128 bytes */
-
-#define LARGE_FILE_SIZE (3 * 1024 * 1024) /* 3 MB */
-#define LARGE_FILE_OFFSET_1 (0)
-#define LARGE_FILE_LEN_1 (2 * 1024 * 1024) /* 2 MB */
-#define LARGE_FILE_OFFSET_2 (64)
-#define LARGE_FILE_LEN_2 (1 * 1024 * 1024 + 75)
-#define LARGE_FILE_OFFSET_3 (2 * 1024 * 1024 - 128)
-#define LARGE_FILE_LEN_3 (LARGE_FILE_SIZE - LARGE_FILE_OFFSET_3)
-#define LARGE_FILE_OFFSET_4 PR_GetPageSize()
-#define LARGE_FILE_LEN_4 769
-#define LARGE_FILE_HEADER_SIZE (512)
-#define LARGE_FILE_TRAILER_SIZE (64)
+#define SMALL_FILE_SIZE (3 * 1024) /* 3 KB */
+#define SMALL_FILE_OFFSET_1 (512)
+#define SMALL_FILE_LEN_1 (1 * 1024) /* 1 KB */
+#define SMALL_FILE_OFFSET_2 (75)
+#define SMALL_FILE_LEN_2 (758)
+#define SMALL_FILE_OFFSET_3 (1024)
+#define SMALL_FILE_LEN_3 (SMALL_FILE_SIZE - SMALL_FILE_OFFSET_3)
+#define SMALL_FILE_HEADER_SIZE (64) /* 64 bytes */
+#define SMALL_FILE_TRAILER_SIZE (128) /* 128 bytes */
+
+#define LARGE_FILE_SIZE (3 * 1024 * 1024) /* 3 MB */
+#define LARGE_FILE_OFFSET_1 (0)
+#define LARGE_FILE_LEN_1 (2 * 1024 * 1024) /* 2 MB */
+#define LARGE_FILE_OFFSET_2 (64)
+#define LARGE_FILE_LEN_2 (1 * 1024 * 1024 + 75)
+#define LARGE_FILE_OFFSET_3 (2 * 1024 * 1024 - 128)
+#define LARGE_FILE_LEN_3 (LARGE_FILE_SIZE - LARGE_FILE_OFFSET_3)
+#define LARGE_FILE_OFFSET_4 PR_GetPageSize()
+#define LARGE_FILE_LEN_4 769
+#define LARGE_FILE_HEADER_SIZE (512)
+#define LARGE_FILE_TRAILER_SIZE (64)
#define BUF_DATA_SIZE (2 * 1024)
#define TCP_MESG_SIZE 1024
@@ -82,14 +78,10 @@ char *LARGE_FILE_NAME = "/tmp/prsocket_test_dir/large_file";
* local host will not be lost
*/
#define UDP_DGRAM_SIZE 128
-#define NUM_TCP_CLIENTS 5 /* for a listen queue depth of 5 */
+#define NUM_TCP_CLIENTS 5 /* for a listen queue depth of 5 */
#define NUM_UDP_CLIENTS 10
-#ifdef SYMBIAN
-#define NUM_TRANSMITFILE_CLIENTS 1
-#else
#define NUM_TRANSMITFILE_CLIENTS 4
-#endif
#define NUM_TCP_CONNECTIONS_PER_CLIENT 5
#define NUM_TCP_MESGS_PER_CONNECTION 10
@@ -149,7 +141,7 @@ typedef struct Client_Param {
/* the sendfile method in emuSendFileMethods */
static PRInt32 PR_CALLBACK
emu_SendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
return PR_EmulateSendFile(sd, sfd, flags, timeout);
}
@@ -157,7 +149,7 @@ emu_SendFile(PRFileDesc *sd, PRSendFileData *sfd,
/* the transmitfile method in emuSendFileMethods */
static PRInt32 PR_CALLBACK
emu_TransmitFile(PRFileDesc *sd, PRFileDesc *fd, const void *headers,
- PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout)
{
PRSendFileData sfd;
@@ -181,33 +173,35 @@ readn(PRFileDesc *sockfd, char *buf, int len)
int rem;
int bytes;
int offset = 0;
- int err;
- PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
+ int err;
+ PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
- if (test_cancelio)
- timeout = PR_SecondsToInterval(2);
+ if (test_cancelio) {
+ timeout = PR_SecondsToInterval(2);
+ }
for (rem=len; rem; offset += bytes, rem -= bytes) {
DPRINTF(("thread = 0x%lx: calling PR_Recv, bytes = %d\n",
- PR_GetCurrentThread(), rem));
+ PR_GetCurrentThread(), rem));
retry:
bytes = PR_Recv(sockfd, buf + offset, rem, 0,
- timeout);
+ timeout);
DPRINTF(("thread = 0x%lx: returning from PR_Recv, bytes = %d\n",
- PR_GetCurrentThread(), bytes));
+ PR_GetCurrentThread(), bytes));
if (bytes < 0) {
#ifdef WINNT
- printf("PR_Recv: error = %d oserr = %d\n",(err = PR_GetError()),
- PR_GetOSError());
- if ((test_cancelio) && (err == PR_IO_TIMEOUT_ERROR)) {
- if (PR_NT_CancelIo(sockfd) != PR_SUCCESS)
- printf("PR_NT_CancelIO: error = %d\n",PR_GetError());
- timeout = PR_INTERVAL_NO_TIMEOUT;
- goto retry;
- }
+ printf("PR_Recv: error = %d oserr = %d\n",(err = PR_GetError()),
+ PR_GetOSError());
+ if ((test_cancelio) && (err == PR_IO_TIMEOUT_ERROR)) {
+ if (PR_NT_CancelIo(sockfd) != PR_SUCCESS) {
+ printf("PR_NT_CancelIO: error = %d\n",PR_GetError());
+ }
+ timeout = PR_INTERVAL_NO_TIMEOUT;
+ goto retry;
+ }
#endif
- return -1;
- }
+ return -1;
+ }
}
return len;
}
@@ -225,13 +219,14 @@ writen(PRFileDesc *sockfd, char *buf, int len)
for (rem=len; rem; offset += bytes, rem -= bytes) {
DPRINTF(("thread = 0x%lx: calling PR_Send, bytes = %d\n",
- PR_GetCurrentThread(), rem));
+ PR_GetCurrentThread(), rem));
bytes = PR_Send(sockfd, buf + offset, rem, 0,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
DPRINTF(("thread = 0x%lx: returning from PR_Send, bytes = %d\n",
- PR_GetCurrentThread(), bytes));
- if (bytes <= 0)
+ PR_GetCurrentThread(), bytes));
+ if (bytes <= 0) {
return -1;
+ }
}
return len;
}
@@ -270,7 +265,6 @@ Serve_Client(void *arg)
goto exit;
}
/* Shutdown only RCV will cause error on Symbian OS */
-#if !defined(SYMBIAN)
/*
* shutdown reads, after the last read
*/
@@ -278,9 +272,8 @@ Serve_Client(void *arg)
if (PR_Shutdown(sockfd, PR_SHUTDOWN_RCV) < 0) {
fprintf(stderr,"prsocket_test: ERROR - PR_Shutdown\n");
}
-#endif
DPRINTF(("Serve_Client [0x%lx]: inbuf[0] = 0x%lx\n",PR_GetCurrentThread(),
- (*((int *) in_buf->data))));
+ (*((int *) in_buf->data))));
if (writen(sockfd, in_buf->data, bytes) < bytes) {
fprintf(stderr,"prsocket_test: ERROR - Serve_Client:writen\n");
failed_already=1;
@@ -303,59 +296,61 @@ exit:
}
PRThread* create_new_thread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize, PRInt32 index)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize, PRInt32 index)
{
-PRInt32 native_thread = 0;
+ PRInt32 native_thread = 0;
- PR_ASSERT(state == PR_UNJOINABLE_THREAD);
+ PR_ASSERT(state == PR_UNJOINABLE_THREAD);
#if defined(_PR_PTHREADS) || defined(WIN32)
- switch(index % 4) {
- case 0:
- scope = (PR_LOCAL_THREAD);
- break;
- case 1:
- scope = (PR_GLOBAL_THREAD);
- break;
- case 2:
- scope = (PR_GLOBAL_BOUND_THREAD);
- break;
- case 3:
- native_thread = 1;
- break;
- default:
- PR_NOT_REACHED("Invalid scope");
- break;
- }
- if (native_thread) {
+ switch(index % 4) {
+ case 0:
+ scope = (PR_LOCAL_THREAD);
+ break;
+ case 1:
+ scope = (PR_GLOBAL_THREAD);
+ break;
+ case 2:
+ scope = (PR_GLOBAL_BOUND_THREAD);
+ break;
+ case 3:
+ native_thread = 1;
+ break;
+ default:
+ PR_NOT_REACHED("Invalid scope");
+ break;
+ }
+ if (native_thread) {
#if defined(_PR_PTHREADS)
- pthread_t tid;
- if (!pthread_create(&tid, NULL, (void * (*)(void *)) start, arg))
- return((PRThread *) tid);
- else
- return (NULL);
+ pthread_t tid;
+ if (!pthread_create(&tid, NULL, (void * (*)(void *)) start, arg)) {
+ return((PRThread *) tid);
+ }
+ else {
+ return (NULL);
+ }
#else
- HANDLE thandle;
- unsigned tid;
-
- thandle = (HANDLE) _beginthreadex(
- NULL,
- stackSize,
- (unsigned (__stdcall *)(void *))start,
- arg,
- STACK_SIZE_PARAM_IS_A_RESERVATION,
- &tid);
- return((PRThread *) thandle);
+ HANDLE thandle;
+ unsigned tid;
+
+ thandle = (HANDLE) _beginthreadex(
+ NULL,
+ stackSize,
+ (unsigned (__stdcall *)(void *))start,
+ arg,
+ STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &tid);
+ return((PRThread *) thandle);
#endif
- } else {
- return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
- }
+ } else {
+ return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
+ }
#else
- return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
+ return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
#endif
}
@@ -377,28 +372,29 @@ TCP_Server(void *arg)
/*
* Create a tcp socket
*/
- if ((sockfd = PR_OpenTCPSocket(server_domain)) == NULL) {
+ if ((sockfd = PR_OpenTCPSocket(server_domain)) == NULL) {
fprintf(stderr,"prsocket_test: PR_NewTCPSocket failed\n");
goto exit;
}
- memset(&netaddr, 0 , sizeof(netaddr));
-
- if (PR_SetNetAddr(PR_IpAddrAny, server_domain, TCP_SERVER_PORT,
- &netaddr) == PR_FAILURE) {
+ memset(&netaddr, 0, sizeof(netaddr));
+
+ if (PR_SetNetAddr(PR_IpAddrAny, server_domain, TCP_SERVER_PORT,
+ &netaddr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
goto exit;
- }
+ }
/*
* try a few times to bind server's address, if addresses are in
* use
*/
i = 0;
-
+
while (PR_Bind(sockfd, &netaddr) < 0) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
perror("PR_Bind");
@@ -419,16 +415,16 @@ TCP_Server(void *arg)
}
DPRINTF(("TCP_Server: PR_BIND netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
- if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
- PR_ntohs(PR_NetAddrInetPort(&netaddr)),
- &tcp_server_addr) == PR_FAILURE) {
+ netaddr.inet.ip, netaddr.inet.port));
+ if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
+ PR_ntohs(PR_NetAddrInetPort(&netaddr)),
+ &tcp_server_addr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
goto exit;
- }
- if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
- PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
- &tcp_server_addr.ipv6.ip);
+ }
+ if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
+ PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
+ &tcp_server_addr.ipv6.ip);
/*
* Wake up parent thread because server address is bound and made
@@ -440,13 +436,13 @@ TCP_Server(void *arg)
/* test both null and non-null 'addr' argument to PR_Accept */
PRNetAddr *addrp = (i%2 ? &netaddr: NULL);
- DPRINTF(("TCP_Server: Accepting connection\n"));
+ DPRINTF(("TCP_Server: Accepting connection\n"));
if ((newsockfd = PR_Accept(sockfd, addrp,
- PR_INTERVAL_NO_TIMEOUT)) == NULL) {
+ PR_INTERVAL_NO_TIMEOUT)) == NULL) {
fprintf(stderr,"prsocket_test: ERROR - PR_Accept failed\n");
goto exit;
}
- DPRINTF(("TCP_Server: Accepted connection\n"));
+ DPRINTF(("TCP_Server: Accepted connection\n"));
scp = PR_NEW(Serve_Client_Param);
if (scp == NULL) {
fprintf(stderr,"prsocket_test: PR_NEW failed\n");
@@ -460,11 +456,11 @@ TCP_Server(void *arg)
scp->datalen = sp->datalen;
t = create_new_thread(PR_USER_THREAD,
- Serve_Client, (void *)scp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0, i);
+ Serve_Client, (void *)scp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -509,18 +505,18 @@ UDP_Server(void *arg)
/*
* Create a udp socket
*/
- if ((sockfd = PR_OpenUDPSocket(server_domain)) == NULL) {
+ if ((sockfd = PR_OpenUDPSocket(server_domain)) == NULL) {
fprintf(stderr,"prsocket_test: PR_NewUDPSocket failed\n");
failed_already=1;
return;
}
- memset(&netaddr, 0 , sizeof(netaddr));
- if (PR_SetNetAddr(PR_IpAddrAny, server_domain, UDP_SERVER_PORT,
- &netaddr) == PR_FAILURE) {
+ memset(&netaddr, 0, sizeof(netaddr));
+ if (PR_SetNetAddr(PR_IpAddrAny, server_domain, UDP_SERVER_PORT,
+ &netaddr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
failed_already=1;
return;
- }
+ }
/*
* try a few times to bind server's address, if addresses are in
* use
@@ -529,8 +525,9 @@ UDP_Server(void *arg)
while (PR_Bind(sockfd, &netaddr) < 0) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
perror("PR_Bind");
@@ -545,24 +542,24 @@ UDP_Server(void *arg)
}
DPRINTF(("PR_Bind: UDP Server netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
+ netaddr.inet.ip, netaddr.inet.port));
/*
* We can't use the IP address returned by PR_GetSockName in
* netaddr.inet.ip because netaddr.inet.ip is returned
* as 0 (= PR_INADDR_ANY).
*/
- if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
- PR_ntohs(PR_NetAddrInetPort(&netaddr)),
- &udp_server_addr) == PR_FAILURE) {
+ if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
+ PR_ntohs(PR_NetAddrInetPort(&netaddr)),
+ &udp_server_addr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
failed_already=1;
return;
- }
- if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
- PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
- &udp_server_addr.ipv6.ip);
-
+ }
+ if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
+ PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
+ &udp_server_addr.ipv6.ip);
+
/*
* Wake up parent thread because server address is bound and made
* available in the global variable 'udp_server_addr'
@@ -580,22 +577,22 @@ UDP_Server(void *arg)
* Receive datagrams from clients and send them back, unmodified, to the
* clients
*/
- memset(&netaddr, 0 , sizeof(netaddr));
+ memset(&netaddr, 0, sizeof(netaddr));
for (i = 0; i < (num_udp_clients * num_udp_datagrams_per_client); i++) {
DPRINTF(("UDP_Server: calling PR_RecvFrom client - ip = 0x%lx, port = %d bytes = %d inbuf = 0x%lx, inbuf[0] = 0x%lx\n",
- netaddr.inet.ip, netaddr.inet.port, bytes, in_buf->data,
- in_buf->data[0]));
+ netaddr.inet.ip, netaddr.inet.port, bytes, in_buf->data,
+ in_buf->data[0]));
rv = PR_RecvFrom(sockfd, in_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
DPRINTF(("UDP_Server: PR_RecvFrom client - ip = 0x%lx, port = %d bytes = %d inbuf = 0x%lx, inbuf[0] = 0x%lx\n",
- netaddr.inet.ip, netaddr.inet.port, rv, in_buf->data,
- in_buf->data[0]));
+ netaddr.inet.ip, netaddr.inet.port, rv, in_buf->data,
+ in_buf->data[0]));
if (rv != bytes) {
return;
}
rv = PR_SendTo(sockfd, in_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (rv != bytes) {
return;
}
@@ -653,9 +650,9 @@ TCP_Client(void *arg)
failed_already=1;
return;
}
- if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0){
- fprintf(stderr, "PR_Connect failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0) {
+ fprintf(stderr, "PR_Connect failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
return;
}
@@ -668,8 +665,9 @@ TCP_Client(void *arg)
* write to server
*/
#ifdef WINNT
- if (test_cancelio && (j == 0))
- PR_Sleep(PR_SecondsToInterval(12));
+ if (test_cancelio && (j == 0)) {
+ PR_Sleep(PR_SecondsToInterval(12));
+ }
#endif
if (writen(sockfd, out_buf->data, bytes) < bytes) {
fprintf(stderr,"prsocket_test: ERROR - TCP_Client:writen\n");
@@ -677,7 +675,7 @@ TCP_Client(void *arg)
return;
}
DPRINTF(("TCP Client [0x%lx]: out_buf = 0x%lx out_buf[0] = 0x%lx\n",
- PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
+ PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
if (readn(sockfd, in_buf->data, bytes) < bytes) {
fprintf(stderr,"prsocket_test: ERROR - TCP_Client:readn\n");
failed_already=1;
@@ -697,9 +695,6 @@ TCP_Client(void *arg)
*/
if (PR_Shutdown(sockfd, PR_SHUTDOWN_BOTH) < 0) {
fprintf(stderr,"prsocket_test: ERROR - PR_Shutdown\n");
-#if defined(SYMBIAN)
- if (EPIPE != errno)
-#endif
failed_already=1;
}
PR_Close(sockfd);
@@ -722,7 +717,7 @@ TCP_Client(void *arg)
/*
* UDP_Client
* Client Thread
- * Create a socket and bind an address
+ * Create a socket and bind an address
* Communicate with the server at the address specified in the argument.
* Fill in a buffer, write data to server, read it back and check
* for data corruption.
@@ -761,13 +756,13 @@ UDP_Client(void *arg)
* bind an address for the client, let the system chose the port
* number
*/
- memset(&netaddr, 0 , sizeof(netaddr));
- if (PR_SetNetAddr(PR_IpAddrAny, client_domain, 0,
- &netaddr) == PR_FAILURE) {
+ memset(&netaddr, 0, sizeof(netaddr));
+ if (PR_SetNetAddr(PR_IpAddrAny, client_domain, 0,
+ &netaddr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
failed_already=1;
return;
- }
+ }
if (PR_Bind(sockfd, &netaddr) < 0) {
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
perror("PR_Bind");
@@ -781,12 +776,12 @@ UDP_Client(void *arg)
}
DPRINTF(("PR_Bind: UDP Client netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
+ netaddr.inet.ip, netaddr.inet.port));
netaddr = cp->server_addr;
if (cp->udp_connect) {
- if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0){
+ if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0) {
fprintf(stderr,"prsocket_test: PR_Connect failed\n");
failed_already=1;
return;
@@ -798,33 +793,33 @@ UDP_Client(void *arg)
* fill in random data
*/
DPRINTF(("UDP_Client [0x%lx]: out_buf = 0x%lx bytes = 0x%lx\n",
- PR_GetCurrentThread(), out_buf->data, bytes));
+ PR_GetCurrentThread(), out_buf->data, bytes));
memset(out_buf->data, ((PRInt32) (&netaddr)) + i, bytes);
/*
* write to server
*/
if (cp->udp_connect)
rv = PR_Send(sockfd, out_buf->data, bytes, 0,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
else
rv = PR_SendTo(sockfd, out_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (rv != bytes) {
return;
}
DPRINTF(("UDP_Client [0x%lx]: out_buf = 0x%lx out_buf[0] = 0x%lx\n",
- PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
+ PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
if (cp->udp_connect)
rv = PR_Recv(sockfd, in_buf->data, bytes, 0,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
else
rv = PR_RecvFrom(sockfd, in_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (rv != bytes) {
return;
}
DPRINTF(("UDP_Client [0x%lx]: in_buf = 0x%lx in_buf[0] = 0x%lx\n",
- PR_GetCurrentThread(), in_buf, (*((int *) in_buf->data))));
+ PR_GetCurrentThread(), in_buf, (*((int *) in_buf->data))));
/*
* verify the data read
*/
@@ -853,7 +848,7 @@ UDP_Client(void *arg)
/*
* TCP_Socket_Client_Server_Test - concurrent server test
- *
+ *
* One server and several clients are started
* Each client connects to the server and sends a chunk of data
* For each connection, server starts another thread to read the data
@@ -905,11 +900,11 @@ TCP_Socket_Client_Server_Test(void)
sparamp->exit_counter = &thread_count;
sparamp->datalen = datalen;
t = PR_CreateThread(PR_USER_THREAD,
- TCP_Server, (void *)sparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ TCP_Server, (void *)sparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -939,11 +934,11 @@ TCP_Socket_Client_Server_Test(void)
cparamp->datalen = datalen;
for (i = 0; i < num_tcp_clients; i++) {
t = create_new_thread(PR_USER_THREAD,
- TCP_Client, (void *) cparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0, i);
+ TCP_Client, (void *) cparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -960,16 +955,16 @@ TCP_Socket_Client_Server_Test(void)
PR_ExitMonitor(mon2);
printf("%30s","TCP_Socket_Client_Server_Test:");
printf("%2ld Server %2ld Clients %2ld connections_per_client\n",1l,
- num_tcp_clients, num_tcp_connections_per_client);
+ num_tcp_clients, num_tcp_connections_per_client);
printf("%30s %2ld messages_per_connection %4ld bytes_per_message\n",":",
- num_tcp_mesgs_per_connection, tcp_mesg_size);
+ num_tcp_mesgs_per_connection, tcp_mesg_size);
return 0;
}
/*
* UDP_Socket_Client_Server_Test - iterative server test
- *
+ *
* One server and several clients are started
* Each client connects to the server and sends a chunk of data
* For each connection, server starts another thread to read the data
@@ -1023,11 +1018,11 @@ UDP_Socket_Client_Server_Test(void)
sparamp->datalen = datalen;
DPRINTF(("Creating UDP server"));
t = PR_CreateThread(PR_USER_THREAD,
- UDP_Server, (void *)sparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ UDP_Server, (void *)sparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -1059,17 +1054,19 @@ UDP_Socket_Client_Server_Test(void)
* Cause every other client thread to connect udp sockets
*/
cparamp->udp_connect = udp_connect;
- if (udp_connect)
+ if (udp_connect) {
udp_connect = 0;
- else
+ }
+ else {
udp_connect = 1;
+ }
DPRINTF(("Creating UDP client %d\n", i));
t = PR_CreateThread(PR_USER_THREAD,
- UDP_Client, (void *) cparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ UDP_Client, (void *) cparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -1086,7 +1083,7 @@ UDP_Socket_Client_Server_Test(void)
printf("%30s","UDP_Socket_Client_Server_Test: ");
printf("%2ld Server %2ld Clients\n",1l, num_udp_clients);
printf("%30s %2ld datagrams_per_client %4ld bytes_per_datagram\n",":",
- num_udp_datagrams_per_client, udp_datagram_size);
+ num_udp_datagrams_per_client, udp_datagram_size);
return 0;
}
@@ -1105,17 +1102,17 @@ TransmitFile_Client(void *arg)
union PRNetAddr netaddr;
char *small_buf, *large_buf;
Client_Param *cp = (Client_Param *) arg;
- PRInt32 rlen;
+ PRInt32 rlen;
small_buf = (char*)PR_Malloc(SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE +
- SMALL_FILE_TRAILER_SIZE);
+ SMALL_FILE_TRAILER_SIZE);
if (small_buf == NULL) {
fprintf(stderr,"prsocket_test: failed to alloc buffer\n");
failed_already=1;
return;
}
large_buf = (char*)PR_Malloc(LARGE_FILE_SIZE + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE);
+ LARGE_FILE_TRAILER_SIZE);
if (large_buf == NULL) {
fprintf(stderr,"prsocket_test: failed to alloc buffer\n");
failed_already=1;
@@ -1131,7 +1128,7 @@ TransmitFile_Client(void *arg)
return;
}
- if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0){
+ if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0) {
fprintf(stderr,"prsocket_test: PR_Connect failed\n");
failed_already=1;
return;
@@ -1142,22 +1139,22 @@ TransmitFile_Client(void *arg)
if (readn(sockfd, small_buf, SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE)
!= (SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE)) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client failed to receive file\n");
+ "prsocket_test: TransmitFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
+#if defined(XP_UNIX)
/* File transmission test can not be done because of large file's size */
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client ERROR - small file header data corruption\n");
+ "prsocket_test: TransmitFile_Client ERROR - small file header data corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_addr, small_buf + SMALL_FILE_HEADER_SIZE,
- SMALL_FILE_SIZE) != 0) {
+ SMALL_FILE_SIZE) != 0) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client ERROR - small file data corruption\n");
+ "prsocket_test: TransmitFile_Client ERROR - small file data corruption\n");
failed_already=1;
return;
}
@@ -1167,263 +1164,263 @@ TransmitFile_Client(void *arg)
*/
if (readn(sockfd, large_buf, LARGE_FILE_SIZE) != LARGE_FILE_SIZE) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client failed to receive file\n");
+ "prsocket_test: TransmitFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
+#if defined(XP_UNIX)
if (memcmp(large_file_addr, large_buf, LARGE_FILE_SIZE) != 0) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client ERROR - large file data corruption\n");
+ "prsocket_test: TransmitFile_Client ERROR - large file data corruption\n");
failed_already=1;
}
#endif
- /*
- * receive data from PR_SendFile
- */
- /*
- * case 1: small file with header and trailer
- */
+ /*
+ * receive data from PR_SendFile
+ */
+ /*
+ * case 1: small file with header and trailer
+ */
rlen = SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE +
- SMALL_FILE_TRAILER_SIZE;
+ SMALL_FILE_TRAILER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+#if defined(XP_UNIX)
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 1. ERROR - small file header corruption\n");
+ "SendFile 1. ERROR - small file header corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_addr, small_buf + SMALL_FILE_HEADER_SIZE,
- SMALL_FILE_SIZE) != 0) {
+ SMALL_FILE_SIZE) != 0) {
fprintf(stderr,
- "SendFile 1. ERROR - small file data corruption\n");
+ "SendFile 1. ERROR - small file data corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_trailer,
- small_buf + SMALL_FILE_HEADER_SIZE + SMALL_FILE_SIZE,
- SMALL_FILE_TRAILER_SIZE) != 0) {
+ small_buf + SMALL_FILE_HEADER_SIZE + SMALL_FILE_SIZE,
+ SMALL_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 1. ERROR - small file trailer corruption\n");
+ "SendFile 1. ERROR - small file trailer corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 2: partial large file at zero offset, file with header and trailer
- */
+ /*
+ * case 2: partial large file at zero offset, file with header and trailer
+ */
rlen = LARGE_FILE_LEN_1 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+#if defined(XP_UNIX)
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file header corruption\n");
+ "SendFile 2. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp(large_file_addr, large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_1) != 0) {
+ LARGE_FILE_LEN_1) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file data corruption\n");
+ "SendFile 2. ERROR - large file data corruption\n");
failed_already=1;
return;
}
if (memcmp(large_file_trailer,
- large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_1,
- LARGE_FILE_TRAILER_SIZE) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_1,
+ LARGE_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file trailer corruption\n");
+ "SendFile 2. ERROR - large file trailer corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 3: partial small file at non-zero offset, with header
- */
+ /*
+ * case 3: partial small file at non-zero offset, with header
+ */
rlen = SMALL_FILE_LEN_1 + SMALL_FILE_HEADER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+#if defined(XP_UNIX)
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 3. ERROR - small file header corruption\n");
+ "SendFile 3. ERROR - small file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *) small_file_addr + SMALL_FILE_OFFSET_1,
- small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_1) != 0) {
+ small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_1) != 0) {
fprintf(stderr,
- "SendFile 3. ERROR - small file data corruption\n");
+ "SendFile 3. ERROR - small file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 4: partial small file at non-zero offset, with trailer
- */
+ /*
+ * case 4: partial small file at non-zero offset, with trailer
+ */
rlen = SMALL_FILE_LEN_2 + SMALL_FILE_TRAILER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
+#if defined(XP_UNIX)
if (memcmp((char *) small_file_addr + SMALL_FILE_OFFSET_2, small_buf,
- SMALL_FILE_LEN_2) != 0) {
+ SMALL_FILE_LEN_2) != 0) {
fprintf(stderr,
- "SendFile 4. ERROR - small file data corruption\n");
+ "SendFile 4. ERROR - small file data corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_trailer, small_buf + SMALL_FILE_LEN_2,
- SMALL_FILE_TRAILER_SIZE) != 0) {
+ SMALL_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 4. ERROR - small file trailer corruption\n");
+ "SendFile 4. ERROR - small file trailer corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 5: partial large file at non-zero offset, file with header
- */
+ /*
+ * case 5: partial large file at non-zero offset, file with header
+ */
rlen = LARGE_FILE_LEN_2 + LARGE_FILE_HEADER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+#if defined(XP_UNIX)
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 5. ERROR - large file header corruption\n");
+ "SendFile 5. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *)large_file_addr + LARGE_FILE_OFFSET_2,
- large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_2) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE,
+ LARGE_FILE_LEN_2) != 0) {
fprintf(stderr,
- "SendFile 5. ERROR - large file data corruption\n");
+ "SendFile 5. ERROR - large file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 6: partial small file at non-zero offset, with header
- */
+ /*
+ * case 6: partial small file at non-zero offset, with header
+ */
rlen = SMALL_FILE_LEN_3 + SMALL_FILE_HEADER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+#if defined(XP_UNIX)
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 6. ERROR - small file header corruption\n");
+ "SendFile 6. ERROR - small file header corruption\n");
return;
}
if (memcmp((char *) small_file_addr + SMALL_FILE_OFFSET_3,
- small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_3) != 0) {
+ small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_3) != 0) {
#if 0
- char *i, *j;
- int k;
-
- i = (char *) small_file_addr + SMALL_FILE_OFFSET_3;
- j = small_buf + SMALL_FILE_HEADER_SIZE;
- k = SMALL_FILE_LEN_3;
- while (k-- > 0) {
- if (*i++ != *j++)
- printf("i = %d j = %d\n",
- (int) (i - ((char *) small_file_addr + SMALL_FILE_OFFSET_3)),
- (int) (j - (small_buf + SMALL_FILE_HEADER_SIZE)));
- }
+ char *i, *j;
+ int k;
+
+ i = (char *) small_file_addr + SMALL_FILE_OFFSET_3;
+ j = small_buf + SMALL_FILE_HEADER_SIZE;
+ k = SMALL_FILE_LEN_3;
+ while (k-- > 0) {
+ if (*i++ != *j++)
+ printf("i = %d j = %d\n",
+ (int) (i - ((char *) small_file_addr + SMALL_FILE_OFFSET_3)),
+ (int) (j - (small_buf + SMALL_FILE_HEADER_SIZE)));
+ }
#endif
fprintf(stderr,
- "SendFile 6. ERROR - small file data corruption\n");
+ "SendFile 6. ERROR - small file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 7: partial large file at non-zero offset, with header
- */
+ /*
+ * case 7: partial large file at non-zero offset, with header
+ */
rlen = LARGE_FILE_LEN_3 + LARGE_FILE_HEADER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+#if defined(XP_UNIX)
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 7. ERROR - large file header corruption\n");
+ "SendFile 7. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *)large_file_addr + LARGE_FILE_OFFSET_3,
- large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_3) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE,
+ LARGE_FILE_LEN_3) != 0) {
fprintf(stderr,
- "SendFile 7. ERROR - large file data corruption\n");
+ "SendFile 7. ERROR - large file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 8: partial large file at non-zero, page-aligned offset, with
- * header and trailer
- */
+ /*
+ * case 8: partial large file at non-zero, page-aligned offset, with
+ * header and trailer
+ */
rlen = LARGE_FILE_LEN_4 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+#if defined(XP_UNIX)
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file header corruption\n");
+ "SendFile 2. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *)large_file_addr + LARGE_FILE_OFFSET_4,
- large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_4) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE,
+ LARGE_FILE_LEN_4) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file data corruption\n");
+ "SendFile 2. ERROR - large file data corruption\n");
failed_already=1;
return;
}
if (memcmp(large_file_trailer,
- large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_4,
- LARGE_FILE_TRAILER_SIZE) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_4,
+ LARGE_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file trailer corruption\n");
+ "SendFile 2. ERROR - large file trailer corruption\n");
failed_already=1;
return;
}
@@ -1458,15 +1455,15 @@ Serve_TransmitFile_Client(void *arg)
PRInt32 bytes;
PRFileDesc *local_small_file_fd=NULL;
PRFileDesc *local_large_file_fd=NULL;
- PRSendFileData sfd;
- PRInt32 slen;
+ PRSendFileData sfd;
+ PRInt32 slen;
sockfd = scp->sockfd;
local_small_file_fd = PR_Open(SMALL_FILE_NAME, PR_RDONLY,0);
if (local_small_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to open file for transmitting %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
goto done;
}
@@ -1474,218 +1471,220 @@ Serve_TransmitFile_Client(void *arg)
if (local_large_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to open file for transmitting %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
goto done;
}
bytes = PR_TransmitFile(sockfd, local_small_file_fd, small_file_header,
- SMALL_FILE_HEADER_SIZE, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ SMALL_FILE_HEADER_SIZE, PR_TRANSMITFILE_KEEP_OPEN,
+ PR_INTERVAL_NO_TIMEOUT);
if (bytes != (SMALL_FILE_SIZE+ SMALL_FILE_HEADER_SIZE)) {
fprintf(stderr,
- "prsocet_test: PR_TransmitFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocet_test: PR_TransmitFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
bytes = PR_TransmitFile(sockfd, local_large_file_fd, NULL, 0,
- PR_TRANSMITFILE_KEEP_OPEN, PR_INTERVAL_NO_TIMEOUT);
+ PR_TRANSMITFILE_KEEP_OPEN, PR_INTERVAL_NO_TIMEOUT);
if (bytes != LARGE_FILE_SIZE) {
fprintf(stderr,
- "prsocket_test: PR_TransmitFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocket_test: PR_TransmitFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
- /*
- * PR_SendFile test cases
- */
+ /*
+ * PR_SendFile test cases
+ */
- /*
- * case 1: small file with header and trailer
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = 0;
- sfd.file_nbytes = 0;
- sfd.header = small_file_header;
- sfd.hlen = SMALL_FILE_HEADER_SIZE;
- sfd.trailer = small_file_trailer;
- sfd.tlen = SMALL_FILE_TRAILER_SIZE;
+ /*
+ * case 1: small file with header and trailer
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = 0;
+ sfd.file_nbytes = 0;
+ sfd.header = small_file_header;
+ sfd.hlen = SMALL_FILE_HEADER_SIZE;
+ sfd.trailer = small_file_trailer;
+ sfd.tlen = SMALL_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_SIZE+ SMALL_FILE_HEADER_SIZE +
- SMALL_FILE_TRAILER_SIZE;
+ SMALL_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 1. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 1. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
- /*
- * case 2: partial large file at zero offset, file with header and trailer
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = 0;
- sfd.file_nbytes = LARGE_FILE_LEN_1;
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = large_file_trailer;
- sfd.tlen = LARGE_FILE_TRAILER_SIZE;
+ /*
+ * case 2: partial large file at zero offset, file with header and trailer
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = 0;
+ sfd.file_nbytes = LARGE_FILE_LEN_1;
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = large_file_trailer;
+ sfd.tlen = LARGE_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_1 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 3: partial small file at non-zero offset, with header
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = SMALL_FILE_OFFSET_1;
- sfd.file_nbytes = SMALL_FILE_LEN_1;
- sfd.header = small_file_header;
- sfd.hlen = SMALL_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 3: partial small file at non-zero offset, with header
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = SMALL_FILE_OFFSET_1;
+ sfd.file_nbytes = SMALL_FILE_LEN_1;
+ sfd.header = small_file_header;
+ sfd.hlen = SMALL_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_LEN_1 + SMALL_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 3. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 3. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 4: partial small file at non-zero offset, with trailer
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = SMALL_FILE_OFFSET_2;
- sfd.file_nbytes = SMALL_FILE_LEN_2;
- sfd.header = NULL;
- sfd.hlen = 0;
- sfd.trailer = small_file_trailer;
- sfd.tlen = SMALL_FILE_TRAILER_SIZE;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 4: partial small file at non-zero offset, with trailer
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = SMALL_FILE_OFFSET_2;
+ sfd.file_nbytes = SMALL_FILE_LEN_2;
+ sfd.header = NULL;
+ sfd.hlen = 0;
+ sfd.trailer = small_file_trailer;
+ sfd.tlen = SMALL_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_LEN_2 + SMALL_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 4. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 4. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 5: partial large file at non-zero offset, file with header
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = LARGE_FILE_OFFSET_2;
- sfd.file_nbytes = LARGE_FILE_LEN_2;
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 5: partial large file at non-zero offset, file with header
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = LARGE_FILE_OFFSET_2;
+ sfd.file_nbytes = LARGE_FILE_LEN_2;
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_2 + LARGE_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 5. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 5. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 6: partial small file from non-zero offset till end of file, with header
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = SMALL_FILE_OFFSET_3;
- sfd.file_nbytes = 0; /* data from offset to end-of-file */
- sfd.header = small_file_header;
- sfd.hlen = SMALL_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 6: partial small file from non-zero offset till end of file, with header
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = SMALL_FILE_OFFSET_3;
+ sfd.file_nbytes = 0; /* data from offset to end-of-file */
+ sfd.header = small_file_header;
+ sfd.hlen = SMALL_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_LEN_3 + SMALL_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 6. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 6. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 7: partial large file at non-zero offset till end-of-file, with header
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = LARGE_FILE_OFFSET_3;
- sfd.file_nbytes = 0; /* data until end-of-file */
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 7: partial large file at non-zero offset till end-of-file, with header
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = LARGE_FILE_OFFSET_3;
+ sfd.file_nbytes = 0; /* data until end-of-file */
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_3 + LARGE_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 7. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 7. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 8: partial large file at non-zero page-aligned offset,
- * with header and trailer
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = LARGE_FILE_OFFSET_4;
- sfd.file_nbytes = LARGE_FILE_LEN_4;
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = large_file_trailer;
- sfd.tlen = LARGE_FILE_TRAILER_SIZE;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 8: partial large file at non-zero page-aligned offset,
+ * with header and trailer
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = LARGE_FILE_OFFSET_4;
+ sfd.file_nbytes = LARGE_FILE_LEN_4;
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = large_file_trailer;
+ sfd.tlen = LARGE_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_CLOSE_SOCKET,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_4 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
done:
- if (local_small_file_fd != NULL)
+ if (local_small_file_fd != NULL) {
PR_Close(local_small_file_fd);
- if (local_large_file_fd != NULL)
+ }
+ if (local_large_file_fd != NULL) {
PR_Close(local_large_file_fd);
+ }
}
/*
@@ -1718,7 +1717,7 @@ TransmitFile_Server(void *arg)
failed_already=1;
goto exit;
}
- memset(&netaddr, 0 , sizeof(netaddr));
+ memset(&netaddr, 0, sizeof(netaddr));
netaddr.inet.family = PR_AF_INET;
netaddr.inet.port = PR_htons(TCP_SERVER_PORT);
netaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
@@ -1730,8 +1729,9 @@ TransmitFile_Server(void *arg)
while (PR_Bind(sockfd, &netaddr) < 0) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
failed_already=1;
@@ -1747,13 +1747,13 @@ TransmitFile_Server(void *arg)
if (PR_GetSockName(sockfd, &netaddr) < 0) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_GetSockName failed\n");
+ "prsocket_test: ERROR - PR_GetSockName failed\n");
failed_already=1;
goto exit;
}
DPRINTF(("TCP_Server: PR_BIND netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
+ netaddr.inet.ip, netaddr.inet.port));
tcp_server_addr.inet.family = netaddr.inet.family;
tcp_server_addr.inet.port = netaddr.inet.port;
tcp_server_addr.inet.ip = netaddr.inet.ip;
@@ -1769,26 +1769,26 @@ TransmitFile_Server(void *arg)
PRNetAddr *addrp = (i%2 ? &netaddr: NULL);
if ((newsockfd = PR_Accept(sockfd, addrp,
- PR_INTERVAL_NO_TIMEOUT)) == NULL) {
+ PR_INTERVAL_NO_TIMEOUT)) == NULL) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_Accept failed\n");
+ "prsocket_test: ERROR - PR_Accept failed\n");
failed_already=1;
goto exit;
}
/* test both regular and emulated PR_SendFile */
if (i%2) {
PRFileDesc *layer = PR_CreateIOLayerStub(
- emuSendFileIdentity, &emuSendFileMethods);
+ emuSendFileIdentity, &emuSendFileMethods);
if (layer == NULL) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_CreateIOLayerStub failed\n");
+ "prsocket_test: ERROR - PR_CreateIOLayerStub failed\n");
failed_already=1;
goto exit;
}
if (PR_PushIOLayer(newsockfd, PR_TOP_IO_LAYER, layer)
- == PR_FAILURE) {
+ == PR_FAILURE) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_PushIOLayer failed\n");
+ "prsocket_test: ERROR - PR_PushIOLayer failed\n");
failed_already=1;
goto exit;
}
@@ -1807,14 +1807,14 @@ TransmitFile_Server(void *arg)
scp->datalen = sp->datalen;
t[i] = PR_CreateThread(PR_USER_THREAD,
- Serve_TransmitFile_Client, (void *)scp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
+ Serve_TransmitFile_Client, (void *)scp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
if (t[i] == NULL) {
fprintf(stderr,
- "prsocket_test: PR_CreateThread failed\n");
+ "prsocket_test: PR_CreateThread failed\n");
failed_already=1;
goto exit;
}
@@ -1850,8 +1850,8 @@ exit:
}
/*
- * Socket_Misc_Test - test miscellaneous functions
- *
+ * Socket_Misc_Test - test miscellaneous functions
+ *
*/
static PRInt32
Socket_Misc_Test(void)
@@ -1865,9 +1865,9 @@ Socket_Misc_Test(void)
PRInt32 datalen;
/*
- * We deliberately pick a buffer size that is not a nice multiple
- * of 1024.
- */
+ * We deliberately pick a buffer size that is not a nice multiple
+ * of 1024.
+ */
#define TRANSMITFILE_BUF_SIZE (4 * 1024 - 11)
typedef struct {
@@ -1888,7 +1888,7 @@ Socket_Misc_Test(void)
if (small_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to create/open file %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1909,12 +1909,12 @@ Socket_Misc_Test(void)
count = 0;
do {
len = (SMALL_FILE_SIZE - count) > TRANSMITFILE_BUF_SIZE ?
- TRANSMITFILE_BUF_SIZE : (SMALL_FILE_SIZE - count);
+ TRANSMITFILE_BUF_SIZE : (SMALL_FILE_SIZE - count);
bytes = PR_Write(small_file_fd, buf->data, len);
if (bytes <= 0) {
fprintf(stderr,
- "prsocket_test failed to write to file %s\n",
- SMALL_FILE_NAME);
+ "prsocket_test failed to write to file %s\n",
+ SMALL_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1926,10 +1926,10 @@ Socket_Misc_Test(void)
* map the small file; used in checking for data corruption
*/
small_file_addr = mmap(0, SMALL_FILE_SIZE, PROT_READ,
- MAP_SHARED, small_file_fd->secret->md.osfd, 0);
+ MAP_SHARED, small_file_fd->secret->md.osfd, 0);
if (small_file_addr == (void *) -1) {
fprintf(stderr,"prsocket_test failed to mmap file %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1946,7 +1946,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(small_file_header, (int) PR_IntervalNow(),
- SMALL_FILE_HEADER_SIZE);
+ SMALL_FILE_HEADER_SIZE);
/*
* trailer for small file
*/
@@ -1958,7 +1958,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(small_file_trailer, (int) PR_IntervalNow(),
- SMALL_FILE_TRAILER_SIZE);
+ SMALL_FILE_TRAILER_SIZE);
/*
* setup large file
*/
@@ -1966,7 +1966,7 @@ Socket_Misc_Test(void)
if (large_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to create/open file %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1980,28 +1980,28 @@ Socket_Misc_Test(void)
count = 0;
do {
len = (LARGE_FILE_SIZE - count) > TRANSMITFILE_BUF_SIZE ?
- TRANSMITFILE_BUF_SIZE : (LARGE_FILE_SIZE - count);
+ TRANSMITFILE_BUF_SIZE : (LARGE_FILE_SIZE - count);
bytes = PR_Write(large_file_fd, buf->data, len);
if (bytes <= 0) {
fprintf(stderr,
- "prsocket_test failed to write to file %s: (%ld, %ld)\n",
- LARGE_FILE_NAME,
- PR_GetError(), PR_GetOSError());
+ "prsocket_test failed to write to file %s: (%ld, %ld)\n",
+ LARGE_FILE_NAME,
+ PR_GetError(), PR_GetOSError());
failed_already=1;
rv = -1;
goto done;
}
count += bytes;
} while (count < LARGE_FILE_SIZE);
-#if defined(XP_UNIX) && !defined(SYMBIAN)
+#if defined(XP_UNIX)
/*
* map the large file; used in checking for data corruption
*/
large_file_addr = mmap(0, LARGE_FILE_SIZE, PROT_READ,
- MAP_SHARED, large_file_fd->secret->md.osfd, 0);
+ MAP_SHARED, large_file_fd->secret->md.osfd, 0);
if (large_file_addr == (void *) -1) {
fprintf(stderr,"prsocket_test failed to mmap file %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -2018,7 +2018,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(large_file_header, (int) PR_IntervalNow(),
- LARGE_FILE_HEADER_SIZE);
+ LARGE_FILE_HEADER_SIZE);
/*
* trailer for large file
*/
@@ -2030,7 +2030,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(large_file_trailer, (int) PR_IntervalNow(),
- LARGE_FILE_TRAILER_SIZE);
+ LARGE_FILE_TRAILER_SIZE);
datalen = tcp_mesg_size;
thread_count = 0;
@@ -2065,11 +2065,11 @@ Socket_Misc_Test(void)
sparamp->exit_counter = &thread_count;
sparamp->datalen = datalen;
t = PR_CreateThread(PR_USER_THREAD,
- TransmitFile_Server, (void *)sparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ TransmitFile_Server, (void *)sparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -2102,11 +2102,11 @@ Socket_Misc_Test(void)
cparamp->datalen = datalen;
for (i = 0; i < num_transmitfile_clients; i++) {
t = create_new_thread(PR_USER_THREAD,
- TransmitFile_Client, (void *) cparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0, i);
+ TransmitFile_Client, (void *) cparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
rv = -1;
@@ -2126,7 +2126,7 @@ done:
if (buf) {
PR_DELETE(buf);
}
-#if defined(XP_UNIX) && !defined(SYMBIAN)
+#if defined(XP_UNIX)
munmap((char*)small_file_addr, SMALL_FILE_SIZE);
munmap((char*)large_file_addr, LARGE_FILE_SIZE);
#endif
@@ -2134,24 +2134,24 @@ done:
PR_Close(large_file_fd);
if ((PR_Delete(SMALL_FILE_NAME)) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: failed to unlink file %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
}
if ((PR_Delete(LARGE_FILE_NAME)) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: failed to unlink file %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
}
if ((PR_RmDir(TEST_DIR)) == PR_FAILURE) {
fprintf(stderr,"prsocket_test failed to rmdir %s: (%ld, %ld)\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
+ TEST_DIR, PR_GetError(), PR_GetOSError());
failed_already=1;
}
printf("%-29s%s","Socket_Misc_Test",":");
printf("%2d Server %2d Clients\n",1, num_transmitfile_clients);
printf("%30s Sizes of Transmitted Files - %4d KB, %2d MB \n",":",
- SMALL_FILE_SIZE/1024, LARGE_FILE_SIZE/(1024 * 1024));
+ SMALL_FILE_SIZE/1024, LARGE_FILE_SIZE/(1024 * 1024));
return rv;
@@ -2172,14 +2172,16 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "d");
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'd': /* debug mode */
- _debug_on = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -2197,112 +2199,69 @@ int main(int argc, char **argv)
/*
* run client-server test with TCP, Ipv4-Ipv4
*/
- printf("TCP Client/Server Test - IPv4/Ipv4\n");
+ printf("TCP Client/Server Test - IPv4/Ipv4\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
/*
* client-server test, Ipv6-Ipv4
*/
- client_domain = PR_AF_INET6;
- printf("TCP Client/Server Test - IPv6/Ipv4\n");
+ client_domain = PR_AF_INET6;
+ printf("TCP Client/Server Test - IPv6/Ipv4\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
/*
* client-server test, Ipv4-Ipv6
*/
- client_domain = PR_AF_INET;
- server_domain = PR_AF_INET6;
- printf("TCP Client/Server Test - IPv4/Ipv6\n");
+ client_domain = PR_AF_INET;
+ server_domain = PR_AF_INET6;
+ printf("TCP Client/Server Test - IPv4/Ipv6\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
/*
* client-server test, Ipv6-Ipv6
*/
- client_domain = PR_AF_INET6;
- server_domain = PR_AF_INET6;
- printf("TCP Client/Server Test - IPv6/Ipv6\n");
+ client_domain = PR_AF_INET6;
+ server_domain = PR_AF_INET6;
+ printf("TCP Client/Server Test - IPv6/Ipv6\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
- test_cancelio = 0;
-
-#if defined(SYMBIAN) && !defined(__WINSCW__)
- /* UDP tests only run on Symbian devices but not emulator */
- /*
- * run client-server test with UDP, IPv4/IPv4
- */
- printf("UDP Client/Server Test - IPv4/Ipv4\n");
- client_domain = PR_AF_INET;
- server_domain = PR_AF_INET;
- if (UDP_Socket_Client_Server_Test() < 0) {
- printf("UDP_Socket_Client_Server_Test failed\n");
- goto done;
- } else
- printf("UDP_Socket_Client_Server_Test Passed\n");
- /*
- * run client-server test with UDP, IPv6/IPv4
- */
- printf("UDP Client/Server Test - IPv6/Ipv4\n");
- client_domain = PR_AF_INET6;
- server_domain = PR_AF_INET;
- if (UDP_Socket_Client_Server_Test() < 0) {
- printf("UDP_Socket_Client_Server_Test failed\n");
- goto done;
- } else
- printf("UDP_Socket_Client_Server_Test Passed\n");
- /*
- * run client-server test with UDP,IPv4-IPv6
- */
- printf("UDP Client/Server Test - IPv4/Ipv6\n");
- client_domain = PR_AF_INET;
- server_domain = PR_AF_INET6;
- if (UDP_Socket_Client_Server_Test() < 0) {
- printf("UDP_Socket_Client_Server_Test failed\n");
- goto done;
- } else
- printf("UDP_Socket_Client_Server_Test Passed\n");
- /*
- * run client-server test with UDP,IPv6-IPv6
- */
- printf("UDP Client/Server Test - IPv6/Ipv6\n");
- client_domain = PR_AF_INET6;
- server_domain = PR_AF_INET6;
- if (UDP_Socket_Client_Server_Test() < 0) {
- printf("UDP_Socket_Client_Server_Test failed\n");
- goto done;
- } else
- printf("UDP_Socket_Client_Server_Test Passed\n");
-#endif
-
+ }
+ test_cancelio = 0;
+
/*
* Misc socket tests - including transmitfile, etc.
*/
- /* File transmission test can not be done in Symbian OS because of
+ /* File transmission test can not be done in Symbian OS because of
* large file's size and the incomplete mmap() implementation. */
-#if !defined(WIN16) && !defined(SYMBIAN)
+#if !defined(WIN16)
/*
-** The 'transmit file' test does not run because
-** transmit file is not implemented in NSPR yet.
-**
-*/
+ ** The 'transmit file' test does not run because
+ ** transmit file is not implemented in NSPR yet.
+ **
+ */
if (Socket_Misc_Test() < 0) {
printf("Socket_Misc_Test failed\n");
failed_already=1;
goto done;
- } else
+ } else {
printf("Socket_Misc_Test passed\n");
+ }
/*
* run client-server test with TCP again to test
@@ -2311,12 +2270,17 @@ int main(int argc, char **argv)
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
#endif
done:
PR_Cleanup();
- if (failed_already) return 1;
- else return 0;
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}