Re: svn commit: r893452 - /tomcat/jk/trunk/native/common/jk_connect.c

2010-01-07 Thread Tim Whittington
This appears to have broken my build on Windows (VC 2005). 

SHUT_RD is SD_RECEIVE on Windows? 

cheers 
tim 
- Original Message - 
From: mt...@apache.org 
To: dev@tomcat.apache.org 
Sent: Wednesday, 23 December, 2009 11:01:47 PM GMT +12:00 New Zealand 
Subject: svn commit: r893452 - /tomcat/jk/trunk/native/common/jk_connect.c 

Author: mturk 
Date: Wed Dec 23 10:01:47 2009 
New Revision: 893452 

URL: http://svn.apache.org/viewvc?rev=893452view=rev 
Log: 
Use smarter shutdown. In case we don't receive the full buffer break from loop. 
This shoud lower down the shutdown to 2 sec max 

Modified: 
tomcat/jk/trunk/native/common/jk_connect.c 

Modified: tomcat/jk/trunk/native/common/jk_connect.c 
URL: 
http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_connect.c?rev=893452r1=893451r2=893452view=diff
 
== 
--- tomcat/jk/trunk/native/common/jk_connect.c (original) 
+++ tomcat/jk/trunk/native/common/jk_connect.c Wed Dec 23 10:01:47 2009 
@@ -694,8 +694,8 @@ 
char dummy[512]; 
int rc = 0; 
int rd = 0; 
+ int rp = 0; 
int save_errno; 
- fd_set rs; 
struct timeval tv; 
time_t start = time(NULL); 

@@ -722,10 +722,16 @@ 
return rc; 
} 

- /* Set up to wait for readable data on socket... */ 
- FD_ZERO(rs); 
- 
do { 
+#ifdef HAVE_POLL 
+ struct pollfd fds; 
+ 
+ fds.fd = sd; 
+ fds.events = POLLIN; 
+#else 
+ fd_set rs; 
+ 
+ FD_ZERO(rs); 
/* Read all data from the peer until we reach end-of-file 
* (FIN from peer) or we've exceeded our overall timeout. If the 
* backend does not send us bytes within 2 seconds 
@@ -735,8 +741,14 @@ 
FD_SET(sd, rs); 
tv.tv_sec = SECONDS_TO_LINGER; 
tv.tv_usec = 0; 
- 
- if (select((int)sd + 1, rs, NULL, NULL, tv)  0) { 
+#endif 
+ rp = 0; 
+#ifdef HAVE_POLL 
+ if (poll(fds, 1, SECONDS_TO_LINGER * 1000)  0) 
+#else 
+ if (select((int)sd + 1, rs, NULL, NULL, tv)  0) 
+#endif 
+ { 
do { 
#if defined(WIN32) || (defined(NETWARE)  defined(__NOVELL_LIBC__)) 
rc = recv(sd, dummy[0], sizeof(dummy), 0); 
@@ -746,7 +758,7 @@ 
rc = read(sd, dummy[0], sizeof(dummy)); 
#endif 
if (rc  0) 
- rd += rc; 
+ rp += rc; 
} while (JK_IS_SOCKET_ERROR(rc)  (errno == EINTR || errno == EAGAIN)); 

if (rc = 0) 
@@ -754,7 +766,27 @@ 
} 
else 
break; 
- 
+ rd += rp; 
+ if (rp  sizeof(dummy)) { 
+ /* We have readed less then size of buffer 
+ * It's a good chance there will be no more data 
+ * to read. 
+ */ 
+ if ((rc = sononblock(sd))) { 
+ rc = jk_close_socket(sd, l); 
+ if (JK_IS_DEBUG_LEVEL(l)) 
+ jk_log(l, JK_LOG_DEBUG, 
+ error setting socket %d to nonblocking, sd); 
+ errno = save_errno; 
+ JK_TRACE_EXIT(l); 
+ return rc; 
+ } 
+ if (JK_IS_DEBUG_LEVEL(l)) 
+ jk_log(l, JK_LOG_DEBUG, 
+ shutting down the read side of socket %d, sd); 
+ shutdown(sd, SHUT_RD); 
+ break; 
+ } 
} while (difftime(time(NULL), start)  MAX_SECS_TO_LINGER); 

rc = jk_close_socket(sd, l); 



- 
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org 
For additional commands, e-mail: dev-h...@tomcat.apache.org 



Re: svn commit: r893452 - /tomcat/jk/trunk/native/common/jk_connect.c

2010-01-07 Thread Tim Whittington
This should fix it 

Index: jk_connect.c 
=== 
--- jk_connect.c (revision 896809) 
+++ jk_connect.c (working copy) 
@@ -678,6 +678,13 @@ 
#define SHUT_WR 0x01 
#endif 
#endif 
+#ifndef SHUT_RD 
+#ifdef SD_RECEIVE 
+#define SHUT_RD SD_RECEIVE 
+#else 
+#define SHUT_RD 0x00 
+#endif 
+#endif 

/** Drain and close the socket 
* @param sd socket to close 


- Original Message - 
From: Tim Whittington t...@orionhealth.com 
To: Tomcat Developers List dev@tomcat.apache.org 
Sent: Thursday, 7 January, 2010 10:41:02 PM GMT +12:00 New Zealand 
Subject: Re: svn commit: r893452 - /tomcat/jk/trunk/native/common/jk_connect.c 


This appears to have broken my build on Windows (VC 2005). 

SHUT_RD is SD_RECEIVE on Windows? 

cheers 
tim 
- Original Message - 
From: mt...@apache.org 
To: dev@tomcat.apache.org 
Sent: Wednesday, 23 December, 2009 11:01:47 PM GMT +12:00 New Zealand 
Subject: svn commit: r893452 - /tomcat/jk/trunk/native/common/jk_connect.c 

Author: mturk 
Date: Wed Dec 23 10:01:47 2009 
New Revision: 893452 

URL: http://svn.apache.org/viewvc?rev=893452view=rev 
Log: 
Use smarter shutdown. In case we don't receive the full buffer break from loop. 
This shoud lower down the shutdown to 2 sec max 

Modified: 
tomcat/jk/trunk/native/common/jk_connect.c 

Modified: tomcat/jk/trunk/native/common/jk_connect.c 
URL: 
http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_connect.c?rev=893452r1=893451r2=893452view=diff
 
== 
--- tomcat/jk/trunk/native/common/jk_connect.c (original) 
+++ tomcat/jk/trunk/native/common/jk_connect.c Wed Dec 23 10:01:47 2009 
@@ -694,8 +694,8 @@ 
char dummy[512]; 
int rc = 0; 
int rd = 0; 
+ int rp = 0; 
int save_errno; 
- fd_set rs; 
struct timeval tv; 
time_t start = time(NULL); 

@@ -722,10 +722,16 @@ 
return rc; 
} 

- /* Set up to wait for readable data on socket... */ 
- FD_ZERO(rs); 
- 
do { 
+#ifdef HAVE_POLL 
+ struct pollfd fds; 
+ 
+ fds.fd = sd; 
+ fds.events = POLLIN; 
+#else 
+ fd_set rs; 
+ 
+ FD_ZERO(rs); 
/* Read all data from the peer until we reach end-of-file 
* (FIN from peer) or we've exceeded our overall timeout. If the 
* backend does not send us bytes within 2 seconds 
@@ -735,8 +741,14 @@ 
FD_SET(sd, rs); 
tv.tv_sec = SECONDS_TO_LINGER; 
tv.tv_usec = 0; 
- 
- if (select((int)sd + 1, rs, NULL, NULL, tv)  0) { 
+#endif 
+ rp = 0; 
+#ifdef HAVE_POLL 
+ if (poll(fds, 1, SECONDS_TO_LINGER * 1000)  0) 
+#else 
+ if (select((int)sd + 1, rs, NULL, NULL, tv)  0) 
+#endif 
+ { 
do { 
#if defined(WIN32) || (defined(NETWARE)  defined(__NOVELL_LIBC__)) 
rc = recv(sd, dummy[0], sizeof(dummy), 0); 
@@ -746,7 +758,7 @@ 
rc = read(sd, dummy[0], sizeof(dummy)); 
#endif 
if (rc  0) 
- rd += rc; 
+ rp += rc; 
} while (JK_IS_SOCKET_ERROR(rc)  (errno == EINTR || errno == EAGAIN)); 

if (rc = 0) 
@@ -754,7 +766,27 @@ 
} 
else 
break; 
- 
+ rd += rp; 
+ if (rp  sizeof(dummy)) { 
+ /* We have readed less then size of buffer 
+ * It's a good chance there will be no more data 
+ * to read. 
+ */ 
+ if ((rc = sononblock(sd))) { 
+ rc = jk_close_socket(sd, l); 
+ if (JK_IS_DEBUG_LEVEL(l)) 
+ jk_log(l, JK_LOG_DEBUG, 
+ error setting socket %d to nonblocking, sd); 
+ errno = save_errno; 
+ JK_TRACE_EXIT(l); 
+ return rc; 
+ } 
+ if (JK_IS_DEBUG_LEVEL(l)) 
+ jk_log(l, JK_LOG_DEBUG, 
+ shutting down the read side of socket %d, sd); 
+ shutdown(sd, SHUT_RD); 
+ break; 
+ } 
} while (difftime(time(NULL), start)  MAX_SECS_TO_LINGER); 

rc = jk_close_socket(sd, l); 



- 
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org 
For additional commands, e-mail: dev-h...@tomcat.apache.org 



svn commit: r893452 - /tomcat/jk/trunk/native/common/jk_connect.c

2009-12-23 Thread mturk
Author: mturk
Date: Wed Dec 23 10:01:47 2009
New Revision: 893452

URL: http://svn.apache.org/viewvc?rev=893452view=rev
Log:
Use smarter shutdown. In case we don't receive the full buffer break from loop. 
This shoud lower down the shutdown to 2 sec max

Modified:
tomcat/jk/trunk/native/common/jk_connect.c

Modified: tomcat/jk/trunk/native/common/jk_connect.c
URL: 
http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_connect.c?rev=893452r1=893451r2=893452view=diff
==
--- tomcat/jk/trunk/native/common/jk_connect.c (original)
+++ tomcat/jk/trunk/native/common/jk_connect.c Wed Dec 23 10:01:47 2009
@@ -694,8 +694,8 @@
 char dummy[512];
 int rc = 0;
 int rd = 0;
+int rp = 0;
 int save_errno;
-fd_set rs;
 struct timeval tv;
 time_t start = time(NULL);
 
@@ -722,10 +722,16 @@
 return rc;
 }
 
-/* Set up to wait for readable data on socket... */
-FD_ZERO(rs);
-
 do {
+#ifdef HAVE_POLL
+struct pollfd fds;
+
+fds.fd = sd;
+fds.events = POLLIN;
+#else
+fd_set rs;
+
+FD_ZERO(rs);
 /* Read all data from the peer until we reach end-of-file
  * (FIN from peer) or we've exceeded our overall timeout. If the
  * backend does not send us bytes within 2 seconds
@@ -735,8 +741,14 @@
 FD_SET(sd, rs);
 tv.tv_sec  = SECONDS_TO_LINGER;
 tv.tv_usec = 0;
-
-if (select((int)sd + 1, rs, NULL, NULL, tv)  0) {
+#endif
+rp = 0;
+#ifdef HAVE_POLL
+if (poll(fds, 1, SECONDS_TO_LINGER * 1000)  0)
+#else
+if (select((int)sd + 1, rs, NULL, NULL, tv)  0)
+#endif
+{
 do {
 #if defined(WIN32) || (defined(NETWARE)  defined(__NOVELL_LIBC__))
 rc = recv(sd, dummy[0], sizeof(dummy), 0);
@@ -746,7 +758,7 @@
 rc = read(sd, dummy[0], sizeof(dummy));
 #endif
 if (rc  0)
-rd += rc;
+rp += rc;
 } while (JK_IS_SOCKET_ERROR(rc)  (errno == EINTR || errno == 
EAGAIN));
 
 if (rc = 0)
@@ -754,7 +766,27 @@
 }
 else
 break;
-
+rd += rp;
+if (rp  sizeof(dummy)) {
+/* We have readed less then size of buffer
+ * It's a good chance there will be no more data
+ * to read.
+ */
+if ((rc = sononblock(sd))) {
+rc = jk_close_socket(sd, l);
+if (JK_IS_DEBUG_LEVEL(l))
+jk_log(l, JK_LOG_DEBUG,
+   error setting  socket %d to nonblocking, sd);
+errno = save_errno;
+JK_TRACE_EXIT(l);
+return rc;
+}
+if (JK_IS_DEBUG_LEVEL(l))
+jk_log(l, JK_LOG_DEBUG,
+   shutting down the read side of socket %d, sd);
+shutdown(sd, SHUT_RD);
+break;
+}
 } while (difftime(time(NULL), start)  MAX_SECS_TO_LINGER);
 
 rc = jk_close_socket(sd, l);



-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org