[asterisk-commits] wedhorn: branch wedhorn/skinny-session r390433 - /team/wedhorn/skinny-session...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 4 15:03:35 CDT 2013
Author: wedhorn
Date: Tue Jun 4 15:03:33 2013
New Revision: 390433
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390433
Log:
skinny: move auth timeout to sched arrangement
Modified:
team/wedhorn/skinny-session/channels/chan_skinny.c
Modified: team/wedhorn/skinny-session/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/wedhorn/skinny-session/channels/chan_skinny.c?view=diff&rev=390433&r1=390432&r2=390433
==============================================================================
--- team/wedhorn/skinny-session/channels/chan_skinny.c (original)
+++ team/wedhorn/skinny-session/channels/chan_skinny.c Tue Jun 4 15:03:33 2013
@@ -1613,6 +1613,9 @@
char outbuf[SKINNY_MAX_PACKET];
struct skinny_device *device;
AST_LIST_ENTRY(skinnysession) list;
+ int destroy;
+ int auth_timeout_sched;
+ int keepalive_timeout_sched;
};
static struct ast_channel *skinny_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *dest, int *cause);
@@ -2234,6 +2237,11 @@
struct sockaddr_in sin;
socklen_t slen;
int instance;
+
+ if (s->auth_timeout_sched && ast_sched_del(sched, s->auth_timeout_sched)) {
+ return 0;
+ }
+ s->auth_timeout_sched = 0;
AST_LIST_LOCK(&devices);
AST_LIST_TRAVERSE(&devices, d, list){
@@ -7367,6 +7375,21 @@
AST_LIST_UNLOCK(&sessions);
}
+static void end_session(struct skinnysession *s)
+{
+ s->destroy = 1;
+ pthread_kill(s->t, SIGURG);
+}
+
+static int skinny_noauth_cb(const void *data)
+{
+ struct skinnysession *s = (struct skinnysession *)data;
+ ast_log(LOG_WARNING, "Skinny Client failed to authenticate in %d seconds (SCHED %d)\n", auth_timeout, s->auth_timeout_sched);
+ s->auth_timeout_sched = 0;
+ end_session(s);
+ return 0;
+}
+
static void *skinny_session(void *data)
{
int res;
@@ -7375,7 +7398,6 @@
int dlen = 0;
int timeout;
- time_t now;
struct pollfd fds[1];
int lockstate = 0;
@@ -7385,25 +7407,12 @@
}
ast_verb(3, "Starting Skinny session from %s\n", ast_inet_ntoa(s->sin.sin_addr));
+ s->destroy = 0;
+ s->auth_timeout_sched = ast_sched_add(sched, auth_timeout*1000, skinny_noauth_cb, s);
for (;;) {
- if (!s->device) {
- if(time(&now) == -1) {
- ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
- ast_verb(3, "Ending Skinny session from %s (bad input)\n", ast_inet_ntoa(s->sin.sin_addr));
- break;
- }
- timeout = (auth_timeout - (now - s->start)) * 1000;
- if (timeout < 0) {
- /* we have timed out */
- ast_log(LOG_WARNING, "Skinny Client failed to authenticate in %d seconds\n", auth_timeout);
- ast_verb(3, "Ending Skinny session from %s (bad input)\n", ast_inet_ntoa(s->sin.sin_addr));
- break;
- }
- } else {
- timeout = keep_alive * 1100;
- }
+ timeout = keep_alive * 1100;
fds[0].fd = s->fd;
fds[0].events = POLLIN;
@@ -7411,6 +7420,9 @@
res = ast_poll(fds, 1, timeout); /* If nothing has happen, client is dead */
/* we add 10% to the keep_alive to deal */
/* with network delays, etc */
+ if (s->destroy) {
+ break;
+ }
if (res < 0) {
if (errno != EINTR) {
ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno));
More information about the asterisk-commits
mailing list