You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2004/11/24 09:08:51 UTC

cvs commit: ws-axis/c/src/transport/axis2/ipv6 IPV6Channel.cpp IPV6Channel.hpp

samisa      2004/11/24 00:08:50

  Modified:    c/src/transport/axis2 Axis2Transport.cpp Channel.cpp
                        Channel.h Makefile
               c/src/transport/axis2/ipv6 IPV6Channel.cpp IPV6Channel.hpp
  Log:
  Fixed Jira AXISCPP-269. There was a bug in chunk reading. Cleaned up the code a bit as well.
  
  Revision  Changes    Path
  1.23      +14 -4     ws-axis/c/src/transport/axis2/Axis2Transport.cpp
  
  Index: Axis2Transport.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/transport/axis2/Axis2Transport.cpp,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Axis2Transport.cpp	16 Nov 2004 02:39:15 -0000	1.22
  +++ Axis2Transport.cpp	24 Nov 2004 08:08:50 -0000	1.23
  @@ -359,8 +359,8 @@
           try
           {
               *m_pChannel >> m_strReceived;
  -
  -            if (!m_bReadPastHTTPHeaders)
  +             
  +             if (!m_bReadPastHTTPHeaders)
               {
                   do
                   {
  @@ -464,7 +464,9 @@
                   {
                       do
                       {
  -                        *m_pChannel >> m_strReceived;
  +                        std::string strTempReceived = "";
  +                        *m_pChannel >> strTempReceived; // Assume non blocking here
  +                        m_strReceived += strTempReceived;
                           endOfChunkData = m_strReceived.find ("\r\n");
                       }
                       while (endOfChunkData == std::string::npos);
  @@ -524,6 +526,14 @@
   
                       // Start looking for the next chunk
                       unsigned int endOfChunkData = m_strReceived.find ("\r\n");	// Skip end of previous chunk
  +                    while (endOfChunkData == std::string::npos)
  +                    {
  +                        std::string strTempRecv = "";
  +                        *m_pChannel >> strTempRecv;
  +                        m_strReceived += strTempRecv;
  +                        endOfChunkData = m_strReceived.find ("\r\n");
  +                    }
  +
                       m_strReceived = m_strReceived.substr (endOfChunkData + 2);
   
                       endOfChunkData = m_strReceived.find ("\r\n");	// Locate start of next chunk
  @@ -622,7 +632,7 @@
           int iToCopy = (*pSize < m_iBytesLeft) ? *pSize : m_iBytesLeft;
   
           strncpy (pcBuffer, m_pcReceived, iToCopy);
  -
  +        pcBuffer[iToCopy] = '\0';
           m_iBytesLeft -= iToCopy;
           m_pcReceived += iToCopy;
           *pSize = iToCopy;
  
  
  
  1.8       +0 -2      ws-axis/c/src/transport/axis2/Channel.cpp
  
  Index: Channel.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/transport/axis2/Channel.cpp,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Channel.cpp	16 Nov 2004 02:39:15 -0000	1.7
  +++ Channel.cpp	24 Nov 2004 08:08:50 -0000	1.8
  @@ -403,7 +403,6 @@
       }
   
       int nByteRecv = 0;
  -    const int BUF_SIZE = 1024;
       char buf[BUF_SIZE];
   	int	iBufSize = BUF_SIZE;
   
  @@ -521,7 +520,6 @@
       }
   
       int nByteRecv = 0;
  -    const int BUF_SIZE = 1024;
       char buf[BUF_SIZE];
   
       //Samisa: I want to set the socket to non blocking mode here
  
  
  
  1.4       +1 -1      ws-axis/c/src/transport/axis2/Channel.h
  
  Index: Channel.h
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/transport/axis2/Channel.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Channel.h	3 Nov 2004 13:23:14 -0000	1.3
  +++ Channel.h	24 Nov 2004 08:08:50 -0000	1.4
  @@ -55,7 +55,7 @@
   
   const unsigned int INVALID_SOCKET =  0;
   const int           SOCKET_ERROR   = -1;
  -
  +const int BUF_SIZE = 1024 * 8;
   /* ther OS specific stuff goes here */
   
   
  
  
  
  1.9       +2 -2      ws-axis/c/src/transport/axis2/Makefile
  
  Index: Makefile
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/transport/axis2/Makefile,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Makefile	23 Nov 2004 04:00:17 -0000	1.8
  +++ Makefile	24 Nov 2004 08:08:50 -0000	1.9
  @@ -88,8 +88,8 @@
   AMTAR = ${SHELL} /home/samisa/autoCVS/cvsAutoBuild/missing --run tar
   APACHE2BUILD = apache2
   APACHE2INC = -I/usr/local/apache2/include
  -APACHEBUILD = apache
  -APACHEINC = -I/usr/local/apache/include
  +APACHEBUILD = 
  +APACHEINC = 
   AR = ar
   AUTOCONF = ${SHELL} /home/samisa/autoCVS/cvsAutoBuild/missing --run autoconf
   AUTOHEADER = ${SHELL} /home/samisa/autoCVS/cvsAutoBuild/missing --run autoheader
  
  
  
  1.4       +0 -408    ws-axis/c/src/transport/axis2/ipv6/IPV6Channel.cpp
  
  Index: IPV6Channel.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/transport/axis2/ipv6/IPV6Channel.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IPV6Channel.cpp	18 Nov 2004 10:45:34 -0000	1.3
  +++ IPV6Channel.cpp	24 Nov 2004 08:08:50 -0000	1.4
  @@ -237,411 +237,3 @@
       return true;
   }
   
  -/**
  - * IPV6Channel::operator << (Msg) Write (send) a message to the remote server.
  - * Sending a message will block the application (i.e. synchronous communication).
  - * NB: We may need to do this asynchronizely; preferably either non-blocking
  - * send or pthread.
  - *
  - * @param    const char * Msg NULL terminated character string containing the
  - * message to be written to the open channel.
  - * NB: For GSKit SSL, the message has been encoded and may contain embedded
  - * null characters.  To overcome this problem, the m_iMsgLength value must be
  - * set to the message length before calling this method.  If m_iMsgLength is
  - * not 0, this method will assume the the value is the message length.
  - * m_iMsgLength is set to 0 in the constructor, so unless it is intentionally
  - * changed, it will not have any effect on this method.
  - *
  - * @return const IPV6Channel & is the addaddrInfos of the IPV6Channel object (the 'this'
  - * pointer).
  - */
  -/*const Channel &IPV6Channel::operator << (const char *msg)
  -{
  -#ifdef FJPDebug
  -    printf( ">IPV6Channel::operator << msg=%s, ", msg);
  -#endif
  -
  -    // Check that the Tx/Rx sockets are valid (this will have been done if the
  -    // application has called the open method first.
  -    if( INVALID_SOCKET == m_Sock)
  -    {
  -        // Error - Writing cannot be done without having a open socket to
  -        //         remote end.  Throw an exception.
  -#ifdef FJPDebug
  -        printf( "<IPV6Channel::operator << exception\n");
  -#endif
  -
  -        throw AxisTransportException( SERVER_TRANSPORT_INVALID_SOCKET);
  -    }
  -
  -    int size = strlen( msg);
  -    int nByteSent;
  -
  -    if( m_iMsgLength)
  -    {
  -        size = m_iMsgLength;
  -    }
  -
  -#ifdef FJPDebug
  -    printf( "size=%d, m_Sock=%d\n", size, m_Sock);
  -
  -    hexOutput( (char *) msg, size);
  -#endif
  -
  -    if( (nByteSent = send( m_Sock, msg, size, MSG_DONTROUTE)) == SOCKET_ERROR)
  -    {
  -        // Output streaming error while writing data.  Close the channel and
  -        // throw an exception.
  -        closeChannel();
  -
  -#ifdef FJPDebug
  -        printf( "<IPV6Channel::operator << exception\n");
  -#endif
  -
  -        throw AxisTransportException(SERVER_TRANSPORT_OUTPUT_STREAMING_ERROR);
  -    }
  -
  -#ifdef FJPDebug
  -    printf( "<IPV6Channel::operator <<\n");
  -#endif
  -
  -    return *this;
  -}
  -*/
  -
  -/**
  - * IPV6Channel::operator >> (Msg) Read (receive) a message from the remote server;
  - * Reading may be done in 'chunks'.
  - *
  - * @param    std::string & Msg is string that will receive the message.
  - * NB: For GSKit SSL, the message has been encoded and may contain embedded
  - * null characters.  To overcome this problem, the m_iMsgLength value must be
  - * set to the negative of the message length before calling this method.  If
  - * m_iMsgLength is not negative, this method will assume the BUF_SIZE value is
  - * the message length.  m_iMsgLength is set to 0 in the constructor, so unless
  - * it is intentionally changed, it will not have any effect on this method.
  - *
  - * @return const IPV6Channel & is the addaddrInfos of the IPV6Channel object (the 'this'
  - * pointer).
  - */
  -/*const Channel &IPV6Channel::operator >> (std::string & msg)
  -{
  -#ifdef FJPDebug
  -    printf( ">IPV6Channel::operator >> m_Sock=%d\n", m_Sock);
  -#endif
  -
  -    msg = "";
  -
  -    if (INVALID_SOCKET == m_Sock)
  -    {
  -        // Error - Reading cannot be done without having a open socket Input
  -        //         streaming error on undefined channel; please open the
  -        //		   channel first
  -
  -#ifdef FJPDebug
  -        printf( "<IPV6Channel::operator >> exception=SERVER_TRANSPORT_INVALID_SOCKET\n");
  -#endif
  -
  -        throw AxisTransportException( SERVER_TRANSPORT_INVALID_SOCKET);
  -    }
  -
  -    int nByteRecv = 0;
  -    const int BUF_SIZE = 1024;
  -    char buf[BUF_SIZE];
  -    int	iBufSize = BUF_SIZE;
  -
  -    if( m_iMsgLength < 0)
  -    {
  -        iBufSize = -m_iMsgLength;
  -    }
  -    else
  -    {
  -        iBufSize--;
  -    }
  -
  -    //assume timeout not set; set default tatus to OK
  -    int iTimeoutStatus = 1;
  -
  -    //check if timeout set
  -    if(m_lTimeoutSeconds)
  -    {
  -        iTimeoutStatus = applyTimeout();
  -    }
  -
  -    // Handle timeout outcome
  -    if( iTimeoutStatus < 0)
  -    {
  -        // Error
  -
  -#ifdef FJPDebug
  -        printf( "<IPV6Channel::operator >> exception=SERVER_TRANSPORT_TIMEOUT_EXCEPTION\n");
  -#endif
  -
  -        // Select SOCKET_ERROR. IPV6Channel error while waiting for timeout
  -        throw AxisTransportException( SERVER_TRANSPORT_TIMEOUT_EXCEPTION,
  -                                      "IPV6Channel error while waiting for timeout");
  -    }
  -
  -    if( iTimeoutStatus == 0)
  -    {
  -        // Timeout expired - select timeout expired.
  -        // IPV6Channel error connection timeout before receving
  -
  -#ifdef FJPDebug
  -        printf( "<IPV6Channel::operator >> exception=SERVER_TRANSPORT_TIMEOUT_EXPIRED\n");
  -#endif
  -
  -        throw AxisTransportException( SERVER_TRANSPORT_TIMEOUT_EXPIRED,
  -                                      "IPV6Channel error: connection timed out before receving");
  -    }
  -
  -    // Either timeout was not set or data available before timeout; so read
  -
  -    if( (nByteRecv = recv( m_Sock, (char *) &buf, iBufSize, 0)) == SOCKET_ERROR)
  -    {
  -        // Recv SOCKET_ERROR, IPV6Channel error while getting data
  -
  -
  -#ifdef FJPDebug
  -        printf( "<IPV6Channel::operator >> exception=SERVER_TRANSPORT_INPUT_STREAMING_ERROR\n");
  -#endif
  -
  -        throw AxisTransportException( SERVER_TRANSPORT_INPUT_STREAMING_ERROR,
  -                                      "IPV6Channel error while getting data");
  -    }
  -
  -    if( nByteRecv)
  -    {
  -        // printf("nByteRecv:%d\n", nByteRecv); 
  -        buf[nByteRecv] = '\0';
  -        // got a part of the message, so add " \        "to form 
  -        msg = buf;
  -
  -        if( m_iMsgLength < 0)
  -        {
  -            m_iMsgLength = nByteRecv;
  -
  -            m_sMsg = new char[nByteRecv];
  -
  -            memcpy( m_sMsg, buf, nByteRecv);
  -        }
  -    }
  -    else
  -    {
  -        if( m_iMsgLength < 0)
  -        {
  -            m_iMsgLength = nByteRecv;
  -        }
  -        ;//printf ("execution break\n");
  -    }
  -
  -#ifdef FJPDebug
  -    hexOutput( m_sMsg, m_iMsgLength);
  -
  -    printf( "m_iMsgLength=%d\n", m_iMsgLength);
  -    printf( "<IPV6Channel::operator >> msg = %s\n", buf);
  -#endif
  -
  -    return *this;
  -}
  -*/
  -
  -/**
  - * IPV6Channel::readNonBlocking( Msg, BlockingRequired) Read (receive) a message
  - * from the remote server; Reading may be done in 'chunks'?
  - *
  - * @param string & Msg
  - * @param bool BlockingRequired
  - *
  - * @return const IPV6Channel & is the addaddrInfos of the IPV6Channel object (the 'this'
  - * pointer).
  - */
  -/*const Channel &IPV6Channel::readNonBlocking( std::string & msg, bool bBlockingRequired)
  -{
  -    msg = "";
  -    if (INVALID_SOCKET == m_Sock)
  -    {
  -        //Reading cannot be done without having a open socket
  -        throw AxisTransportException(SERVER_TRANSPORT_INVALID_SOCKET);
  -    }
  -
  -    int nByteRecv = 0;
  -    const int BUF_SIZE = 1024;
  -    char buf[BUF_SIZE];
  -
  -    //Samisa: I want to set the socket to non blocking mode here
  -    //for Winsock there is no simple way to do this but for Linux I used MSG_DONTWAIT
  -    //there is no MSG_DONTWAIT defined in Winsock
  -    int flags = 0;
  -
  -#if defined WIN32
  -    // 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
  -    if( !bBlockingRequired)
  -    {
  -        flags = MSG_DONTWAIT;
  -    }
  -
  -    //TODO: define flags (or other means) to enable non blocking for other operating systems
  -#endif
  -
  -    if ((nByteRecv = recv (m_Sock, (char *) &buf, BUF_SIZE - 1, flags))
  -            == SOCKET_ERROR)
  -    {
  -        //IPV6Channel error while getting data
  -        return *this;
  -    }
  -    if (nByteRecv)
  -    {
  -        buf[nByteRecv] = '\0';
  -        msg = buf;
  -    }
  -    else
  -        Error( "IPV6Channel::readNonBlocking: execution break");
  -
  -    return *this;
  -}
  -*/
  -
  -/**
  - * IPV6Channel::closeChannel() Close and clean-up using specific Operating System
  - * calls.
  - */
  -void IPV6Channel::closeChannel ()
  -{
  -#ifdef FJPDebug
  -    printf( ">IPV6Channel::closeChannel()\n");
  -#endif
  -
  -    if( INVALID_SOCKET == m_Sock) // Check if socket already closed : AXISCPP-185
  -    {
  -#ifdef FJPDebug
  -        printf( "<IPV6Channel::closeChannel()\n");
  -#endif
  -
  -        return;
  -    }
  -
  -#ifdef WIN32
  -    closesocket( m_Sock);
  -
  -    // Check for any possible error conditions from WSACleanup() and report
  -    // them before exiting, as this information might indicate a network
  -    // layer problem in the system.
  -
  -    WSACleanup ();
  -#else
  -
  -    ::close( m_Sock);
  -
  -#endif
  -
  -    m_Sock = INVALID_SOCKET; // fix for AXISCPP-185
  -
  -#ifdef FJPDebug
  -    printf( "<IPV6Channel::closeChannel()\n");
  -#endif
  -}
  -
  -/**
  - * IPV6Channel::applyTimeout()
  - *
  - * @return int 
  - */
  -int IPV6Channel::applyTimeout()
  -{
  -#ifdef FJPDebug
  -    printf( ">IPV6Channel::applyTimeout()\n");
  -#endif
  -
  -    fd_set set
  -        ;
  -    struct timeval timeout;
  -
  -    // Initialize the file descriptor set.
  -    FD_ZERO( &set
  -           );
  -    FD_SET( m_Sock, &set
  -          );
  -
  -    /* Initialize the timeout data structure. */
  -    timeout.tv_sec = m_lTimeoutSeconds;
  -    timeout.tv_usec = 0;
  -
  -    /* select returns 0 if timeout, 1 if input available, -1 if error. */
  -#ifdef FJPDebug
  -    printf( "<IPV6Channel::applyTimeout()\n");
  -#endif
  -
  -    return select( FD_SETSIZE, &set
  -                   , NULL, NULL, &timeout);
  -}
  -
  -/**
  - * Debug routine will be deleted.
  - */
  -void IPV6Channel::hexOutput( char * psData, int iDataLength)
  -{
  -    unsigned char *	pByte = (unsigned char *) psData;
  -    string			sLineHex;
  -    string			sLineChar;
  -    int				iByteCount = 0;
  -    int				iLineCount;
  -    char			szDigits[6];
  -
  -    while( iByteCount < iDataLength)
  -    {
  -        sprintf( szDigits, "%04X ", iByteCount);
  -
  -        sLineHex = szDigits;
  -        sLineChar = "";
  -        iLineCount = 0;
  -
  -        while( iLineCount < 16 && iByteCount < iDataLength)
  -        {
  -            unsigned char Char = *pByte;
  -
  -            if( Char < 32 || Char > 127)
  -            {
  -                Char = '.';
  -            }
  -
  -            sprintf( szDigits, "%02X ", *pByte);
  -
  -            sLineHex = sLineHex + szDigits;
  -            sLineChar = sLineChar + (char) Char;
  -
  -            pByte++;
  -            iByteCount++;
  -            iLineCount++;
  -        }
  -
  -        for( int iCount = iLineCount; iCount < 16; iCount++)
  -        {
  -            sLineHex = sLineHex + "   ";
  -        }
  -
  -        printf( "%s %s\n", sLineHex.c_str(), sLineChar.c_str());
  -    }
  -}
  
  
  
  1.3       +1 -19     ws-axis/c/src/transport/axis2/ipv6/IPV6Channel.hpp
  
  Index: IPV6Channel.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/transport/axis2/ipv6/IPV6Channel.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IPV6Channel.hpp	22 Nov 2004 07:32:47 -0000	1.2
  +++ IPV6Channel.hpp	24 Nov 2004 08:08:50 -0000	1.3
  @@ -39,30 +39,12 @@
       /* Open a socket to a given remote node/server address with remote port */
       virtual bool  open() throw (AxisTransportException&);
   
  -    /* Read from a open socket and store read message in msg */
  -    //virtual const Channel& operator >> (std::string& msg);
  -    
  -    /* Read from socket in non bloking more in 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);
  -    
  -
   protected:
       /* OS specific initilization */
       virtual bool init();
   
   
  -    /* Close & clean-up the open socket/system resources */
  -    virtual void closeChannel();
  -
  -	virtual void hexOutput( char * psData, int iDataLength);
  -
  -  /**
  -    * @return 0 if timeout, 1 if input available, -1 if error.
  -    */
  -    int applyTimeout();
  +   
   };
   
   #endif