Append() public method

Either HTTPRequest contains the header AND some data, or it contains part or all of the header. Accumulate pieces of the header in case it spans multiple reads.
public Append ( string HTTPRequest ) : STATUS
HTTPRequest string
return STATUS
        private bool readRequest()
        {
            int left    = header.ContentLength - header.DataString.Length;
            int dataLen = 0;

            if (left > 0)
            {
                byte[] data = new byte[left];
                try
                {
                    dataLen = stream.Read(data, 0, left);
                    if (dataLen == 0)
                    {
                        XmlRpcUtil.error("XmlRpcServerConnection::readRequest: Stream was closed");
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    XmlRpcUtil.error("XmlRpcServerConnection::readRequest: error while reading the rest of data ({0}).", ex.Message);
                    return(false);
                }
                header.Append(Encoding.ASCII.GetString(data, 0, dataLen));
            }
            // Otherwise, parse and dispatch the request
            XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.DEBUG, "XmlRpcServerConnection::readRequest read {0} bytes.", dataLen);

            if (!header.ContentComplete)
            {
                return(false);
            }
            _connectionState = ServerConnectionState.WRITE_RESPONSE;

            return(true); // Continue monitoring this source
        }
Example #2
0
        private bool readResponse()
        {
            int left    = header.ContentLength - header.DataString.Length;
            int dataLen = 0;

            if (left > 0)
            {
                byte[] data = new byte[left];
                try
                {
                    var stream = socket.GetStream();
                    dataLen = stream.Read(data, 0, left);
                    if (dataLen == 0)
                    {
                        XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.ERROR, "XmlRpcClient::readResponse: Stream was closed");
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    XmlRpcUtil.error("XmlRpcClient::readResponse: error while reading the rest of data ({0}).", ex.Message);
                    return(false);
                }
                header.Append(Encoding.ASCII.GetString(data, 0, dataLen));
            }
            if (header.ContentComplete)
            {
                // Otherwise, parse and dispatch the request
                XmlRpcUtil.log(XmlRpcUtil.XMLRPC_LOG_LEVEL.INFO, "XmlRpcClient::readResponse read {0} bytes.", _request.Length);

                _connectionState = ConnectionState.IDLE;

                return(false); // no need to continue monitoring because we're done reading the response
            }

            // Continue monitoring this source
            return(true);
        }