You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2007/12/12 12:12:58 UTC
svn commit: r603561 -
/tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
Author: rjung
Date: Wed Dec 12 03:12:55 2007
New Revision: 603561
URL: http://svn.apache.org/viewvc?rev=603561&view=rev
Log:
Cleanup usage of jk_shutdown_socket() and setting
a socket to JK_INVALID_SOCKET.
Always try to do it early, because in most
situations we already know we've got to do it.
Exception: jk_is_input_event() because it could
be used in the future for a non-fatal wait.
Modified:
tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c?rev=603561&r1=603560&r2=603561&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c Wed Dec 12 03:12:55 2007
@@ -888,6 +888,10 @@
return JK_FATAL_ERROR;
}
+ /* This is the only place in this function where we use the socket. */
+ /* If sendfull gets an error, it implicitely closes the socket. */
+ /* So any socket error inside ajp_connection_tcp_send_message */
+ /* results in a socket close and invalidated endpoint connection. */
if ((rc = jk_tcp_socket_sendfull(ae->sd, msg->buf,
msg->len, l)) > 0) {
ae->endpoint.wr += (jk_uint64_t)rc;
@@ -898,6 +902,7 @@
ae->last_errno = errno;
jk_log(l, JK_LOG_ERROR,
"sendfull returned %d (errno=%d)", rc, ae->last_errno);
+ ae->sd = JK_INVALID_SOCKET;
JK_TRACE_EXIT(l);
return JK_FALSE;
@@ -918,6 +923,8 @@
JK_TRACE_ENTER(l);
+ /* If recvfull gets an error, it implicitely closes the socket. */
+ /* We will invalidate the endpoint connection. */
rc = jk_tcp_socket_recvfull(ae->sd, head, AJP_HEADER_LEN, l);
if (rc < 0) {
@@ -926,7 +933,6 @@
jk_log(l, JK_LOG_INFO,
"(%s) Tomcat has forced a connection close for socket %d",
ae->worker->name, ae->sd);
- JK_TRACE_EXIT(l);
}
else {
jk_log(l, JK_LOG_ERROR,
@@ -934,8 +940,9 @@
"network problems or tomcat (%s) is down (errno=%d)",
ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
ae->last_errno);
- JK_TRACE_EXIT(l);
}
+ ae->sd = JK_INVALID_SOCKET;
+ JK_TRACE_EXIT(l);
return JK_FALSE;
}
ae->last_errno = 0;
@@ -956,6 +963,10 @@
header, jk_dump_hinfo(&ae->worker->worker_inet_addr,
buf));
}
+ /* We've got a protocol error. */
+ /* We can't trust this connection any more. */
+ jk_shutdown_socket(ae->sd, l);
+ ae->sd = JK_INVALID_SOCKET;
JK_TRACE_EXIT(l);
return JK_FALSE;
}
@@ -974,6 +985,10 @@
header, jk_dump_hinfo(&ae->worker->worker_inet_addr,
buf));
}
+ /* We've got a protocol error. */
+ /* We can't trust this connection any more. */
+ jk_shutdown_socket(ae->sd, l);
+ ae->sd = JK_INVALID_SOCKET;
JK_TRACE_EXIT(l);
return JK_FALSE;
}
@@ -987,6 +1002,10 @@
"wrong message size %d %d from %s",
msglen, msg->maxlen,
jk_dump_hinfo(&ae->worker->worker_inet_addr, buf));
+ /* We've got a protocol error. */
+ /* We can't trust this connection any more. */
+ jk_shutdown_socket(ae->sd, l);
+ ae->sd = JK_INVALID_SOCKET;
JK_TRACE_EXIT(l);
return JK_FALSE;
}
@@ -994,6 +1013,8 @@
msg->len = msglen;
msg->pos = 0;
+ /* If recvfull gets an error, it implicitely closes the socket. */
+ /* We will invalidate the endpoint connection. */
rc = jk_tcp_socket_recvfull(ae->sd, msg->buf, msglen, l);
if (rc < 0) {
ae->last_errno = errno;
@@ -1003,8 +1024,6 @@
"tomcat (%s) has forced a connection close for socket %d",
ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
ae->sd);
- JK_TRACE_EXIT(l);
- return JK_FALSE;
}
else {
jk_log(l, JK_LOG_ERROR,
@@ -1012,9 +1031,10 @@
"network problems or tomcat (%s) is down (errno=%d)",
ae->worker->name, jk_dump_hinfo(&ae->worker->worker_inet_addr, buf),
ae->last_errno);
- JK_TRACE_EXIT(l);
- return JK_FALSE;
}
+ ae->sd = JK_INVALID_SOCKET;
+ JK_TRACE_EXIT(l);
+ return JK_FALSE;
}
ae->last_errno = 0;
ae->endpoint.rd += (jk_uint64_t)rc;
@@ -1178,7 +1198,6 @@
jk_log(l, JK_LOG_DEBUG,
"(%s) socket %d is not connected any more (errno=%d)",
ae->worker->name, ae->sd, errno);
- jk_shutdown_socket(ae->sd, l);
ae->sd = JK_INVALID_SOCKET;
err = 1;
}
@@ -1273,9 +1292,6 @@
* have is probably unrecoverable
*/
if (ajp_connection_tcp_send_message(ae, op->request, l) != JK_TRUE) {
- /* Close the socket if unable to send request */
- jk_shutdown_socket(ae->sd, l);
- ae->sd = JK_INVALID_SOCKET;
jk_log(l, JK_LOG_INFO,
"(%s) error sending request on a fresh connection (errno=%d)",
ae->worker->name, ae->last_errno);
@@ -1318,9 +1334,6 @@
postlen = op->post->len;
if (postlen > AJP_HEADER_LEN) {
if (ajp_connection_tcp_send_message(ae, op->post, l) != JK_TRUE) {
- /* Close the socket if unable to send request */
- jk_shutdown_socket(ae->sd, l);
- ae->sd = JK_INVALID_SOCKET;
jk_log(l, JK_LOG_ERROR, "(%s) failed resending request body (%d)",
ae->worker->name, postlen);
JK_TRACE_EXIT(l);
@@ -1338,9 +1351,6 @@
if (postlen > AJP_HEADER_LEN) {
if (ajp_connection_tcp_send_message(ae, s->reco_buf, l) != JK_TRUE) {
- /* Close the socket if unable to send request */
- jk_shutdown_socket(ae->sd, l);
- ae->sd = JK_INVALID_SOCKET;
jk_log(l, JK_LOG_ERROR,
"(%s) failed resending request body (lb mode) (%d)",
ae->worker->name, postlen);
@@ -1388,9 +1398,6 @@
s->content_read = (jk_uint64_t)len;
if (ajp_connection_tcp_send_message(ae, op->post, l) != JK_TRUE) {
- /* Close the socket if unable to send request */
- jk_shutdown_socket(ae->sd, l);
- ae->sd = JK_INVALID_SOCKET;
jk_log(l, JK_LOG_ERROR, "(%s) error sending request body",
ae->worker->name);
JK_TRACE_EXIT(l);
@@ -1661,7 +1668,7 @@
}
}
- if (!ajp_connection_tcp_get_message(p, op->reply, l)) {
+ if (ajp_connection_tcp_get_message(p, op->reply, l) != JK_TRUE) {
/* we just can't recover, unset recover flag */
if (headeratclient == JK_FALSE) {
jk_log(l, JK_LOG_ERROR,
@@ -1778,8 +1785,6 @@
jk_log(l, JK_LOG_ERROR,
"(%s) Tomcat is down or network problems",
p->worker->name);
- jk_shutdown_socket(p->sd, l);
- p->sd = JK_INVALID_SOCKET;
JK_TRACE_EXIT(l);
return JK_FALSE;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org