Commit 18a0a838 authored by smorlat's avatar smorlat
Browse files

merge patch adding a timed version of session_set_select()

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@750 3f6dc0c8-ddfe-455d-9043-3cd528dc4637
parent 9e7480ff
......@@ -130,7 +130,7 @@ void session_set_destroy(SessionSet *set);
int session_set_select(SessionSet *recvs, SessionSet *sends, SessionSet *errors);
int session_set_timedselect(SessionSet *recvs, SessionSet *sends, SessionSet *errors, struct timeval *timeout);
#ifdef __cplusplus
}
......
......@@ -146,3 +146,59 @@ int session_set_select(SessionSet *recvs, SessionSet *sends, SessionSet *errors)
return -1;
}
int session_set_timedselect(SessionSet *recvs, SessionSet *sends, SessionSet *errors, struct timeval *timeout)
{
int ret=0,bits;
int remainingTime; // duration in ms
SessionSet temp;
RtpScheduler *sched;
if (timeout==NULL)
return session_set_select(recvs, sends, errors);
sched=ortp_get_scheduler();
remainingTime = timeout->tv_usec/1000 + timeout->tv_sec*1000;
/*lock the scheduler to not read the masks while they are being modified by the scheduler*/
rtp_scheduler_lock(sched);
do {
/* computes the SessionSet intersection (in the other words mask intersection) between
the mask given by the user and scheduler masks */
if (recvs!=NULL){
session_set_init(&temp);
bits=session_set_and(&sched->r_sessions,sched->all_max,recvs,&temp);
ret+=bits;
/* copy the result set in the given user set (might be empty) */
if (ret>0) session_set_copy(recvs,&temp);
}
if (sends!=NULL){
session_set_init(&temp);
bits=session_set_and(&sched->w_sessions,sched->all_max,sends,&temp);
ret+=bits;
if (ret>0){
/* copy the result set in the given user set (might be empty)*/
session_set_copy(sends,&temp);
}
}
if (errors!=NULL){
session_set_init(&temp);
bits=session_set_and(&sched->e_sessions,sched->all_max,errors,&temp);
ret+=bits;
if (ret>0){
/* copy the result set in the given user set */
session_set_copy(errors,&temp);
}
}
if (ret>0){
/* there are set file descriptors, return immediately */
//printf("There are %i sessions set, returning.\n",ret);
rtp_scheduler_unlock(sched);
return ret;
}
//printf("There are %i sessions set.\n",ret);
/* else we wait until the next loop of the scheduler*/
ortp_cond_wait(&sched->unblock_select_cond,&sched->lock);
remainingTime -= sched->timer_inc;
} while (remainingTime>0);
return -1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment