<commit_before>"""
Created on 14 Aug 2020

@author: <NAME> (<EMAIL>)
"""

import time

from scs_host.comms.domain_socket import DomainSocket


# --------------------------------------------------------------------------------------------------------------------
# input reader...

class UDSClient(object):
    """
    classdocs
    """

    EOS = 'UDS-CLIENT-EOS'              # end of session message

    _RECONNECT_WAIT = 10.0              # seconds

    # ----------------------------------------------------------------------------------------------------------------

    def __init__(self, path, logger=None):
        """
        Constructor
        """
        self.__path = path
        self.__uds = DomainSocket(path, logger=logger)

        self.__disconnecting = False


    # ----------------------------------------------------------------------------------------------------------------

    def connect(self):
        self.__disconnecting = False

        self.__uds.connect()


    def disconnect(self):
        self.__disconnecting = True

        self.request(self.EOS)
        self.__uds.close()


    def request(self, message):
        while True:
            try:
                self.__uds.client_send(message)
                return

            except (BrokenPipeError, OSError):
                if self.__disconnecting:
                    return

                time.sleep(self._RECONNECT_WAIT)
<commit_msg>Added UDS client and server<commit_after>"""
Created on 14 Aug 2020

@author: <NAME> (<EMAIL>)
"""

import time

from scs_host.comms.domain_socket import DomainSocket


# --------------------------------------------------------------------------------------------------------------------
# input reader...

class UDSClient(object):
    """
    classdocs
    """

    EOS = 'UDS-CLIENT-EOS'              # end of session message

    _RECONNECT_WAIT = 10.0              # seconds

    # ----------------------------------------------------------------------------------------------------------------

    def __init__(self, path, logger=None):
        """
        Constructor
        """
        self.__path = path
        self.__uds = DomainSocket(path, logger=logger)

        self.__disconnecting = False


    # ----------------------------------------------------------------------------------------------------------------

    def connect(self):
        self.__disconnecting = False

        self.__uds.connect()


    def disconnect(self):
        self.__disconnecting = True

        self.request(self.EOS)
        self.__uds.close()


    def request(self, message):
        while True:
            try:
                self.__uds.client_send(message)
                return

            except (BrokenPipeError, OSError):
                if self.__disconnecting:
                    return                          # don't wait forever if terminating

                time.sleep(self._RECONNECT_WAIT)

{'fraction_non_alphanumeric': 0.3047166610111978, 'fraction_numerical': 0.006107906345436036, 'mean_word_length': 0.9242819843342036, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878693', 'n_tokens_mistral': 709, 'n_tokens_neox': 632, 'n_words': 143}