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:35:06 UTC
svn commit: r603573 - in /tomcat/connectors/trunk/jk/native/common:
jk_ajp_common.c jk_connect.c
Author: rjung
Date: Wed Dec 12 03:35:05 2007
New Revision: 603573
URL: http://svn.apache.org/viewvc?rev=603573&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
tomcat/connectors/trunk/jk/native/common/jk_connect.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=603573&r1=603572&r2=603573&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:35:05 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;
}
Modified: tomcat/connectors/trunk/jk/native/common/jk_connect.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_connect.c?rev=603573&r1=603572&r2=603573&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_connect.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_connect.c Wed Dec 12 03:35:05 2007
@@ -692,6 +692,7 @@
* negative pseudo errno: send returns SOCKET_ERROR (WIN32)
* JK_SOCKET_EOF: no bytes could be sent
* >0: success, total size send
+ * @remark Always closes socket in case of error
* @bug this fails on Unixes if len is too big for the underlying
* protocol
*/
@@ -715,10 +716,12 @@
} while (JK_IS_SOCKET_ERROR(wr) && (errno == EINTR || errno == EAGAIN));
if (JK_IS_SOCKET_ERROR(wr)) {
+ jk_shutdown_socket(sd, l);
JK_TRACE_EXIT(l);
return (errno > 0) ? -errno : errno;
}
else if (wr == 0) {
+ jk_shutdown_socket(sd, l);
JK_TRACE_EXIT(l);
return JK_SOCKET_EOF;
}
@@ -738,6 +741,7 @@
* negative pseudo errno: recv returns SOCKET_ERROR (WIN32)
* JK_SOCKET_EOF: no bytes could be read
* >0: success, total size received
+ * @remark Always closes socket in case of error
*/
int jk_tcp_socket_recvfull(jk_sock_t sd, unsigned char *b, int len, jk_logger_t *l)
{
@@ -759,10 +763,12 @@
} while (JK_IS_SOCKET_ERROR(rd) && (errno == EINTR || errno == EAGAIN));
if (JK_IS_SOCKET_ERROR(rd)) {
+ jk_shutdown_socket(sd, l);
JK_TRACE_EXIT(l);
return (errno > 0) ? -errno : errno;
}
else if (rd == 0) {
+ jk_shutdown_socket(sd, l);
JK_TRACE_EXIT(l);
return JK_SOCKET_EOF;
}
@@ -796,6 +802,8 @@
* @return JK_FALSE: Timeout expired without something to read
* JK_FALSE: Error during waiting
* JK_TRUE: success
+ * @remark Does not close socket in case of error
+ * to allow for iterative waiting
*/
int jk_is_input_event(jk_sock_t sd, int timeout, jk_logger_t *l)
{
@@ -843,6 +851,7 @@
* @param l logger
* @return JK_FALSE: failure
* JK_TRUE: success
+ * @remark Always closes socket in case of error
*/
int jk_is_socket_connected(jk_sock_t sd, jk_logger_t *l)
{
@@ -888,11 +897,12 @@
rc = ioctl(sd, FIONREAD, (void*)&nr);
#endif
if (rc == 0 && nr != 0) {
- return JK_TRUE;
JK_TRACE_EXIT(l);
+ return JK_TRUE;
}
JK_GET_SOCKET_ERRNO();
}
+ jk_shutdown_socket(sd, l);
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