def parse_connection_setup(self):
        """Internal function used to parse connection setup response.
        """

        # Only the ConnectionSetupRequest has been sent so far
        r = self.sent_requests[0]

        while 1:
            # print 'data_send:', repr(self.data_send)
            # print 'data_recv:', repr(self.data_recv)

            if r._data:
                alen = r._data['additional_length'] * 4

                # The full response haven't arrived yet
                if len(self.data_recv) < alen:
                    return 0

                # Connection failed or further authentication is needed.
                # Set reason to the reason string
                if r._data['status'] != 1:
                    r._data['reason'] = self.data_recv[:r._data['reason_length']]

                # Else connection succeeded, parse the reply
                else:
                    x, d = r._success_reply.parse_binary(self.data_recv[:alen],
                                                         self, rawdict = 1)
                    r._data.update(x)

                del self.sent_requests[0]

                self.data_recv = self.data_recv[alen:]

                return 1

            else:
                # The base reply is 8 bytes long
                if len(self.data_recv) < 8:
                    return 0

                r._data, d = r._reply.parse_binary(self.data_recv[:8],
                                                   self, rawdict = 1)
                self.data_recv = self.data_recv[8:]
Internal function used to parse connection setup response.