White spaces and indentation.
This commit is contained in:
parent
6c125feea0
commit
fdb8b9ef2f
@ -414,11 +414,11 @@ static void SetSeed(void)
|
|||||||
|
|
||||||
gettimeofday(&t, NULL);
|
gettimeofday(&t, NULL);
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id().p);
|
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id().p);
|
||||||
#elif defined(BSD) || defined(__OSX__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
|
#elif defined(BSD) || defined(__OSX__) || defined(__APPLE__) || defined(__FreeBSD_kernel__)
|
||||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
||||||
#elif defined(__linux__) || defined(__sun) || defined(__CYGWIN__) || defined(__GLIBC__)
|
#elif defined(__linux__) || defined(__sun) || defined(__CYGWIN__) || defined(__GLIBC__)
|
||||||
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
srand((unsigned int)t.tv_usec + (unsigned int)ithread_get_current_thread_id());
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
volatile union {
|
volatile union {
|
||||||
@ -780,9 +780,8 @@ int ThreadPoolAddPersistent(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
|
|||||||
ithread_cond_signal(&tp->condition);
|
ithread_cond_signal(&tp->condition);
|
||||||
|
|
||||||
/* wait until long job has been picked up */
|
/* wait until long job has been picked up */
|
||||||
while (tp->persistentJob) {
|
while (tp->persistentJob)
|
||||||
ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
|
ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
|
||||||
}
|
|
||||||
*jobId = tp->lastJobId++;
|
*jobId = tp->lastJobId++;
|
||||||
|
|
||||||
exit_function:
|
exit_function:
|
||||||
@ -798,9 +797,8 @@ int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
|
|||||||
long totalJobs;
|
long totalJobs;
|
||||||
ThreadPoolJob *temp = NULL;
|
ThreadPoolJob *temp = NULL;
|
||||||
|
|
||||||
if (!tp || !job) {
|
if (!tp || !job)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
ithread_mutex_lock(&tp->mutex);
|
ithread_mutex_lock(&tp->mutex);
|
||||||
|
|
||||||
@ -809,38 +807,29 @@ int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
|
|||||||
fprintf(stderr, "total jobs = %ld, too many jobs", totalJobs);
|
fprintf(stderr, "total jobs = %ld, too many jobs", totalJobs);
|
||||||
goto exit_function;
|
goto exit_function;
|
||||||
}
|
}
|
||||||
if (!jobId) {
|
if (!jobId)
|
||||||
jobId = &tempId;
|
jobId = &tempId;
|
||||||
}
|
|
||||||
*jobId = INVALID_JOB_ID;
|
*jobId = INVALID_JOB_ID;
|
||||||
temp = CreateThreadPoolJob(job, tp->lastJobId, tp);
|
temp = CreateThreadPoolJob(job, tp->lastJobId, tp);
|
||||||
if (!temp) {
|
if (!temp)
|
||||||
goto exit_function;
|
goto exit_function;
|
||||||
}
|
|
||||||
if (job->priority == HIGH_PRIORITY) {
|
if (job->priority == HIGH_PRIORITY) {
|
||||||
if (ListAddTail(&tp->highJobQ, temp)) {
|
if (ListAddTail(&tp->highJobQ, temp))
|
||||||
rc = 0;
|
rc = 0;
|
||||||
}
|
|
||||||
} else if (job->priority == MED_PRIORITY) {
|
} else if (job->priority == MED_PRIORITY) {
|
||||||
if (ListAddTail(&tp->medJobQ, temp)) {
|
if (ListAddTail(&tp->medJobQ, temp))
|
||||||
rc = 0;
|
rc = 0;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (ListAddTail(&tp->lowJobQ, temp)) {
|
if (ListAddTail(&tp->lowJobQ, temp))
|
||||||
rc = 0;
|
rc = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* AddWorker if appropriate */
|
/* AddWorker if appropriate */
|
||||||
AddWorker(tp);
|
AddWorker(tp);
|
||||||
|
|
||||||
/* Notify a waiting thread */
|
/* Notify a waiting thread */
|
||||||
if (rc == 0) {
|
if (rc == 0)
|
||||||
ithread_cond_signal(&tp->condition);
|
ithread_cond_signal(&tp->condition);
|
||||||
} else {
|
else
|
||||||
FreeThreadPoolJob(tp, temp);
|
FreeThreadPoolJob(tp, temp);
|
||||||
}
|
|
||||||
|
|
||||||
*jobId = tp->lastJobId++;
|
*jobId = tp->lastJobId++;
|
||||||
|
|
||||||
exit_function:
|
exit_function:
|
||||||
@ -856,12 +845,10 @@ int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out)
|
|||||||
ListNode *tempNode = NULL;
|
ListNode *tempNode = NULL;
|
||||||
ThreadPoolJob dummy;
|
ThreadPoolJob dummy;
|
||||||
|
|
||||||
if (!tp) {
|
if (!tp)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
if (!out)
|
||||||
if (!out) {
|
|
||||||
out = &dummy;
|
out = &dummy;
|
||||||
}
|
|
||||||
dummy.jobId = jobId;
|
dummy.jobId = jobId;
|
||||||
|
|
||||||
ithread_mutex_lock(&tp->mutex);
|
ithread_mutex_lock(&tp->mutex);
|
||||||
@ -910,16 +897,13 @@ exit_function:
|
|||||||
|
|
||||||
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out)
|
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out)
|
||||||
{
|
{
|
||||||
if (!tp || !out) {
|
if (!tp || !out)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
if (!tp->shutdown)
|
||||||
if (!tp->shutdown) {
|
|
||||||
ithread_mutex_lock(&tp->mutex);
|
ithread_mutex_lock(&tp->mutex);
|
||||||
}
|
|
||||||
*out = tp->attr;
|
*out = tp->attr;
|
||||||
if (!tp->shutdown) {
|
if (!tp->shutdown)
|
||||||
ithread_mutex_unlock(&tp->mutex);
|
ithread_mutex_unlock(&tp->mutex);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -930,20 +914,17 @@ int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr)
|
|||||||
ThreadPoolAttr temp;
|
ThreadPoolAttr temp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!tp) {
|
if (!tp)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
ithread_mutex_lock(&tp->mutex);
|
ithread_mutex_lock(&tp->mutex);
|
||||||
|
|
||||||
if (attr) {
|
if (attr)
|
||||||
temp = *attr;
|
temp = *attr;
|
||||||
} else {
|
else
|
||||||
TPAttrInit(&temp);
|
TPAttrInit(&temp);
|
||||||
}
|
|
||||||
if (SetPolicyType(temp.schedPolicy) != 0) {
|
if (SetPolicyType(temp.schedPolicy) != 0) {
|
||||||
ithread_mutex_unlock(&tp->mutex);
|
ithread_mutex_unlock(&tp->mutex);
|
||||||
|
|
||||||
return INVALID_POLICY;
|
return INVALID_POLICY;
|
||||||
}
|
}
|
||||||
tp->attr = temp;
|
tp->attr = temp;
|
||||||
@ -961,10 +942,9 @@ int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr)
|
|||||||
|
|
||||||
ithread_mutex_unlock(&tp->mutex);
|
ithread_mutex_unlock(&tp->mutex);
|
||||||
|
|
||||||
if (retCode != 0) {
|
if (retCode != 0)
|
||||||
/* clean up if the min threads could not be created */
|
/* clean up if the min threads could not be created */
|
||||||
ThreadPoolShutdown(tp);
|
ThreadPoolShutdown(tp);
|
||||||
}
|
|
||||||
|
|
||||||
return retCode;
|
return retCode;
|
||||||
}
|
}
|
||||||
@ -974,54 +954,44 @@ int ThreadPoolShutdown(ThreadPool *tp)
|
|||||||
ListNode *head = NULL;
|
ListNode *head = NULL;
|
||||||
ThreadPoolJob *temp = NULL;
|
ThreadPoolJob *temp = NULL;
|
||||||
|
|
||||||
if (!tp) {
|
if (!tp)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
ithread_mutex_lock(&tp->mutex);
|
ithread_mutex_lock(&tp->mutex);
|
||||||
|
|
||||||
/* clean up high priority jobs */
|
/* clean up high priority jobs */
|
||||||
while (tp->highJobQ.size) {
|
while (tp->highJobQ.size) {
|
||||||
head = ListHead(&tp->highJobQ);
|
head = ListHead(&tp->highJobQ);
|
||||||
temp = (ThreadPoolJob *)head->item;
|
temp = (ThreadPoolJob *)head->item;
|
||||||
if (temp->free_func) {
|
if (temp->free_func)
|
||||||
temp->free_func(temp->arg);
|
temp->free_func(temp->arg);
|
||||||
}
|
|
||||||
FreeThreadPoolJob(tp, temp);
|
FreeThreadPoolJob(tp, temp);
|
||||||
ListDelNode(&tp->highJobQ, head, 0);
|
ListDelNode(&tp->highJobQ, head, 0);
|
||||||
}
|
}
|
||||||
ListDestroy(&tp->highJobQ, 0);
|
ListDestroy(&tp->highJobQ, 0);
|
||||||
|
|
||||||
/* clean up med priority jobs */
|
/* clean up med priority jobs */
|
||||||
while (tp->medJobQ.size) {
|
while (tp->medJobQ.size) {
|
||||||
head = ListHead(&tp->medJobQ);
|
head = ListHead(&tp->medJobQ);
|
||||||
temp = (ThreadPoolJob *)head->item;
|
temp = (ThreadPoolJob *)head->item;
|
||||||
if (temp->free_func) {
|
if (temp->free_func)
|
||||||
temp->free_func(temp->arg);
|
temp->free_func(temp->arg);
|
||||||
}
|
|
||||||
FreeThreadPoolJob(tp, temp);
|
FreeThreadPoolJob(tp, temp);
|
||||||
ListDelNode(&tp->medJobQ, head, 0);
|
ListDelNode(&tp->medJobQ, head, 0);
|
||||||
}
|
}
|
||||||
ListDestroy(&tp->medJobQ, 0);
|
ListDestroy(&tp->medJobQ, 0);
|
||||||
|
|
||||||
/* clean up low priority jobs */
|
/* clean up low priority jobs */
|
||||||
while (tp->lowJobQ.size) {
|
while (tp->lowJobQ.size) {
|
||||||
head = ListHead(&tp->lowJobQ);
|
head = ListHead(&tp->lowJobQ);
|
||||||
temp = (ThreadPoolJob *)head->item;
|
temp = (ThreadPoolJob *)head->item;
|
||||||
if (temp->free_func) {
|
if (temp->free_func)
|
||||||
temp->free_func(temp->arg);
|
temp->free_func(temp->arg);
|
||||||
}
|
|
||||||
FreeThreadPoolJob(tp, temp);
|
FreeThreadPoolJob(tp, temp);
|
||||||
ListDelNode(&tp->lowJobQ, head, 0);
|
ListDelNode(&tp->lowJobQ, head, 0);
|
||||||
}
|
}
|
||||||
ListDestroy(&tp->lowJobQ, 0);
|
ListDestroy(&tp->lowJobQ, 0);
|
||||||
|
|
||||||
/* clean up long term job */
|
/* clean up long term job */
|
||||||
if (tp->persistentJob) {
|
if (tp->persistentJob) {
|
||||||
temp = tp->persistentJob;
|
temp = tp->persistentJob;
|
||||||
if (temp->free_func) {
|
if (temp->free_func)
|
||||||
temp->free_func(temp->arg);
|
temp->free_func(temp->arg);
|
||||||
}
|
|
||||||
FreeThreadPoolJob(tp, temp);
|
FreeThreadPoolJob(tp, temp);
|
||||||
tp->persistentJob = NULL;
|
tp->persistentJob = NULL;
|
||||||
}
|
}
|
||||||
@ -1029,33 +999,25 @@ int ThreadPoolShutdown(ThreadPool *tp)
|
|||||||
tp->shutdown = 1;
|
tp->shutdown = 1;
|
||||||
ithread_cond_broadcast(&tp->condition);
|
ithread_cond_broadcast(&tp->condition);
|
||||||
/* wait for all threads to finish */
|
/* wait for all threads to finish */
|
||||||
while (tp->totalThreads > 0) {
|
while (tp->totalThreads > 0)
|
||||||
ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
|
ithread_cond_wait(&tp->start_and_shutdown, &tp->mutex);
|
||||||
}
|
|
||||||
/* destroy condition */
|
/* destroy condition */
|
||||||
while (ithread_cond_destroy(&tp->condition) != 0) {
|
while (ithread_cond_destroy(&tp->condition) != 0) {}
|
||||||
/**/
|
while (ithread_cond_destroy(&tp->start_and_shutdown) != 0) {}
|
||||||
}
|
|
||||||
while (ithread_cond_destroy(&tp->start_and_shutdown) != 0) {
|
|
||||||
/**/
|
|
||||||
}
|
|
||||||
FreeListDestroy(&tp->jobFreeList);
|
FreeListDestroy(&tp->jobFreeList);
|
||||||
|
|
||||||
ithread_mutex_unlock(&tp->mutex);
|
ithread_mutex_unlock(&tp->mutex);
|
||||||
|
|
||||||
/* destroy mutex */
|
/* destroy mutex */
|
||||||
while (ithread_mutex_destroy(&tp->mutex) != 0) {
|
while (ithread_mutex_destroy(&tp->mutex) != 0) {}
|
||||||
/**/
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int TPAttrInit(ThreadPoolAttr *attr)
|
int TPAttrInit(ThreadPoolAttr *attr)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->jobsPerThread = DEFAULT_JOBS_PER_THREAD;
|
attr->jobsPerThread = DEFAULT_JOBS_PER_THREAD;
|
||||||
attr->maxIdleTime = DEFAULT_IDLE_TIME;
|
attr->maxIdleTime = DEFAULT_IDLE_TIME;
|
||||||
attr->maxThreads = DEFAULT_MAX_THREADS;
|
attr->maxThreads = DEFAULT_MAX_THREADS;
|
||||||
@ -1070,9 +1032,8 @@ int TPAttrInit(ThreadPoolAttr *attr)
|
|||||||
|
|
||||||
int TPJobInit(ThreadPoolJob *job, start_routine func, void *arg)
|
int TPJobInit(ThreadPoolJob *job, start_routine func, void *arg)
|
||||||
{
|
{
|
||||||
if (!job || !func) {
|
if (!job || !func)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
job->func = func;
|
job->func = func;
|
||||||
job->arg = arg;
|
job->arg = arg;
|
||||||
job->priority = DEFAULT_PRIORITY;
|
job->priority = DEFAULT_PRIORITY;
|
||||||
@ -1083,9 +1044,8 @@ int TPJobInit(ThreadPoolJob *job, start_routine func, void *arg)
|
|||||||
|
|
||||||
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
|
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
|
||||||
{
|
{
|
||||||
if (!job) {
|
if (!job)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
if (priority == LOW_PRIORITY ||
|
if (priority == LOW_PRIORITY ||
|
||||||
priority == MED_PRIORITY ||
|
priority == MED_PRIORITY ||
|
||||||
priority == HIGH_PRIORITY) {
|
priority == HIGH_PRIORITY) {
|
||||||
@ -1098,9 +1058,8 @@ int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
|
|||||||
|
|
||||||
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
|
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
|
||||||
{
|
{
|
||||||
if(!job) {
|
if(!job)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
job->free_func = func;
|
job->free_func = func;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1108,9 +1067,8 @@ int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
|
|||||||
|
|
||||||
int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
|
int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->maxThreads = maxThreads;
|
attr->maxThreads = maxThreads;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1118,9 +1076,8 @@ int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
|
|||||||
|
|
||||||
int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
|
int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->minThreads = minThreads;
|
attr->minThreads = minThreads;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1128,9 +1085,8 @@ int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
|
|||||||
|
|
||||||
int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
|
int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->stackSize = stackSize;
|
attr->stackSize = stackSize;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1138,9 +1094,8 @@ int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
|
|||||||
|
|
||||||
int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
|
int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->maxIdleTime = idleTime;
|
attr->maxIdleTime = idleTime;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1148,9 +1103,8 @@ int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
|
|||||||
|
|
||||||
int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
|
int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->jobsPerThread = jobsPerThread;
|
attr->jobsPerThread = jobsPerThread;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1158,9 +1112,8 @@ int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
|
|||||||
|
|
||||||
int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
|
int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->starvationTime = starvationTime;
|
attr->starvationTime = starvationTime;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1168,9 +1121,8 @@ int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
|
|||||||
|
|
||||||
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
|
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->schedPolicy = schedPolicy;
|
attr->schedPolicy = schedPolicy;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1178,9 +1130,8 @@ int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
|
|||||||
|
|
||||||
int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal)
|
int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal)
|
||||||
{
|
{
|
||||||
if (!attr) {
|
if (!attr)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
attr->maxJobsTotal = maxJobsTotal;
|
attr->maxJobsTotal = maxJobsTotal;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1189,9 +1140,8 @@ int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal)
|
|||||||
#ifdef STATS
|
#ifdef STATS
|
||||||
void ThreadPoolPrintStats(ThreadPoolStats *stats)
|
void ThreadPoolPrintStats(ThreadPoolStats *stats)
|
||||||
{
|
{
|
||||||
if (!stats) {
|
if (!stats)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
/* some OSses time_t length may depending on platform, promote it to long for safety */
|
/* some OSses time_t length may depending on platform, promote it to long for safety */
|
||||||
printf("ThreadPoolStats at Time: %ld\n", (long)StatsTime(NULL));
|
printf("ThreadPoolStats at Time: %ld\n", (long)StatsTime(NULL));
|
||||||
printf("High Jobs pending: %d\n", stats->currentJobsHQ);
|
printf("High Jobs pending: %d\n", stats->currentJobsHQ);
|
||||||
@ -1211,40 +1161,34 @@ void ThreadPoolPrintStats(ThreadPoolStats *stats)
|
|||||||
|
|
||||||
int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
|
int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
|
||||||
{
|
{
|
||||||
if (tp == NULL || stats == NULL) {
|
if (tp == NULL || stats == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
|
|
||||||
/* if not shutdown then acquire mutex */
|
/* if not shutdown then acquire mutex */
|
||||||
if (!tp->shutdown) {
|
if (!tp->shutdown)
|
||||||
ithread_mutex_lock(&tp->mutex);
|
ithread_mutex_lock(&tp->mutex);
|
||||||
}
|
|
||||||
|
|
||||||
*stats = tp->stats;
|
*stats = tp->stats;
|
||||||
if (stats->totalJobsHQ > 0) {
|
if (stats->totalJobsHQ > 0)
|
||||||
stats->avgWaitHQ = stats->totalTimeHQ / stats->totalJobsHQ;
|
stats->avgWaitHQ = stats->totalTimeHQ / stats->totalJobsHQ;
|
||||||
} else {
|
else
|
||||||
stats->avgWaitHQ = 0;
|
stats->avgWaitHQ = 0;
|
||||||
}
|
if (stats->totalJobsMQ > 0)
|
||||||
if (stats->totalJobsMQ > 0) {
|
|
||||||
stats->avgWaitMQ = stats->totalTimeMQ / stats->totalJobsMQ;
|
stats->avgWaitMQ = stats->totalTimeMQ / stats->totalJobsMQ;
|
||||||
} else {
|
else
|
||||||
stats->avgWaitMQ = 0;
|
stats->avgWaitMQ = 0;
|
||||||
}
|
if (stats->totalJobsLQ > 0)
|
||||||
if (stats->totalJobsLQ > 0) {
|
|
||||||
stats->avgWaitLQ = stats->totalTimeLQ / stats->totalJobsLQ;
|
stats->avgWaitLQ = stats->totalTimeLQ / stats->totalJobsLQ;
|
||||||
} else {
|
else
|
||||||
stats->avgWaitLQ = 0;
|
stats->avgWaitLQ = 0;
|
||||||
}
|
|
||||||
stats->totalThreads = tp->totalThreads;
|
stats->totalThreads = tp->totalThreads;
|
||||||
stats->persistentThreads = tp->persistentThreads;
|
stats->persistentThreads = tp->persistentThreads;
|
||||||
stats->currentJobsHQ = (int)ListSize(&tp->highJobQ);
|
stats->currentJobsHQ = (int)ListSize(&tp->highJobQ);
|
||||||
stats->currentJobsLQ = (int)ListSize(&tp->lowJobQ);
|
stats->currentJobsLQ = (int)ListSize(&tp->lowJobQ);
|
||||||
stats->currentJobsMQ = (int)ListSize(&tp->medJobQ);
|
stats->currentJobsMQ = (int)ListSize(&tp->medJobQ);
|
||||||
|
|
||||||
/* if not shutdown then release mutex */
|
/* if not shutdown then release mutex */
|
||||||
if (!tp->shutdown) {
|
if (!tp->shutdown)
|
||||||
ithread_mutex_unlock(&tp->mutex);
|
ithread_mutex_unlock(&tp->mutex);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1288,4 +1232,3 @@ int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
|
@ -520,7 +520,6 @@ exit_function:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int UpnpFinish(void)
|
int UpnpFinish(void)
|
||||||
{
|
{
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
@ -531,75 +530,64 @@ int UpnpFinish(void)
|
|||||||
#endif
|
#endif
|
||||||
struct Handle_Info *temp;
|
struct Handle_Info *temp;
|
||||||
|
|
||||||
if (UpnpSdkInit != 1) {
|
if (UpnpSdkInit != 1)
|
||||||
return UPNP_E_FINISH;
|
return UPNP_E_FINISH;
|
||||||
}
|
|
||||||
|
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"Inside UpnpFinish: UpnpSdkInit is %d\n", UpnpSdkInit);
|
"Inside UpnpFinish: UpnpSdkInit is %d\n", UpnpSdkInit);
|
||||||
if (UpnpSdkInit == 1) {
|
if (UpnpSdkInit == 1)
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"UpnpFinish: UpnpSdkInit is ONE\n");
|
"UpnpFinish: UpnpSdkInit is ONE\n");
|
||||||
}
|
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__,
|
||||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
"Send Thread Pool");
|
||||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__,
|
||||||
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
"Recv Thread Pool");
|
||||||
|
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__,
|
||||||
|
"MiniServer Thread Pool");
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
if (GetDeviceHandleInfo(AF_INET, &device_handle, &temp) == HND_DEVICE ) {
|
if (GetDeviceHandleInfo(AF_INET, &device_handle, &temp) == HND_DEVICE)
|
||||||
UpnpUnRegisterRootDevice(device_handle);
|
UpnpUnRegisterRootDevice(device_handle);
|
||||||
}
|
if (GetDeviceHandleInfo(AF_INET6, &device_handle, &temp) == HND_DEVICE)
|
||||||
if (GetDeviceHandleInfo(AF_INET6, &device_handle, &temp) == HND_DEVICE ) {
|
|
||||||
UpnpUnRegisterRootDevice(device_handle);
|
UpnpUnRegisterRootDevice(device_handle);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
if (GetClientHandleInfo(&client_handle, &temp) == HND_CLIENT) {
|
if (GetClientHandleInfo(&client_handle, &temp) == HND_CLIENT)
|
||||||
UpnpUnRegisterClient(client_handle);
|
UpnpUnRegisterClient(client_handle);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TimerThreadShutdown(&gTimerThread);
|
TimerThreadShutdown(&gTimerThread);
|
||||||
StopMiniServer();
|
StopMiniServer();
|
||||||
|
|
||||||
#if EXCLUDE_WEB_SERVER == 0
|
#if EXCLUDE_WEB_SERVER == 0
|
||||||
web_server_destroy();
|
web_server_destroy();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ThreadPoolShutdown(&gMiniServerThreadPool);
|
ThreadPoolShutdown(&gMiniServerThreadPool);
|
||||||
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__, "MiniServer Thread Pool");
|
PrintThreadPoolStats(&gMiniServerThreadPool, __FILE__, __LINE__,
|
||||||
|
"MiniServer Thread Pool");
|
||||||
ThreadPoolShutdown(&gRecvThreadPool);
|
ThreadPoolShutdown(&gRecvThreadPool);
|
||||||
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__, "Send Thread Pool");
|
PrintThreadPoolStats(&gSendThreadPool, __FILE__, __LINE__,
|
||||||
|
"Send Thread Pool");
|
||||||
ThreadPoolShutdown(&gSendThreadPool);
|
ThreadPoolShutdown(&gSendThreadPool);
|
||||||
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__, "Recv Thread Pool");
|
PrintThreadPoolStats(&gRecvThreadPool, __FILE__, __LINE__,
|
||||||
|
"Recv Thread Pool");
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
ithread_mutex_destroy(&GlobalClientSubscribeMutex);
|
ithread_mutex_destroy(&GlobalClientSubscribeMutex);
|
||||||
#endif
|
#endif
|
||||||
ithread_rwlock_destroy(&GlobalHndRWLock);
|
ithread_rwlock_destroy(&GlobalHndRWLock);
|
||||||
ithread_mutex_destroy(&gUUIDMutex);
|
ithread_mutex_destroy(&gUUIDMutex);
|
||||||
|
|
||||||
/* remove all virtual dirs */
|
/* remove all virtual dirs */
|
||||||
UpnpRemoveAllVirtualDirs();
|
UpnpRemoveAllVirtualDirs();
|
||||||
|
|
||||||
/* Clean-up ithread library resources */
|
/* Clean-up ithread library resources */
|
||||||
ithread_cleanup_library();
|
ithread_cleanup_library();
|
||||||
|
|
||||||
UpnpSdkInit = 0;
|
UpnpSdkInit = 0;
|
||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"Exiting UpnpFinish: UpnpSdkInit is :%d:\n", UpnpSdkInit);
|
"Exiting UpnpFinish: UpnpSdkInit is :%d:\n", UpnpSdkInit);
|
||||||
UpnpCloseLog();
|
UpnpCloseLog();
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
return UPNP_E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned short UpnpGetServerPort(void)
|
unsigned short UpnpGetServerPort(void)
|
||||||
{
|
{
|
||||||
if (UpnpSdkInit != 1) {
|
if (UpnpSdkInit != 1)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return LOCAL_PORT_V4;
|
return LOCAL_PORT_V4;
|
||||||
}
|
}
|
||||||
@ -607,44 +595,37 @@ unsigned short UpnpGetServerPort(void)
|
|||||||
#ifdef UPNP_ENABLE_IPV6
|
#ifdef UPNP_ENABLE_IPV6
|
||||||
unsigned short UpnpGetServerPort6(void)
|
unsigned short UpnpGetServerPort6(void)
|
||||||
{
|
{
|
||||||
if (UpnpSdkInit != 1) {
|
if (UpnpSdkInit != 1)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
return LOCAL_PORT_V6;
|
return LOCAL_PORT_V6;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
char *UpnpGetServerIpAddress(void)
|
char *UpnpGetServerIpAddress(void)
|
||||||
{
|
{
|
||||||
if (UpnpSdkInit != 1) {
|
if (UpnpSdkInit != 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
return gIF_IPV4;
|
return gIF_IPV4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *UpnpGetServerIp6Address(void)
|
char *UpnpGetServerIp6Address(void)
|
||||||
{
|
{
|
||||||
if( UpnpSdkInit != 1 ) {
|
if (UpnpSdkInit != 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
return gIF_IPV6;
|
return gIF_IPV6;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *UpnpGetServerUlaGuaIp6Address(void)
|
char *UpnpGetServerUlaGuaIp6Address(void)
|
||||||
{
|
{
|
||||||
if( UpnpSdkInit != 1 ) {
|
if (UpnpSdkInit != 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
return gIF_IPV6_ULA_GUA;
|
return gIF_IPV6_ULA_GUA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Get a free handle.
|
* \brief Get a free handle.
|
||||||
*
|
*
|
||||||
@ -656,18 +637,14 @@ static int GetFreeHandle()
|
|||||||
/* Handle 0 is not used as NULL translates to 0 when passed as a handle */
|
/* Handle 0 is not used as NULL translates to 0 when passed as a handle */
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
while (i < NUM_HANDLE && HandleTable[i] != NULL) {
|
while (i < NUM_HANDLE && HandleTable[i] != NULL)
|
||||||
++i;
|
++i;
|
||||||
}
|
if (i == NUM_HANDLE)
|
||||||
|
|
||||||
if (i == NUM_HANDLE) {
|
|
||||||
return UPNP_E_OUTOF_HANDLE;
|
return UPNP_E_OUTOF_HANDLE;
|
||||||
} else {
|
else
|
||||||
return i;
|
return i;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Free handle.
|
* \brief Free handle.
|
||||||
*
|
*
|
||||||
@ -681,7 +658,6 @@ static int FreeHandle(
|
|||||||
|
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
"FreeHandle: entering, Handle is %d\n", Upnp_Handle);
|
"FreeHandle: entering, Handle is %d\n", Upnp_Handle);
|
||||||
|
|
||||||
if (Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE) {
|
if (Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE) {
|
||||||
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
|
||||||
"FreeHandle: Handle %d is out of range\n",
|
"FreeHandle: Handle %d is out of range\n",
|
||||||
@ -695,14 +671,12 @@ static int FreeHandle(
|
|||||||
HandleTable[Upnp_Handle] = NULL;
|
HandleTable[Upnp_Handle] = NULL;
|
||||||
ret = UPNP_E_SUCCESS;
|
ret = UPNP_E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
"FreeHandle: exiting, ret = %d.\n", ret);
|
"FreeHandle: exiting, ret = %d.\n", ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
int UpnpRegisterRootDevice(
|
int UpnpRegisterRootDevice(
|
||||||
const char *DescUrl,
|
const char *DescUrl,
|
||||||
@ -1140,179 +1114,159 @@ exit_function:
|
|||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
int UpnpUnRegisterRootDevice(UpnpDevice_Handle Hnd)
|
int UpnpUnRegisterRootDevice(UpnpDevice_Handle Hnd)
|
||||||
{
|
{
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
struct Handle_Info *HInfo = NULL;
|
struct Handle_Info *HInfo = NULL;
|
||||||
|
|
||||||
if (UpnpSdkInit != 1) {
|
if (UpnpSdkInit != 1)
|
||||||
return UPNP_E_FINISH;
|
return UPNP_E_FINISH;
|
||||||
}
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
|
"Inside UpnpUnRegisterRootDevice\n");
|
||||||
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
|
||||||
"Inside UpnpUnRegisterRootDevice\n");
|
|
||||||
#if EXCLUDE_GENA == 0
|
#if EXCLUDE_GENA == 0
|
||||||
if( genaUnregisterDevice( Hnd ) != UPNP_E_SUCCESS )
|
if (genaUnregisterDevice(Hnd) != UPNP_E_SUCCESS)
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HandleLock();
|
HandleLock();
|
||||||
if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) {
|
if (GetHandleInfo(Hnd, &HInfo) == UPNP_E_INVALID_HANDLE) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
|
|
||||||
#if EXCLUDE_SSDP == 0
|
#if EXCLUDE_SSDP == 0
|
||||||
retVal = AdvertiseAndReply(-1, Hnd, 0, (struct sockaddr *)NULL,
|
retVal = AdvertiseAndReply(-1, Hnd, 0, (struct sockaddr *)NULL,
|
||||||
(char *)NULL, (char *)NULL, (char *)NULL, HInfo->MaxAge);
|
(char *)NULL, (char *)NULL, (char *)NULL,
|
||||||
|
HInfo->MaxAge);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
HandleLock();
|
HandleLock();
|
||||||
if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) {
|
if (GetHandleInfo(Hnd, &HInfo) == UPNP_E_INVALID_HANDLE) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
/*info = (struct Handle_Info *) HandleTable[Hnd]; */
|
ixmlNodeList_free(HInfo->DeviceList);
|
||||||
ixmlNodeList_free( HInfo->DeviceList );
|
ixmlNodeList_free(HInfo->ServiceList);
|
||||||
ixmlNodeList_free( HInfo->ServiceList );
|
ixmlDocument_free(HInfo->DescDocument);
|
||||||
ixmlDocument_free( HInfo->DescDocument );
|
|
||||||
|
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
ListDestroy( &HInfo->SsdpSearchList, 0 );
|
ListDestroy(&HInfo->SsdpSearchList, 0);
|
||||||
#endif /* INCLUDE_CLIENT_APIS */
|
#endif /* INCLUDE_CLIENT_APIS */
|
||||||
|
|
||||||
#ifdef INTERNAL_WEB_SERVER
|
#ifdef INTERNAL_WEB_SERVER
|
||||||
if( HInfo->aliasInstalled ) {
|
if (HInfo->aliasInstalled)
|
||||||
web_server_set_alias( NULL, NULL, 0, 0 );
|
web_server_set_alias(NULL, NULL, 0, 0);
|
||||||
}
|
|
||||||
#endif /* INTERNAL_WEB_SERVER */
|
#endif /* INTERNAL_WEB_SERVER */
|
||||||
|
if (HInfo->DeviceAf == AF_INET)
|
||||||
|
UpnpSdkDeviceRegisteredV4 = 0;
|
||||||
|
else if (HInfo->DeviceAf == AF_INET6)
|
||||||
|
UpnpSdkDeviceregisteredV6 = 0;
|
||||||
|
FreeHandle(Hnd);
|
||||||
|
HandleUnlock();
|
||||||
|
|
||||||
if( HInfo->DeviceAf == AF_INET ) {
|
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
|
||||||
UpnpSdkDeviceRegisteredV4 = 0;
|
"Exiting UpnpUnRegisterRootDevice\n");
|
||||||
} else if( HInfo->DeviceAf == AF_INET6 ) {
|
|
||||||
UpnpSdkDeviceregisteredV6 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FreeHandle(Hnd);
|
return retVal;
|
||||||
HandleUnlock();
|
|
||||||
|
|
||||||
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
|
|
||||||
"Exiting UpnpUnRegisterRootDevice\n" );
|
|
||||||
|
|
||||||
return retVal;
|
|
||||||
}
|
}
|
||||||
#endif /* INCLUDE_DEVICE_APIS */
|
#endif /* INCLUDE_DEVICE_APIS */
|
||||||
|
|
||||||
|
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
int UpnpRegisterClient(
|
int UpnpRegisterClient(Upnp_FunPtr Fun, const void *Cookie,
|
||||||
Upnp_FunPtr Fun,
|
|
||||||
const void *Cookie,
|
|
||||||
UpnpClient_Handle *Hnd)
|
UpnpClient_Handle *Hnd)
|
||||||
{
|
{
|
||||||
struct Handle_Info *HInfo;
|
struct Handle_Info *HInfo;
|
||||||
|
|
||||||
if( UpnpSdkInit != 1 ) {
|
if (UpnpSdkInit != 1)
|
||||||
return UPNP_E_FINISH;
|
return UPNP_E_FINISH;
|
||||||
}
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
"Inside UpnpRegisterClient \n");
|
||||||
"Inside UpnpRegisterClient \n" );
|
if (Fun == NULL || Hnd == NULL)
|
||||||
if( Fun == NULL || Hnd == NULL ) {
|
return UPNP_E_INVALID_PARAM;
|
||||||
return UPNP_E_INVALID_PARAM;
|
|
||||||
}
|
|
||||||
|
|
||||||
HandleLock();
|
HandleLock();
|
||||||
|
if (UpnpSdkClientRegistered) {
|
||||||
if( UpnpSdkClientRegistered ) {
|
HandleUnlock();
|
||||||
HandleUnlock();
|
return UPNP_E_ALREADY_REGISTERED;
|
||||||
return UPNP_E_ALREADY_REGISTERED;
|
}
|
||||||
}
|
if ((*Hnd = GetFreeHandle()) == UPNP_E_OUTOF_HANDLE) {
|
||||||
if( ( *Hnd = GetFreeHandle() ) == UPNP_E_OUTOF_HANDLE ) {
|
HandleUnlock();
|
||||||
HandleUnlock();
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
}
|
||||||
}
|
HInfo = (struct Handle_Info *)malloc(sizeof(struct Handle_Info));
|
||||||
HInfo = ( struct Handle_Info * )malloc( sizeof( struct Handle_Info ) );
|
if (HInfo == NULL) {
|
||||||
if( HInfo == NULL ) {
|
HandleUnlock();
|
||||||
HandleUnlock();
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
}
|
||||||
}
|
HInfo->HType = HND_CLIENT;
|
||||||
|
HInfo->Callback = Fun;
|
||||||
HInfo->HType = HND_CLIENT;
|
HInfo->Cookie = (void *)Cookie;
|
||||||
HInfo->Callback = Fun;
|
HInfo->ClientSubList = NULL;
|
||||||
HInfo->Cookie = ( void * )Cookie;
|
ListInit(&HInfo->SsdpSearchList, NULL, NULL);
|
||||||
HInfo->ClientSubList = NULL;
|
|
||||||
ListInit( &HInfo->SsdpSearchList, NULL, NULL );
|
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
HInfo->MaxAge = 0;
|
HInfo->MaxAge = 0;
|
||||||
HInfo->MaxSubscriptions = UPNP_INFINITE;
|
HInfo->MaxSubscriptions = UPNP_INFINITE;
|
||||||
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
|
HInfo->MaxSubscriptionTimeOut = UPNP_INFINITE;
|
||||||
#endif
|
#endif
|
||||||
|
HandleTable[*Hnd] = HInfo;
|
||||||
|
UpnpSdkClientRegistered = 1;
|
||||||
|
HandleUnlock();
|
||||||
|
|
||||||
HandleTable[*Hnd] = HInfo;
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
UpnpSdkClientRegistered = 1;
|
"Exiting UpnpRegisterClient \n");
|
||||||
|
|
||||||
HandleUnlock();
|
return UPNP_E_SUCCESS;
|
||||||
|
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
|
||||||
"Exiting UpnpRegisterClient \n" );
|
|
||||||
|
|
||||||
return UPNP_E_SUCCESS;
|
|
||||||
}
|
}
|
||||||
#endif /* INCLUDE_CLIENT_APIS */
|
#endif /* INCLUDE_CLIENT_APIS */
|
||||||
|
|
||||||
|
|
||||||
#ifdef INCLUDE_CLIENT_APIS
|
#ifdef INCLUDE_CLIENT_APIS
|
||||||
int UpnpUnRegisterClient(UpnpClient_Handle Hnd)
|
int UpnpUnRegisterClient(UpnpClient_Handle Hnd)
|
||||||
{
|
{
|
||||||
struct Handle_Info *HInfo;
|
struct Handle_Info *HInfo;
|
||||||
ListNode *node = NULL;
|
ListNode *node = NULL;
|
||||||
SsdpSearchArg *searchArg = NULL;
|
SsdpSearchArg *searchArg = NULL;
|
||||||
|
|
||||||
if( UpnpSdkInit != 1 ) {
|
if (UpnpSdkInit != 1)
|
||||||
return UPNP_E_FINISH;
|
return UPNP_E_FINISH;
|
||||||
}
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
|
"Inside UpnpUnRegisterClient \n");
|
||||||
|
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
HandleLock();
|
||||||
"Inside UpnpUnRegisterClient \n" );
|
if (!UpnpSdkClientRegistered) {
|
||||||
HandleLock();
|
HandleUnlock();
|
||||||
if( !UpnpSdkClientRegistered ) {
|
return UPNP_E_INVALID_HANDLE;
|
||||||
HandleUnlock();
|
}
|
||||||
return UPNP_E_INVALID_HANDLE;
|
HandleUnlock();
|
||||||
}
|
|
||||||
HandleUnlock();
|
|
||||||
|
|
||||||
#if EXCLUDE_GENA == 0
|
#if EXCLUDE_GENA == 0
|
||||||
if( genaUnregisterClient( Hnd ) != UPNP_E_SUCCESS )
|
if (genaUnregisterClient(Hnd) != UPNP_E_SUCCESS)
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
#endif
|
#endif
|
||||||
HandleLock();
|
HandleLock();
|
||||||
if( GetHandleInfo( Hnd, &HInfo ) == UPNP_E_INVALID_HANDLE ) {
|
if (GetHandleInfo(Hnd, &HInfo) == UPNP_E_INVALID_HANDLE) {
|
||||||
HandleUnlock();
|
HandleUnlock();
|
||||||
return UPNP_E_INVALID_HANDLE;
|
return UPNP_E_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
/* clean up search list */
|
/* clean up search list */
|
||||||
node = ListHead( &HInfo->SsdpSearchList );
|
node = ListHead(&HInfo->SsdpSearchList);
|
||||||
while( node != NULL ) {
|
while (node != NULL) {
|
||||||
searchArg = ( SsdpSearchArg * ) node->item;
|
searchArg = (SsdpSearchArg *) node->item;
|
||||||
if( searchArg ) {
|
if (searchArg) {
|
||||||
free( searchArg->searchTarget );
|
free(searchArg->searchTarget);
|
||||||
free( searchArg );
|
free(searchArg);
|
||||||
}
|
}
|
||||||
ListDelNode( &HInfo->SsdpSearchList, node, 0 );
|
ListDelNode(&HInfo->SsdpSearchList, node, 0);
|
||||||
node = ListHead( &HInfo->SsdpSearchList );
|
node = ListHead(&HInfo->SsdpSearchList);
|
||||||
}
|
}
|
||||||
|
ListDestroy(&HInfo->SsdpSearchList, 0);
|
||||||
|
FreeHandle(Hnd);
|
||||||
|
UpnpSdkClientRegistered = 0;
|
||||||
|
HandleUnlock();
|
||||||
|
|
||||||
ListDestroy( &HInfo->SsdpSearchList, 0 );
|
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
|
||||||
FreeHandle(Hnd);
|
"Exiting UpnpUnRegisterClient \n");
|
||||||
UpnpSdkClientRegistered = 0;
|
|
||||||
HandleUnlock();
|
|
||||||
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
|
|
||||||
"Exiting UpnpUnRegisterClient \n" );
|
|
||||||
return UPNP_E_SUCCESS;
|
|
||||||
|
|
||||||
|
return UPNP_E_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif /* INCLUDE_CLIENT_APIS */
|
#endif /* INCLUDE_CLIENT_APIS */
|
||||||
|
|
||||||
|
|
||||||
#ifdef INCLUDE_DEVICE_APIS
|
#ifdef INCLUDE_DEVICE_APIS
|
||||||
#ifdef INTERNAL_WEB_SERVER
|
#ifdef INTERNAL_WEB_SERVER
|
||||||
/*!
|
/*!
|
||||||
|
@ -303,11 +303,9 @@ static UPNP_INLINE int get_content_type(
|
|||||||
(*content_type) = NULL;
|
(*content_type) = NULL;
|
||||||
/* get ext */
|
/* get ext */
|
||||||
extension = strrchr(filename, '.');
|
extension = strrchr(filename, '.');
|
||||||
if (extension != NULL) {
|
if (extension != NULL)
|
||||||
if (search_extension(extension + 1, &type, &subtype) == 0) {
|
if (search_extension(extension + 1, &type, &subtype) == 0)
|
||||||
ctype_found = TRUE;
|
ctype_found = TRUE;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ctype_found) {
|
if (!ctype_found) {
|
||||||
/* unknown content type */
|
/* unknown content type */
|
||||||
type = gMediaTypes[APPLICATION_INDEX];
|
type = gMediaTypes[APPLICATION_INDEX];
|
||||||
@ -315,16 +313,14 @@ static UPNP_INLINE int get_content_type(
|
|||||||
}
|
}
|
||||||
length = strlen(type) + strlen("/") + strlen(subtype) + 1;
|
length = strlen(type) + strlen("/") + strlen(subtype) + 1;
|
||||||
temp = malloc(length);
|
temp = malloc(length);
|
||||||
if (!temp) {
|
if (!temp)
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
}
|
|
||||||
sprintf(temp, "%s/%s", type, subtype);
|
sprintf(temp, "%s/%s", type, subtype);
|
||||||
(*content_type) = ixmlCloneDOMString(temp);
|
(*content_type) = ixmlCloneDOMString(temp);
|
||||||
free(temp);
|
free(temp);
|
||||||
|
if (!content_type)
|
||||||
if (!content_type) {
|
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,18 +407,14 @@ int web_server_set_alias(const char *alias_name,
|
|||||||
alias.ct = NULL;
|
alias.ct = NULL;
|
||||||
do {
|
do {
|
||||||
/* insert leading /, if missing */
|
/* insert leading /, if missing */
|
||||||
if (*alias_name != '/') {
|
if (*alias_name != '/')
|
||||||
if (membuffer_assign_str(&alias.name, "/") != 0) {
|
if (membuffer_assign_str(&alias.name, "/") != 0)
|
||||||
break; /* error; out of mem */
|
break; /* error; out of mem */
|
||||||
}
|
|
||||||
}
|
|
||||||
ret_code = membuffer_append_str(&alias.name, alias_name);
|
ret_code = membuffer_append_str(&alias.name, alias_name);
|
||||||
if (ret_code != 0) {
|
if (ret_code != 0)
|
||||||
break; /* error */
|
break; /* error */
|
||||||
}
|
if ((alias.ct = (int *)malloc(sizeof(int))) == NULL)
|
||||||
if ((alias.ct = (int *)malloc(sizeof(int))) == NULL) {
|
|
||||||
break; /* error */
|
break; /* error */
|
||||||
}
|
|
||||||
*alias.ct = 1;
|
*alias.ct = 1;
|
||||||
membuffer_attach(&alias.doc, (char *)alias_content,
|
membuffer_attach(&alias.doc, (char *)alias_content,
|
||||||
alias_content_length);
|
alias_content_length);
|
||||||
@ -434,18 +426,19 @@ int web_server_set_alias(const char *alias_name,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} while (FALSE);
|
} while (FALSE);
|
||||||
|
|
||||||
/* error handler */
|
/* error handler */
|
||||||
/* free temp alias */
|
/* free temp alias */
|
||||||
membuffer_destroy(&alias.name);
|
membuffer_destroy(&alias.name);
|
||||||
membuffer_destroy(&alias.doc);
|
membuffer_destroy(&alias.doc);
|
||||||
free(alias.ct);
|
free(alias.ct);
|
||||||
|
|
||||||
return UPNP_E_OUTOF_MEMORY;
|
return UPNP_E_OUTOF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int web_server_init()
|
int web_server_init()
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (bWebServerState == WEB_SERVER_DISABLED) {
|
if (bWebServerState == WEB_SERVER_DISABLED) {
|
||||||
/* decode media list */
|
/* decode media list */
|
||||||
media_list_init();
|
media_list_init();
|
||||||
@ -461,11 +454,10 @@ int web_server_init()
|
|||||||
virtualDirCallback.seek = NULL;
|
virtualDirCallback.seek = NULL;
|
||||||
virtualDirCallback.close = NULL;
|
virtualDirCallback.close = NULL;
|
||||||
|
|
||||||
if (ithread_mutex_init(&gWebMutex, NULL) == -1) {
|
if (ithread_mutex_init(&gWebMutex, NULL) == -1)
|
||||||
ret = UPNP_E_OUTOF_MEMORY;
|
ret = UPNP_E_OUTOF_MEMORY;
|
||||||
} else {
|
else
|
||||||
bWebServerState = WEB_SERVER_ENABLED;
|
bWebServerState = WEB_SERVER_ENABLED;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -510,32 +502,23 @@ static int get_file_info(
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
info->content_type = NULL;
|
info->content_type = NULL;
|
||||||
|
|
||||||
code = stat(filename, &s);
|
code = stat(filename, &s);
|
||||||
if (code == -1) {
|
if (code == -1)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
if (S_ISDIR(s.st_mode))
|
||||||
|
|
||||||
if (S_ISDIR(s.st_mode)) {
|
|
||||||
info->is_directory = TRUE;
|
info->is_directory = TRUE;
|
||||||
} else if (S_ISREG(s.st_mode)) {
|
else if (S_ISREG(s.st_mode))
|
||||||
info->is_directory = FALSE;
|
info->is_directory = FALSE;
|
||||||
} else {
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
/* check readable */
|
/* check readable */
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
info->is_readable = (fp != NULL);
|
info->is_readable = (fp != NULL);
|
||||||
if (fp) {
|
if (fp)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
|
||||||
|
|
||||||
info->file_length = s.st_size;
|
info->file_length = s.st_size;
|
||||||
info->last_modified = s.st_mtime;
|
info->last_modified = s.st_mtime;
|
||||||
|
|
||||||
rc = get_content_type(filename, &info->content_type);
|
rc = get_content_type(filename, &info->content_type);
|
||||||
|
|
||||||
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
|
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
|
||||||
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
|
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
|
||||||
filename, (long long)info->file_length,
|
filename, (long long)info->file_length,
|
||||||
@ -550,15 +533,13 @@ int web_server_set_root_dir(const char *root_dir)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = membuffer_assign_str(&gDocumentRootDir, root_dir);
|
ret = membuffer_assign_str(&gDocumentRootDir, root_dir);
|
||||||
if (ret != 0) {
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
/* remove trailing '/', if any */
|
/* remove trailing '/', if any */
|
||||||
if (gDocumentRootDir.length > 0) {
|
if (gDocumentRootDir.length > 0) {
|
||||||
index = gDocumentRootDir.length - 1; /* last char */
|
index = gDocumentRootDir.length - 1; /* last char */
|
||||||
if (gDocumentRootDir.buf[index] == '/') {
|
if (gDocumentRootDir.buf[index] == '/')
|
||||||
membuffer_delete(&gDocumentRootDir, index, 1);
|
membuffer_delete(&gDocumentRootDir, index, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -662,17 +643,15 @@ static char *StrStr(
|
|||||||
if (!Str1)
|
if (!Str1)
|
||||||
goto error1;
|
goto error1;
|
||||||
Str2 = strdup(s2);
|
Str2 = strdup(s2);
|
||||||
if (!Str2) {
|
if (!Str2)
|
||||||
goto error2;
|
goto error2;
|
||||||
}
|
|
||||||
ToUpperCase(Str1);
|
ToUpperCase(Str1);
|
||||||
ToUpperCase(Str2);
|
ToUpperCase(Str2);
|
||||||
Ptr = strstr(Str1, Str2);
|
Ptr = strstr(Str1, Str2);
|
||||||
if (!Ptr) {
|
if (!Ptr)
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
} else {
|
else
|
||||||
ret = s1 + (Ptr - Str1);
|
ret = s1 + (Ptr - Str1);
|
||||||
}
|
|
||||||
|
|
||||||
free(Str2);
|
free(Str2);
|
||||||
error2:
|
error2:
|
||||||
@ -730,13 +709,11 @@ static int GetNextRange(
|
|||||||
int64_t L = -1;
|
int64_t L = -1;
|
||||||
int Is_Suffix_byte_Range = 1;
|
int Is_Suffix_byte_Range = 1;
|
||||||
|
|
||||||
if (*SrcRangeStr == NULL) {
|
if (*SrcRangeStr == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
Tok = StrTok(SrcRangeStr, ",");
|
Tok = StrTok(SrcRangeStr, ",");
|
||||||
if ((Ptr = strstr(Tok, "-")) == NULL) {
|
if ((Ptr = strstr(Tok, "-")) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
*Ptr = ' ';
|
*Ptr = ' ';
|
||||||
sscanf(Tok, "%" SCNd64 "%" SCNd64, &F, &L);
|
sscanf(Tok, "%" SCNd64 "%" SCNd64, &F, &L);
|
||||||
if (F == -1 || L == -1) {
|
if (F == -1 || L == -1) {
|
||||||
@ -974,8 +951,8 @@ static int CheckOtherHTTPHeaders(
|
|||||||
}
|
}
|
||||||
node = ListNext(&Req->headers, node);
|
node = ListNext(&Req->headers, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(TmpBuf);
|
free(TmpBuf);
|
||||||
|
|
||||||
return RetCode;
|
return RetCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1335,21 +1312,18 @@ static int http_RecvPostMessage(
|
|||||||
|
|
||||||
if (Instr && Instr->IsVirtualFile) {
|
if (Instr && Instr->IsVirtualFile) {
|
||||||
Fp = (virtualDirCallback.open) (filename, UPNP_WRITE);
|
Fp = (virtualDirCallback.open) (filename, UPNP_WRITE);
|
||||||
if (Fp == NULL) {
|
if (Fp == NULL)
|
||||||
return HTTP_INTERNAL_SERVER_ERROR;
|
return HTTP_INTERNAL_SERVER_ERROR;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Fp = fopen(filename, "wb");
|
Fp = fopen(filename, "wb");
|
||||||
if (Fp == NULL) {
|
if (Fp == NULL)
|
||||||
return HTTP_UNAUTHORIZED;
|
return HTTP_UNAUTHORIZED;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
parser->position = POS_ENTITY;
|
parser->position = POS_ENTITY;
|
||||||
do {
|
do {
|
||||||
/* first parse what has already been gotten */
|
/* first parse what has already been gotten */
|
||||||
if (parser->position != POS_COMPLETE) {
|
if (parser->position != POS_COMPLETE)
|
||||||
status = parser_parse_entity(parser);
|
status = parser_parse_entity(parser);
|
||||||
}
|
|
||||||
if (status == PARSE_INCOMPLETE_ENTITY) {
|
if (status == PARSE_INCOMPLETE_ENTITY) {
|
||||||
/* read until close */
|
/* read until close */
|
||||||
ok_on_close = TRUE;
|
ok_on_close = TRUE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user