You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ha...@apache.org on 2004/08/20 11:41:51 UTC
cvs commit: ws-axis/c/src/transport/axis Channel.cpp Channel.hpp HttpTransport.cpp
hawkeye 2004/08/20 02:41:51
Modified: c/src/transport/axis Channel.cpp Channel.hpp
HttpTransport.cpp
Log:
Ability to turn on/off blocking mode, due to problems seen with longer messages
Submitted by: Fred Preston
Reviewed by: Adrian Dick / John Hawkins
Revision Changes Path
1.22 +21 -6 ws-axis/c/src/transport/axis/Channel.cpp
Index: Channel.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/transport/axis/Channel.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Channel.cpp 19 Aug 2004 10:20:02 -0000 1.21
+++ Channel.cpp 20 Aug 2004 09:41:51 -0000 1.22
@@ -282,7 +282,7 @@
}
const Channel &
-Channel::readNonBlocking (std::string & msg)
+Channel::readNonBlocking( std::string & msg, bool bBlockingRequired)
{
msg = "";
if (INVALID_SOCKET == m_Sock)
@@ -301,18 +301,33 @@
int flags = 0;
#if defined WIN32
- // Set the socket I/O mode; iMode = 0 for blocking; iMode != 0 for non-blocking
- int iMode = 1;
- ioctlsocket(m_Sock, FIONBIO, (u_long FAR*) &iMode);
- flags = 0;
+ // Set the socket I/O mode; iMode = 0 for blocking; iMode != 0 for non-blocking
+ int iMode = 1;
+
+ if( bBlockingRequired)
+ {
+ iMode = 0;
+ }
+
+ ioctlsocket( m_Sock, FIONBIO, (u_long FAR*) &iMode);
+
+ flags = 0;
#elif defined AIX
+ flags=MSG_WAITALL;
+ if (!bBlockingRequired)
+ {
flags=MSG_NONBLOCK;
+ }
#elif defined( __OS400__ )
fcntl(m_Sock, F_SETFL, (int)O_NONBLOCK);
flags = 0;
#else
//for linux
- flags = MSG_DONTWAIT;
+ if( !bBlockingRequired)
+ {
+ flags = MSG_DONTWAIT;
+ }
+
//TODO: define flags (or other means) to enable non blocking for other operating systems
#endif
1.8 +1 -1 ws-axis/c/src/transport/axis/Channel.hpp
Index: Channel.hpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/transport/axis/Channel.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Channel.hpp 19 Aug 2004 10:20:02 -0000 1.7
+++ Channel.hpp 20 Aug 2004 09:41:51 -0000 1.8
@@ -124,7 +124,7 @@
virtual const Channel& operator >> (std::string& msg);
/* Read from socket in non bloking more in msg */
- virtual const Channel& readNonBlocking(std::string& msg);
+ virtual const Channel& readNonBlocking(std::string& msg, bool bBlockingRequired);
/* Write a given message (msg) to the end-point using the open socket */
virtual const Channel& operator << (const char* msg);
1.41 +37 -4 ws-axis/c/src/transport/axis/HttpTransport.cpp
Index: HttpTransport.cpp
===================================================================
RCS file: /home/cvs/ws-axis/c/src/transport/axis/HttpTransport.cpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- HttpTransport.cpp 15 Jul 2004 11:27:00 -0000 1.40
+++ HttpTransport.cpp 20 Aug 2004 09:41:51 -0000 1.41
@@ -249,15 +249,48 @@
/* TODO */
// There are other places m_channel is used and needs to have same loop.
+
+//Initially, set the reading of the message to non-blocking.
+ bool bBlockingRequired = false;
+ int iterationCount = 0;
+
do
{
//*m_Channel >> tmpCompletePacket;
//have read from channel once
//hence read the rest in non bloking mode
- m_Channel->readNonBlocking (tmpCompletePacket);
- tmpPacket.append (tmpCompletePacket);
- }
- while (tmpCompletePacket.length ());
+ m_Channel->readNonBlocking( tmpCompletePacket, bBlockingRequired);
+ tmpPacket.append( tmpCompletePacket);
+
+// If a full buffer was read, then we need to implement blocking, so set the
+// 'blocking' flag for the remainder of the message.
+// Else, if a full buffer was not read, then do not set blocking, but wait a
+// short period of time to allow the buffer to fill (if the message has more
+// data).
+ if( !bBlockingRequired)
+ {
+ if( tmpCompletePacket.length() == 1023)
+ {
+ bBlockingRequired = true;
+ }
+ else
+ {
+#ifdef WIN32
+ Sleep( 100); // Sleep for 100ms Allow the message to build
+#else
+ usleep( 100000); // Sleep for 100000us Allow the message to build
+#endif
+ }
+ }
+
+ iterationCount++;
+ }
+// Continue to loop unless the length of the recieved data packet is zero or this
+// is the first time through the loop (if the data packet was zero, it could have
+// been because not enough time had elapsed to allow more data to arrive at the
+// socket. By putting in the sleep whilst not in blocking mode, it is hoped that
+// in this period, more of the message would have had time to arrive).
+ while( tmpCompletePacket.length() || iterationCount == 1);
#ifdef _DEBUG
std::cout << "\n\n\nGot the message:\r\n\r\n" << tmpPacket << "\n\n";