[svn-commits] dvossel: branch dvossel/sip_nonblocking_tcp_client r220670 - in /team/dvossel...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Sep 28 09:55:45 CDT 2009
Author: dvossel
Date: Mon Sep 28 09:55:41 2009
New Revision: 220670
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=220670
Log:
moved tcp connect() to tcp helper thread
Modified:
team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c
team/dvossel/sip_nonblocking_tcp_client/main/tcptls.c
Modified: team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c?view=diff&rev=220670&r1=220669&r2=220670
==============================================================================
--- team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c (original)
+++ team/dvossel/sip_nonblocking_tcp_client/channels/chan_sip.c Mon Sep 28 09:55:41 2009
@@ -2113,7 +2113,7 @@
/*! \brief Definition of a thread that handles a socket */
struct sip_threadinfo {
int stop;
- int alert_pipe[2];
+ int alert_pipe[2]; /*! Used to alert tcptls thread when packet is ready to write */
pthread_t threadid;
struct ast_tcptls_session_instance *tcptls_session;
enum sip_transport type; /*!< We keep a copy of the type here so we can display it in the connection list */
@@ -2922,6 +2922,7 @@
ast_free((char *) args->name);
}
}
+
static void sip_threadinfo_destructor(void *obj)
{
struct sip_threadinfo *th = obj;
@@ -2943,6 +2944,7 @@
}
}
+/*! brief\ creates a sip_threadinfo object and links it into the threadl table. */
static struct sip_threadinfo *sip_threadinfo_create(struct ast_tcptls_session_instance *tcptls_session, int transport)
{
struct sip_threadinfo *th;
@@ -2965,6 +2967,7 @@
return th;
}
+/*! brief\ used to indicate to a tcptls thread that data is ready to be written */
static int sip_tcptls_write(struct ast_tcptls_session_instance *tcptls_session, const void *buf, size_t len)
{
int res = len;
@@ -3007,6 +3010,7 @@
ast_log(LOG_ERROR, "write() to alert pipe failed: %s\n", strerror(errno));
AST_LIST_REMOVE_HEAD(&th->packet_q, entry);
ao2_t_ref(packet, -1, "could not write to alert pipe, remove packet");
+ packet = NULL;
res = XMIT_ERROR;
}
@@ -22871,8 +22875,7 @@
* 1. We need to check to see if a connectin thread exists
* for this address, if so use that.
* 2. If a thread does not exist for this address, but the tcptls_session
- * exists on the socket, the connect must have been closed. Don't attempt
- * to reopen, dialog is dead.
+ * exists on the socket, the connection was closed.
* 3. If no tcptls_session thread exists for the address, and no tcptls_session
* already exists on the socket, create a new one and launch a new thread.
*/
@@ -22889,11 +22892,7 @@
return s->fd;
/* 2. Thread not found, if tcptls_session already exists, it once had a thread and is now terminated */
} else if (s->tcptls_session) {
- /* at this point, if the tcptls_session exists, but no thread was found
- * for it, that means a thread existed but has been closed. Currently no
- * attempt is made to reconnect, XXX whether reconnection is necessary
- * needs to be investigated */
- return -1;
+ return s->fd; /* XXX whether reconnection is ever necessary here needs to be investigated further */
}
/* 3. Create a new TCP/TLS client connection */
@@ -22907,8 +22906,7 @@
ca->remote_address = *(sip_real_dst(p));
/* if type is TLS, we need to create a tls cfg for this session arg */
if (s->type == SIP_TRANSPORT_TLS) {
- ca->tls_cfg = ast_calloc(1, sizeof(*ca->tls_cfg));
- if (!ca->tls_cfg) {
+ if (!(ca->tls_cfg = ast_calloc(1, sizeof(*ca->tls_cfg)))) {
goto create_tcptls_session_fail;
}
memcpy(ca->tls_cfg, &default_tls_cfg, sizeof(*ca->tls_cfg));
@@ -22933,7 +22931,7 @@
goto create_tcptls_session_fail;
}
- /* Give the new thread a reference */
+ /* Give the new thread a reference to the tcptls_session */
ao2_ref(s->tcptls_session, +1);
if (ast_pthread_create_background(&ca->master, NULL, sip_tcp_worker_fn, s->tcptls_session)) {
Modified: team/dvossel/sip_nonblocking_tcp_client/main/tcptls.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/sip_nonblocking_tcp_client/main/tcptls.c?view=diff&rev=220670&r1=220669&r2=220670
==============================================================================
--- team/dvossel/sip_nonblocking_tcp_client/main/tcptls.c (original)
+++ team/dvossel/sip_nonblocking_tcp_client/main/tcptls.c Mon Sep 28 09:55:41 2009
@@ -363,12 +363,43 @@
*/
struct ast_tcptls_session_instance *ast_tcptls_client_start(struct ast_tcptls_session_instance *tcptls_session)
{
+ struct ast_tcptls_session_args *desc;
+ int flags;
+
+ if (!(desc = tcptls_session->parent)) {
+ goto client_start_error;
+ }
+
+ if (connect(desc->accept_fd, (const struct sockaddr *) &desc->remote_address, sizeof(desc->remote_address))) {
+ ast_log(LOG_ERROR, "Unable to connect %s to %s:%d: %s\n",
+ desc->name,
+ ast_inet_ntoa(desc->remote_address.sin_addr), ntohs(desc->remote_address.sin_port),
+ strerror(errno));
+ goto client_start_error;
+ }
+
+ flags = fcntl(desc->accept_fd, F_GETFL);
+ fcntl(desc->accept_fd, F_SETFL, flags & ~O_NONBLOCK);
+
+ if (desc->tls_cfg) {
+ desc->tls_cfg->enabled = 1;
+ __ssl_setup(desc->tls_cfg, 1);
+ }
+
return handle_tcptls_connection(tcptls_session);
+
+client_start_error:
+ close(desc->accept_fd);
+ desc->accept_fd = -1;
+ if (tcptls_session) {
+ ao2_ref(tcptls_session, -1);
+ }
+ return NULL;
+
}
struct ast_tcptls_session_instance *ast_tcptls_client_create(struct ast_tcptls_session_args *desc)
{
- int flags;
int x = 1;
struct ast_tcptls_session_instance *tcptls_session = NULL;
@@ -403,33 +434,15 @@
}
}
- if (connect(desc->accept_fd, (const struct sockaddr *) &desc->remote_address, sizeof(desc->remote_address))) {
- ast_log(LOG_ERROR, "Unable to connect %s to %s:%d: %s\n",
- desc->name,
- ast_inet_ntoa(desc->remote_address.sin_addr), ntohs(desc->remote_address.sin_port),
- strerror(errno));
- goto error;
- }
-
if (!(tcptls_session = ao2_alloc(sizeof(*tcptls_session), session_instance_destructor)))
goto error;
ast_mutex_init(&tcptls_session->lock);
-
- flags = fcntl(desc->accept_fd, F_GETFL);
- fcntl(desc->accept_fd, F_SETFL, flags & ~O_NONBLOCK);
-
+ tcptls_session->client = 1;
tcptls_session->fd = desc->accept_fd;
tcptls_session->parent = desc;
tcptls_session->parent->worker_fn = NULL;
memcpy(&tcptls_session->remote_address, &desc->remote_address, sizeof(tcptls_session->remote_address));
-
- tcptls_session->client = 1;
-
- if (desc->tls_cfg) {
- desc->tls_cfg->enabled = 1;
- __ssl_setup(desc->tls_cfg, 1);
- }
return tcptls_session;
More information about the svn-commits
mailing list