[svn-commits] russell: branch group/issue_11972 r105772 - in /team/group/issue_11972: chann...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Mar 4 16:11:03 CST 2008
Author: russell
Date: Tue Mar 4 16:11:02 2008
New Revision: 105772
URL: http://svn.digium.com/view/asterisk?view=rev&rev=105772
Log:
Move the tcp/tls socket lock into the server_instance struct to ease fixing up
some cleanup issues ...
Modified:
team/group/issue_11972/channels/chan_sip.c
team/group/issue_11972/include/asterisk/tcptls.h
team/group/issue_11972/main/tcptls.c
Modified: team/group/issue_11972/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/issue_11972/channels/chan_sip.c?view=diff&rev=105772&r1=105771&r2=105772
==============================================================================
--- team/group/issue_11972/channels/chan_sip.c (original)
+++ team/group/issue_11972/channels/chan_sip.c Tue Mar 4 16:11:02 2008
@@ -773,7 +773,6 @@
/*!< The SIP socket definition */
struct sip_socket {
- ast_mutex_t *lock;
enum sip_transport type;
int fd;
uint16_t port;
@@ -2170,13 +2169,6 @@
AST_LIST_INSERT_TAIL(&threadl, me, list);
AST_LIST_UNLOCK(&threadl);
- req.socket.lock = ast_calloc(1, sizeof(*req.socket.lock));
-
- if (!req.socket.lock)
- goto cleanup;
-
- ast_mutex_init(req.socket.lock);
-
for (;;) {
memset(req.data, 0, sizeof(req.data));
req.len = 0;
@@ -2198,14 +2190,12 @@
/* Read in headers one line at a time */
while (req.len < 4 || strncmp((char *)&req.data + req.len - 4, "\r\n\r\n", 4)) {
- if (req.socket.lock)
- ast_mutex_lock(req.socket.lock);
+ ast_mutex_lock(&ser->lock);
if (!fgets(buf, sizeof(buf), ser->f)) {
- ast_mutex_unlock(req.socket.lock);
+ ast_mutex_unlock(&ser->lock);
goto cleanup;
}
- if (req.socket.lock)
- ast_mutex_unlock(req.socket.lock);
+ ast_mutex_unlock(&ser->lock);
if (me->stop)
goto cleanup;
strncat(req.data, buf, sizeof(req.data) - req.len);
@@ -2214,12 +2204,12 @@
parse_copy(&reqcpy, &req);
if (sscanf(get_header(&reqcpy, "Content-Length"), "%d", &cl)) {
while (cl > 0) {
- if (req.socket.lock)
- ast_mutex_lock(req.socket.lock);
- if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, ser->f))
+ ast_mutex_lock(&ser->lock);
+ if (!fread(buf, (cl < sizeof(buf)) ? cl : sizeof(buf), 1, ser->f)) {
+ ast_mutex_unlock(&ser->lock);
goto cleanup;
- if (req.socket.lock)
- ast_mutex_unlock(req.socket.lock);
+ }
+ ast_mutex_unlock(&ser->lock);
if (me->stop)
goto cleanup;
cl -= strlen(buf);
@@ -2238,13 +2228,10 @@
ast_free(me);
cleanup2:
fclose(ser->f);
+
+ /* XXX this cleanup needs to happen somewhere else. */
+ ast_mutex_destroy(&ser->lock);
ast_free(ser);
-
- if (req.socket.lock) {
- ast_mutex_destroy(req.socket.lock);
- ast_free(req.socket.lock);
- req.socket.lock = NULL;
- }
return NULL;
}
@@ -2519,8 +2506,8 @@
if (sip_prepare_socket(p) < 0)
return XMIT_ERROR;
- if (p->socket.lock)
- ast_mutex_lock(p->socket.lock);
+ if (p->socket.ser)
+ ast_mutex_lock(&p->socket.ser->lock);
if (p->socket.type & SIP_TRANSPORT_UDP)
res = sendto(p->socket.fd, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in));
@@ -2531,8 +2518,8 @@
ast_debug(1, "No p->socket.ser->f len=%d\n", len);
}
- if (p->socket.lock)
- ast_mutex_unlock(p->socket.lock);
+ if (p->socket.ser)
+ ast_mutex_unlock(&p->socket.ser->lock);
if (res == -1) {
switch (errno) {
@@ -7457,11 +7444,7 @@
build_via(p);
ast_string_field_set(p, callid, callid);
- p->socket.lock = req->socket.lock;
- p->socket.type = req->socket.type;
- p->socket.fd = req->socket.fd;
- p->socket.port = req->socket.port;
- p->socket.ser = req->socket.ser;
+ p->socket = req->socket;
/* Use this temporary pvt structure to send the message */
__transmit_response(p, msg, req, XMIT_UNRELIABLE);
@@ -17963,7 +17946,6 @@
req.socket.type = SIP_TRANSPORT_UDP;
req.socket.ser = NULL;
req.socket.port = bindaddr.sin_port;
- req.socket.lock = NULL;
handle_request_do(&req, &sin);
Modified: team/group/issue_11972/include/asterisk/tcptls.h
URL: http://svn.digium.com/view/asterisk/team/group/issue_11972/include/asterisk/tcptls.h?view=diff&rev=105772&r1=105771&r2=105772
==============================================================================
--- team/group/issue_11972/include/asterisk/tcptls.h (original)
+++ team/group/issue_11972/include/asterisk/tcptls.h Tue Mar 4 16:11:02 2008
@@ -127,6 +127,7 @@
int client;
struct sockaddr_in requestor;
struct server_args *parent;
+ ast_mutex_t lock;
};
/*! \brief
Modified: team/group/issue_11972/main/tcptls.c
URL: http://svn.digium.com/view/asterisk/team/group/issue_11972/main/tcptls.c?view=diff&rev=105772&r1=105771&r2=105772
==============================================================================
--- team/group/issue_11972/main/tcptls.c (original)
+++ team/group/issue_11972/main/tcptls.c Tue Mar 4 16:11:02 2008
@@ -129,6 +129,9 @@
close(fd);
continue;
}
+
+ ast_mutex_init(&ser->lock);
+
flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
ser->fd = fd;
@@ -237,6 +240,8 @@
if (!(ser = ast_calloc(1, sizeof(*ser))))
goto error;
+
+ ast_mutex_init(&ser->lock);
flags = fcntl(desc->accept_fd, F_GETFL);
fcntl(desc->accept_fd, F_SETFL, flags & ~O_NONBLOCK);
More information about the svn-commits
mailing list