mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-25 18:07:31 +09:00
update NSPR to 4.24 and keep NSPR Bug 1586070 and win64 patch intact.
This commit is contained in:
parent
dd094ae552
commit
0b9855b841
487 changed files with 42933 additions and 48679 deletions
|
|
@ -23,7 +23,7 @@
|
|||
* The debug mode will print all of the printfs associated with this test.
|
||||
* The regress mode will be the default mode. Since the regress tool limits
|
||||
* the output to a one line status:PASS or FAIL,all of the printf statements
|
||||
* have been handled with an if (debug_mode) statement.
|
||||
* have been handled with an if (debug_mode) statement.
|
||||
*/
|
||||
|
||||
#include "prclist.h"
|
||||
|
|
@ -184,7 +184,7 @@ static void _MY_Assert(const char *s, const char *file, PRIntn ln)
|
|||
static PRBool Aborted(PRStatus rv)
|
||||
{
|
||||
return ((PR_FAILURE == rv) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) ?
|
||||
PR_TRUE : PR_FALSE;
|
||||
PR_TRUE : PR_FALSE;
|
||||
}
|
||||
|
||||
static void TimeOfDayMessage(const char *msg, PRThread* me)
|
||||
|
|
@ -213,8 +213,9 @@ static void PR_CALLBACK Client(void *arg)
|
|||
PRIntervalTime timeout = PR_MillisecondsToInterval(DEFAULT_CLIENT_TIMEOUT);
|
||||
|
||||
|
||||
for (index = 0; index < sizeof(buffer); ++index)
|
||||
for (index = 0; index < sizeof(buffer); ++index) {
|
||||
buffer[index] = (char)index;
|
||||
}
|
||||
|
||||
client->started = PR_IntervalNow();
|
||||
|
||||
|
|
@ -230,8 +231,8 @@ static void PR_CALLBACK Client(void *arg)
|
|||
PRInt32 bytes, descbytes, filebytes, netbytes;
|
||||
|
||||
(void)PR_NetAddrToString(&client->serverAddress, buffer, sizeof(buffer));
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_INFO,
|
||||
("\tClient(0x%p): connecting to server at %s\n", me, buffer));
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_INFO,
|
||||
("\tClient(0x%p): connecting to server at %s\n", me, buffer));
|
||||
|
||||
fd = PR_Socket(domain, SOCK_STREAM, protocol);
|
||||
TEST_ASSERT(NULL != fd);
|
||||
|
|
@ -253,10 +254,12 @@ static void PR_CALLBACK Client(void *arg)
|
|||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\tClient(0x%p): sending descriptor for %u bytes\n", me, descbytes));
|
||||
bytes = PR_Send(
|
||||
fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
|
||||
fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
|
||||
if (sizeof(CSDescriptor_t) != bytes)
|
||||
{
|
||||
if (Aborted(PR_FAILURE)) goto aborted;
|
||||
if (Aborted(PR_FAILURE)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
|
|
@ -271,15 +274,18 @@ static void PR_CALLBACK Client(void *arg)
|
|||
while (netbytes < descbytes)
|
||||
{
|
||||
filebytes = sizeof(buffer);
|
||||
if ((descbytes - netbytes) < filebytes)
|
||||
if ((descbytes - netbytes) < filebytes) {
|
||||
filebytes = descbytes - netbytes;
|
||||
}
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\tClient(0x%p): sending %d bytes\n", me, filebytes));
|
||||
bytes = PR_Send(fd, buffer, filebytes, SEND_FLAGS, timeout);
|
||||
if (filebytes != bytes)
|
||||
{
|
||||
if (Aborted(PR_FAILURE)) goto aborted;
|
||||
if (Aborted(PR_FAILURE)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
|
|
@ -295,8 +301,9 @@ static void PR_CALLBACK Client(void *arg)
|
|||
while (filebytes < descbytes)
|
||||
{
|
||||
netbytes = sizeof(buffer);
|
||||
if ((descbytes - filebytes) < netbytes)
|
||||
if ((descbytes - filebytes) < netbytes) {
|
||||
netbytes = descbytes - filebytes;
|
||||
}
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\tClient(0x%p): receiving %d bytes\n", me, netbytes));
|
||||
|
|
@ -314,26 +321,28 @@ static void PR_CALLBACK Client(void *arg)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ERROR,
|
||||
("\tClient(0x%p): receive data timeout\n", me));
|
||||
else
|
||||
else
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ERROR,
|
||||
("\tClient(0x%p): receive error (%d, %d)\n",
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
if (0 == bytes)
|
||||
{
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ERROR,
|
||||
("\t\tClient(0x%p): unexpected end of stream\n",
|
||||
PR_GetCurrentThread()));
|
||||
PR_GetCurrentThread()));
|
||||
break;
|
||||
}
|
||||
filebytes += bytes;
|
||||
}
|
||||
|
||||
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
TEST_ASSERT(PR_SUCCESS == rv);
|
||||
retry:
|
||||
(void)PR_Close(fd); fd = NULL;
|
||||
|
|
@ -346,14 +355,18 @@ retry:
|
|||
client->bytesTransferred += 2 * descbytes;
|
||||
rv = PR_WaitCondVar(client->stateChange, rand() % clipping);
|
||||
PR_Unlock(client->ml);
|
||||
if (Aborted(rv)) break;
|
||||
if (Aborted(rv)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
aborted:
|
||||
client->stopped = PR_IntervalNow();
|
||||
|
||||
PR_ClearInterrupt();
|
||||
if (NULL != fd) rv = PR_Close(fd);
|
||||
if (NULL != fd) {
|
||||
rv = PR_Close(fd);
|
||||
}
|
||||
|
||||
PR_Lock(client->ml);
|
||||
client->state = cs_exit;
|
||||
|
|
@ -363,7 +376,7 @@ aborted:
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ALWAYS,
|
||||
("\tClient(0x%p): stopped after %u operations and %u bytes\n",
|
||||
PR_GetCurrentThread(), client->operations, client->bytesTransferred));
|
||||
PR_GetCurrentThread(), client->operations, client->bytesTransferred));
|
||||
|
||||
} /* Client */
|
||||
|
||||
|
|
@ -381,11 +394,13 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\tProcessRequest(0x%p): receiving desciptor\n", me));
|
||||
bytes = PR_Recv(
|
||||
fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
|
||||
fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
|
||||
if (-1 == bytes)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
if (Aborted(rv)) goto exit;
|
||||
if (Aborted(rv)) {
|
||||
goto exit;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
|
|
@ -406,16 +421,18 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
TEST_ASSERT(sizeof(*descriptor) == bytes);
|
||||
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\t\tProcessRequest(0x%p): read descriptor {%d, %s}\n",
|
||||
me, descbytes, descriptor->filename));
|
||||
me, descbytes, descriptor->filename));
|
||||
|
||||
file = PR_Open(
|
||||
descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
|
||||
descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
|
||||
if (NULL == file)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
|
|
@ -430,8 +447,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
while (filebytes < descbytes)
|
||||
{
|
||||
netbytes = sizeof(buffer);
|
||||
if ((descbytes - filebytes) < netbytes)
|
||||
if ((descbytes - filebytes) < netbytes) {
|
||||
netbytes = descbytes - filebytes;
|
||||
}
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\tProcessRequest(0x%p): receive %d bytes\n", me, netbytes));
|
||||
|
|
@ -439,7 +457,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
if (-1 == bytes)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
|
|
@ -455,7 +475,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_WARNING,
|
||||
("\t\tProcessRequest(0x%p): unexpected error (%d, %d)\n",
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
goto aborted;
|
||||
}
|
||||
if(0 == bytes)
|
||||
|
|
@ -477,7 +497,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
if (netbytes != bytes)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
|
|
@ -495,7 +517,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
PR_Unlock(server->ml);
|
||||
|
||||
rv = PR_Close(file); file = NULL;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
TEST_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
TEST_LOG(
|
||||
|
|
@ -505,19 +529,21 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
if (NULL == file)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ERROR,
|
||||
("\t\tProcessRequest(0x%p): open file timeout\n",
|
||||
PR_GetCurrentThread()));
|
||||
PR_GetCurrentThread()));
|
||||
goto aborted;
|
||||
}
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ERROR,
|
||||
("\t\tProcessRequest(0x%p): other file open error (%u, %u)\n",
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
goto aborted;
|
||||
}
|
||||
TEST_ASSERT(NULL != file);
|
||||
|
|
@ -526,8 +552,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
while (netbytes < descbytes)
|
||||
{
|
||||
filebytes = sizeof(buffer);
|
||||
if ((descbytes - netbytes) < filebytes)
|
||||
if ((descbytes - netbytes) < filebytes) {
|
||||
filebytes = descbytes - netbytes;
|
||||
}
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\tProcessRequest(0x%p): read %d bytes from file\n", me, filebytes));
|
||||
|
|
@ -535,7 +562,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
if (filebytes != bytes)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ERROR,
|
||||
|
|
@ -544,7 +573,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ERROR,
|
||||
("\t\tProcessRequest(0x%p): other file error (%d, %d)\n",
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
me, PR_GetError(), PR_GetOSError()));
|
||||
goto aborted;
|
||||
}
|
||||
TEST_ASSERT(bytes > 0);
|
||||
|
|
@ -557,7 +586,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
if (filebytes != bytes)
|
||||
{
|
||||
rv = PR_FAILURE;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
|
||||
{
|
||||
TEST_LOG(
|
||||
|
|
@ -567,23 +598,29 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
|
|||
}
|
||||
break;
|
||||
}
|
||||
TEST_ASSERT(bytes > 0);
|
||||
TEST_ASSERT(bytes > 0);
|
||||
}
|
||||
|
||||
|
||||
PR_Lock(server->ml);
|
||||
server->bytesTransferred += filebytes;
|
||||
PR_Unlock(server->ml);
|
||||
|
||||
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
|
||||
rv = PR_Close(file); file = NULL;
|
||||
if (Aborted(rv)) goto aborted;
|
||||
if (Aborted(rv)) {
|
||||
goto aborted;
|
||||
}
|
||||
TEST_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
aborted:
|
||||
PR_ClearInterrupt();
|
||||
if (NULL != file) PR_Close(file);
|
||||
if (NULL != file) {
|
||||
PR_Close(file);
|
||||
}
|
||||
drv = PR_Delete(descriptor->filename);
|
||||
TEST_ASSERT(PR_SUCCESS == drv);
|
||||
exit:
|
||||
|
|
@ -621,19 +658,6 @@ static void *pthread_start(void *arg)
|
|||
} /* pthread_start */
|
||||
#endif /* defined(_PR_PTHREADS) */
|
||||
|
||||
#if defined(IRIX) && !defined(_PR_PTHREADS)
|
||||
#include <sys/types.h>
|
||||
#include <sys/prctl.h>
|
||||
static void sproc_start(void *arg, PRSize size)
|
||||
{
|
||||
StartObject *so = (StartObject*)arg;
|
||||
StartFn start = so->start;
|
||||
void *data = so->arg;
|
||||
PR_Free(so);
|
||||
start(data);
|
||||
} /* sproc_start */
|
||||
#endif /* defined(IRIX) && !defined(_PR_PTHREADS) */
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <process.h> /* for _beginthreadex() */
|
||||
|
||||
|
|
@ -653,24 +677,24 @@ static PRStatus JoinThread(PRThread *thread)
|
|||
PRStatus rv;
|
||||
switch (thread_provider)
|
||||
{
|
||||
case thread_nspr:
|
||||
rv = PR_JoinThread(thread);
|
||||
break;
|
||||
case thread_pthread:
|
||||
case thread_nspr:
|
||||
rv = PR_JoinThread(thread);
|
||||
break;
|
||||
case thread_pthread:
|
||||
#if defined(_PR_PTHREADS)
|
||||
rv = PR_SUCCESS;
|
||||
break;
|
||||
rv = PR_SUCCESS;
|
||||
break;
|
||||
#endif /* defined(_PR_PTHREADS) */
|
||||
case thread_win32:
|
||||
case thread_win32:
|
||||
#if defined(WIN32)
|
||||
rv = PR_SUCCESS;
|
||||
break;
|
||||
rv = PR_SUCCESS;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
rv = PR_FAILURE;
|
||||
break;
|
||||
default:
|
||||
rv = PR_FAILURE;
|
||||
break;
|
||||
}
|
||||
return rv;
|
||||
return rv;
|
||||
} /* JoinThread */
|
||||
|
||||
static PRStatus NewThread(
|
||||
|
|
@ -680,16 +704,16 @@ static PRStatus NewThread(
|
|||
|
||||
switch (thread_provider)
|
||||
{
|
||||
case thread_nspr:
|
||||
case thread_nspr:
|
||||
{
|
||||
PRThread *thread = PR_CreateThread(
|
||||
PR_USER_THREAD, start, arg,
|
||||
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
|
||||
PR_JOINABLE_THREAD, 0);
|
||||
PR_USER_THREAD, start, arg,
|
||||
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
|
||||
PR_JOINABLE_THREAD, 0);
|
||||
rv = (NULL == thread) ? PR_FAILURE : PR_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case thread_pthread:
|
||||
case thread_pthread:
|
||||
#if defined(_PR_PTHREADS)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -720,41 +744,27 @@ static PRStatus NewThread(
|
|||
#endif /* defined(_PR_PTHREADS) */
|
||||
break;
|
||||
|
||||
case thread_sproc:
|
||||
#if defined(IRIX) && !defined(_PR_PTHREADS)
|
||||
{
|
||||
PRInt32 pid;
|
||||
StartObject *start_object;
|
||||
start_object = PR_NEW(StartObject);
|
||||
PR_ASSERT(NULL != start_object);
|
||||
start_object->start = start;
|
||||
start_object->arg = arg;
|
||||
pid = sprocsp(
|
||||
sproc_start, PR_SALL, start_object, NULL, 64 * 1024);
|
||||
rv = (0 < pid) ? PR_SUCCESS : PR_FAILURE;
|
||||
}
|
||||
#else
|
||||
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
|
||||
rv = PR_FAILURE;
|
||||
#endif /* defined(IRIX) && !defined(_PR_PTHREADS) */
|
||||
break;
|
||||
case thread_win32:
|
||||
case thread_sproc:
|
||||
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
|
||||
rv = PR_FAILURE;
|
||||
break;
|
||||
case thread_win32:
|
||||
#if defined(WIN32)
|
||||
{
|
||||
void *th;
|
||||
PRUintn id;
|
||||
PRUintn id;
|
||||
StartObject *start_object;
|
||||
start_object = PR_NEW(StartObject);
|
||||
PR_ASSERT(NULL != start_object);
|
||||
start_object->start = start;
|
||||
start_object->arg = arg;
|
||||
th = (void*)_beginthreadex(
|
||||
NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
|
||||
0U, /* DWORD - initial thread stack size, in bytes */
|
||||
windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
|
||||
start_object, /* LPVOID - argument for new thread */
|
||||
STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
|
||||
&id /* LPDWORD - pointer to returned thread identifier */ );
|
||||
NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
|
||||
0U, /* DWORD - initial thread stack size, in bytes */
|
||||
windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
|
||||
start_object, /* LPVOID - argument for new thread */
|
||||
STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
|
||||
&id /* LPDWORD - pointer to returned thread identifier */ );
|
||||
|
||||
rv = (NULL == th) ? PR_FAILURE : PR_SUCCESS;
|
||||
}
|
||||
|
|
@ -763,9 +773,9 @@ static PRStatus NewThread(
|
|||
rv = PR_FAILURE;
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
|
||||
rv = PR_FAILURE;
|
||||
default:
|
||||
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
|
||||
rv = PR_FAILURE;
|
||||
}
|
||||
return rv;
|
||||
} /* NewThread */
|
||||
|
|
@ -777,12 +787,14 @@ static PRStatus CreateWorker(CSServer_t *server, CSPool_t *pool)
|
|||
worker->server = server;
|
||||
PR_INIT_CLIST(&worker->element);
|
||||
rv = NewThread(
|
||||
Worker, worker, DEFAULT_SERVER_PRIORITY, PR_UNJOINABLE_THREAD);
|
||||
if (PR_FAILURE == rv) PR_DELETE(worker);
|
||||
Worker, worker, DEFAULT_SERVER_PRIORITY, PR_UNJOINABLE_THREAD);
|
||||
if (PR_FAILURE == rv) {
|
||||
PR_DELETE(worker);
|
||||
}
|
||||
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
|
||||
("\tCreateWorker(0x%p): create new worker (0x%p)\n",
|
||||
PR_GetCurrentThread(), worker->thread));
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
|
||||
("\tCreateWorker(0x%p): create new worker (0x%p)\n",
|
||||
PR_GetCurrentThread(), worker->thread));
|
||||
|
||||
return rv;
|
||||
} /* CreateWorker */
|
||||
|
|
@ -813,17 +825,17 @@ static void PR_CALLBACK Worker(void *arg)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("\t\tWorker(0x%p): waiting for accept slot[%d]\n",
|
||||
me, pool->accepting));
|
||||
me, pool->accepting));
|
||||
rv = PR_WaitCondVar(pool->acceptComplete, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (Aborted(rv) || (cs_run != server->state))
|
||||
{
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_NOTICE,
|
||||
("\tWorker(0x%p): has been %s\n",
|
||||
me, (Aborted(rv) ? "interrupted" : "stopped")));
|
||||
me, (Aborted(rv) ? "interrupted" : "stopped")));
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
pool->accepting += 1; /* how many are really in accept */
|
||||
PR_Unlock(server->ml);
|
||||
|
||||
|
|
@ -832,7 +844,7 @@ static void PR_CALLBACK Worker(void *arg)
|
|||
("\t\tWorker(0x%p): calling accept\n", me));
|
||||
fd = PR_Accept(server->listener, &from, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
PR_Lock(server->ml);
|
||||
PR_Lock(server->ml);
|
||||
pool->accepting -= 1;
|
||||
PR_NotifyCondVar(pool->acceptComplete);
|
||||
|
||||
|
|
@ -858,13 +870,15 @@ static void PR_CALLBACK Worker(void *arg)
|
|||
*/
|
||||
PRBool another =
|
||||
((pool->workers < server->workers.minimum) ||
|
||||
((0 == pool->accepting)
|
||||
&& (pool->workers < server->workers.maximum))) ?
|
||||
PR_TRUE : PR_FALSE;
|
||||
((0 == pool->accepting)
|
||||
&& (pool->workers < server->workers.maximum))) ?
|
||||
PR_TRUE : PR_FALSE;
|
||||
pool->active += 1;
|
||||
PR_Unlock(server->ml);
|
||||
|
||||
if (another) (void)CreateWorker(server, pool);
|
||||
if (another) {
|
||||
(void)CreateWorker(server, pool);
|
||||
}
|
||||
|
||||
rv = ProcessRequest(fd, server);
|
||||
if (PR_SUCCESS != rv)
|
||||
|
|
@ -879,7 +893,7 @@ static void PR_CALLBACK Worker(void *arg)
|
|||
}
|
||||
|
||||
exit:
|
||||
PR_ClearInterrupt();
|
||||
PR_ClearInterrupt();
|
||||
PR_Unlock(server->ml);
|
||||
|
||||
if (NULL != fd)
|
||||
|
|
@ -990,7 +1004,7 @@ static void PR_CALLBACK Server(void *arg)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_NOTICE,
|
||||
("\tServer(0x%p): waiting for %u workers to exit\n",
|
||||
me, server->pool.workers));
|
||||
me, server->pool.workers));
|
||||
(void)PR_WaitCondVar(server->pool.exiting, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
|
||||
|
|
@ -1001,9 +1015,11 @@ static void PR_CALLBACK Server(void *arg)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ALWAYS,
|
||||
("\tServer(0x%p): stopped after %u operations and %u bytes\n",
|
||||
me, server->operations, server->bytesTransferred));
|
||||
me, server->operations, server->bytesTransferred));
|
||||
|
||||
if (NULL != server->listener) PR_Close(server->listener);
|
||||
if (NULL != server->listener) {
|
||||
PR_Close(server->listener);
|
||||
}
|
||||
server->stopped = PR_IntervalNow();
|
||||
|
||||
} /* Server */
|
||||
|
|
@ -1011,10 +1027,12 @@ static void PR_CALLBACK Server(void *arg)
|
|||
static void WaitForCompletion(PRIntn execution)
|
||||
{
|
||||
while (execution > 0)
|
||||
{
|
||||
{
|
||||
PRIntn dally = (execution > 30) ? 30 : execution;
|
||||
PR_Sleep(PR_SecondsToInterval(dally));
|
||||
if (pthread_stats) PT_FPrintStats(debug_out, "\nPThread Statistics\n");
|
||||
if (pthread_stats) {
|
||||
PT_FPrintStats(debug_out, "\nPThread Statistics\n");
|
||||
}
|
||||
execution -= dally;
|
||||
}
|
||||
} /* WaitForCompletion */
|
||||
|
|
@ -1052,7 +1070,7 @@ int main(int argc, char **argv)
|
|||
CSClient_t *client;
|
||||
PRStatus rv, joinStatus;
|
||||
CSServer_t *server = NULL;
|
||||
char *thread_type;
|
||||
char *thread_type;
|
||||
|
||||
PRUintn backlog = DEFAULT_BACKLOG;
|
||||
PRUintn clients = DEFAULT_CLIENTS;
|
||||
|
|
@ -1079,11 +1097,9 @@ int main(int argc, char **argv)
|
|||
PLOptState *opt = PL_CreateOptState(argc, argv, "GX6b:a:c:w:W:e:s:T:vdhp");
|
||||
|
||||
#if defined(WIN32)
|
||||
thread_provider = thread_win32;
|
||||
thread_provider = thread_win32;
|
||||
#elif defined(_PR_PTHREADS)
|
||||
thread_provider = thread_pthread;
|
||||
#elif defined(IRIX)
|
||||
thread_provider = thread_sproc;
|
||||
thread_provider = thread_pthread;
|
||||
#else
|
||||
thread_provider = thread_nspr;
|
||||
#endif
|
||||
|
|
@ -1092,70 +1108,95 @@ int main(int argc, char **argv)
|
|||
|
||||
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
|
||||
{
|
||||
if (PL_OPT_BAD == os) continue;
|
||||
if (PL_OPT_BAD == os) {
|
||||
continue;
|
||||
}
|
||||
switch (opt->option)
|
||||
{
|
||||
case 'G': /* use global threads */
|
||||
thread_scope = PR_GLOBAL_THREAD;
|
||||
break;
|
||||
case 'X': /* use XTP as transport */
|
||||
protocol = 36;
|
||||
break;
|
||||
case '6': /* Use IPv6 */
|
||||
domain = PR_AF_INET6;
|
||||
break;
|
||||
case 'a': /* the value for accepting */
|
||||
accepting = atoi(opt->value);
|
||||
break;
|
||||
case 'b': /* the value for backlock */
|
||||
backlog = atoi(opt->value);
|
||||
break;
|
||||
case 'T': /* the thread provider */
|
||||
if ('n' == *opt->value) thread_provider = thread_nspr;
|
||||
else if ('p' == *opt->value) thread_provider = thread_pthread;
|
||||
else if ('w' == *opt->value) thread_provider = thread_win32;
|
||||
else {Help(); return 2; }
|
||||
break;
|
||||
case 'c': /* number of client threads */
|
||||
clients = atoi(opt->value);
|
||||
break;
|
||||
case 'w': /* minimum server worker threads */
|
||||
workersMin = atoi(opt->value);
|
||||
break;
|
||||
case 'W': /* maximum server worker threads */
|
||||
workersMax = atoi(opt->value);
|
||||
break;
|
||||
case 'e': /* program execution time in seconds */
|
||||
execution = atoi(opt->value);
|
||||
break;
|
||||
case 's': /* server's address */
|
||||
serverName = opt->value;
|
||||
break;
|
||||
case 'v': /* verbosity */
|
||||
verbosity = IncrementVerbosity();
|
||||
break;
|
||||
case 'd': /* debug mode */
|
||||
debug_mode = PR_TRUE;
|
||||
break;
|
||||
case 'p': /* pthread mode */
|
||||
pthread_stats = PR_TRUE;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
Help();
|
||||
return 2;
|
||||
case 'G': /* use global threads */
|
||||
thread_scope = PR_GLOBAL_THREAD;
|
||||
break;
|
||||
case 'X': /* use XTP as transport */
|
||||
protocol = 36;
|
||||
break;
|
||||
case '6': /* Use IPv6 */
|
||||
domain = PR_AF_INET6;
|
||||
break;
|
||||
case 'a': /* the value for accepting */
|
||||
accepting = atoi(opt->value);
|
||||
break;
|
||||
case 'b': /* the value for backlock */
|
||||
backlog = atoi(opt->value);
|
||||
break;
|
||||
case 'T': /* the thread provider */
|
||||
if ('n' == *opt->value) {
|
||||
thread_provider = thread_nspr;
|
||||
}
|
||||
else if ('p' == *opt->value) {
|
||||
thread_provider = thread_pthread;
|
||||
}
|
||||
else if ('w' == *opt->value) {
|
||||
thread_provider = thread_win32;
|
||||
}
|
||||
else {
|
||||
Help();
|
||||
return 2;
|
||||
}
|
||||
break;
|
||||
case 'c': /* number of client threads */
|
||||
clients = atoi(opt->value);
|
||||
break;
|
||||
case 'w': /* minimum server worker threads */
|
||||
workersMin = atoi(opt->value);
|
||||
break;
|
||||
case 'W': /* maximum server worker threads */
|
||||
workersMax = atoi(opt->value);
|
||||
break;
|
||||
case 'e': /* program execution time in seconds */
|
||||
execution = atoi(opt->value);
|
||||
break;
|
||||
case 's': /* server's address */
|
||||
serverName = opt->value;
|
||||
break;
|
||||
case 'v': /* verbosity */
|
||||
verbosity = IncrementVerbosity();
|
||||
break;
|
||||
case 'd': /* debug mode */
|
||||
debug_mode = PR_TRUE;
|
||||
break;
|
||||
case 'p': /* pthread mode */
|
||||
pthread_stats = PR_TRUE;
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
Help();
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
PL_DestroyOptState(opt);
|
||||
|
||||
if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) serverIsLocal = PR_FALSE;
|
||||
if (0 == execution) execution = DEFAULT_EXECUTION_TIME;
|
||||
if (0 == workersMax) workersMax = DEFAULT_WORKERS_MAX;
|
||||
if (0 == workersMin) workersMin = DEFAULT_WORKERS_MIN;
|
||||
if (0 == accepting) accepting = ALLOWED_IN_ACCEPT;
|
||||
if (0 == backlog) backlog = DEFAULT_BACKLOG;
|
||||
if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) {
|
||||
serverIsLocal = PR_FALSE;
|
||||
}
|
||||
if (0 == execution) {
|
||||
execution = DEFAULT_EXECUTION_TIME;
|
||||
}
|
||||
if (0 == workersMax) {
|
||||
workersMax = DEFAULT_WORKERS_MAX;
|
||||
}
|
||||
if (0 == workersMin) {
|
||||
workersMin = DEFAULT_WORKERS_MIN;
|
||||
}
|
||||
if (0 == accepting) {
|
||||
accepting = ALLOWED_IN_ACCEPT;
|
||||
}
|
||||
if (0 == backlog) {
|
||||
backlog = DEFAULT_BACKLOG;
|
||||
}
|
||||
|
||||
if (workersMin > accepting) accepting = workersMin;
|
||||
if (workersMin > accepting) {
|
||||
accepting = workersMin;
|
||||
}
|
||||
|
||||
PR_STDIO_INIT();
|
||||
TimeOfDayMessage("Client/Server started at", PR_GetCurrentThread());
|
||||
|
|
@ -1190,7 +1231,7 @@ int main(int argc, char **argv)
|
|||
("main(0x%p): creating server thread\n", PR_GetCurrentThread()));
|
||||
|
||||
rv = NewThread(
|
||||
Server, server, PR_PRIORITY_HIGH, PR_JOINABLE_THREAD);
|
||||
Server, server, PR_PRIORITY_HIGH, PR_JOINABLE_THREAD);
|
||||
TEST_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
TEST_LOG(
|
||||
|
|
@ -1198,14 +1239,15 @@ int main(int argc, char **argv)
|
|||
("main(0x%p): waiting for server init\n", PR_GetCurrentThread()));
|
||||
|
||||
PR_Lock(server->ml);
|
||||
while (server->state == cs_init)
|
||||
while (server->state == cs_init) {
|
||||
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
PR_Unlock(server->ml);
|
||||
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("main(0x%p): server init complete (port #%d)\n",
|
||||
PR_GetCurrentThread(), server->port));
|
||||
PR_GetCurrentThread(), server->port));
|
||||
}
|
||||
|
||||
if (clients != 0)
|
||||
|
|
@ -1218,8 +1260,8 @@ int main(int argc, char **argv)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("main(0x%p): creating %d client threads\n",
|
||||
PR_GetCurrentThread(), clients));
|
||||
|
||||
PR_GetCurrentThread(), clients));
|
||||
|
||||
if (!serverIsLocal)
|
||||
{
|
||||
rv = PR_GetHostByName(serverName, buffer, BUFFER_SIZE, &host);
|
||||
|
|
@ -1250,11 +1292,12 @@ int main(int argc, char **argv)
|
|||
cltsrv_log_file, TEST_LOG_INFO,
|
||||
("main(0x%p): creating client threads\n", PR_GetCurrentThread()));
|
||||
rv = NewThread(
|
||||
Client, &client[index], PR_PRIORITY_NORMAL, PR_JOINABLE_THREAD);
|
||||
Client, &client[index], PR_PRIORITY_NORMAL, PR_JOINABLE_THREAD);
|
||||
TEST_ASSERT(PR_SUCCESS == rv);
|
||||
PR_Lock(client[index].ml);
|
||||
while (cs_init == client[index].state)
|
||||
while (cs_init == client[index].state) {
|
||||
PR_WaitCondVar(client[index].stateChange, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
PR_Unlock(client[index].ml);
|
||||
}
|
||||
}
|
||||
|
|
@ -1263,7 +1306,7 @@ int main(int argc, char **argv)
|
|||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ALWAYS,
|
||||
("main(0x%p): waiting for execution interval (%d seconds)\n",
|
||||
PR_GetCurrentThread(), execution));
|
||||
PR_GetCurrentThread(), execution));
|
||||
|
||||
WaitForCompletion(execution);
|
||||
|
||||
|
|
@ -1273,9 +1316,9 @@ int main(int argc, char **argv)
|
|||
{
|
||||
for (index = 0; index < clients; ++index)
|
||||
{
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
|
||||
("main(0x%p): notifying client(0x%p) to stop\n",
|
||||
PR_GetCurrentThread(), client[index].thread));
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
|
||||
("main(0x%p): notifying client(0x%p) to stop\n",
|
||||
PR_GetCurrentThread(), client[index].thread));
|
||||
|
||||
PR_Lock(client[index].ml);
|
||||
if (cs_run == client[index].state)
|
||||
|
|
@ -1288,12 +1331,12 @@ int main(int argc, char **argv)
|
|||
}
|
||||
PR_Unlock(client[index].ml);
|
||||
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("main(0x%p): joining client(0x%p)\n",
|
||||
PR_GetCurrentThread(), client[index].thread));
|
||||
TEST_LOG(cltsrv_log_file, TEST_LOG_VERBOSE,
|
||||
("main(0x%p): joining client(0x%p)\n",
|
||||
PR_GetCurrentThread(), client[index].thread));
|
||||
|
||||
joinStatus = JoinThread(client[index].thread);
|
||||
TEST_ASSERT(PR_SUCCESS == joinStatus);
|
||||
joinStatus = JoinThread(client[index].thread);
|
||||
TEST_ASSERT(PR_SUCCESS == joinStatus);
|
||||
PR_DestroyCondVar(client[index].stateChange);
|
||||
PR_DestroyLock(client[index].ml);
|
||||
}
|
||||
|
|
@ -1304,21 +1347,22 @@ int main(int argc, char **argv)
|
|||
{
|
||||
/* All clients joined - retrieve the server */
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_NOTICE,
|
||||
cltsrv_log_file, TEST_LOG_NOTICE,
|
||||
("main(0x%p): notifying server(0x%p) to stop\n",
|
||||
PR_GetCurrentThread(), server->thread));
|
||||
PR_GetCurrentThread(), server->thread));
|
||||
|
||||
PR_Lock(server->ml);
|
||||
server->state = cs_stop;
|
||||
PR_Interrupt(server->thread);
|
||||
while (cs_exit != server->state)
|
||||
while (cs_exit != server->state) {
|
||||
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
PR_Unlock(server->ml);
|
||||
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_NOTICE,
|
||||
cltsrv_log_file, TEST_LOG_NOTICE,
|
||||
("main(0x%p): joining server(0x%p)\n",
|
||||
PR_GetCurrentThread(), server->thread));
|
||||
PR_GetCurrentThread(), server->thread));
|
||||
joinStatus = JoinThread(server->thread);
|
||||
TEST_ASSERT(PR_SUCCESS == joinStatus);
|
||||
|
||||
|
|
@ -1330,19 +1374,22 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
TEST_LOG(
|
||||
cltsrv_log_file, TEST_LOG_ALWAYS,
|
||||
cltsrv_log_file, TEST_LOG_ALWAYS,
|
||||
("main(0x%p): test complete\n", PR_GetCurrentThread()));
|
||||
|
||||
if (thread_provider == thread_win32)
|
||||
thread_type = "\nWin32 Thread Statistics\n";
|
||||
else if (thread_provider == thread_pthread)
|
||||
thread_type = "\npthread Statistics\n";
|
||||
else if (thread_provider == thread_sproc)
|
||||
thread_type = "\nsproc Statistics\n";
|
||||
if (thread_provider == thread_win32) {
|
||||
thread_type = "\nWin32 Thread Statistics\n";
|
||||
}
|
||||
else if (thread_provider == thread_pthread) {
|
||||
thread_type = "\npthread Statistics\n";
|
||||
}
|
||||
else if (thread_provider == thread_sproc) {
|
||||
thread_type = "\nsproc Statistics\n";
|
||||
}
|
||||
else {
|
||||
PR_ASSERT(thread_provider == thread_nspr);
|
||||
thread_type = "\nPRThread Statistics\nn";
|
||||
}
|
||||
PR_ASSERT(thread_provider == thread_nspr);
|
||||
thread_type = "\nPRThread Statistics\nn";
|
||||
}
|
||||
|
||||
PT_FPrintStats(debug_out, thread_type);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue