Skip to content

[ENH] Use socket keepalived instead of original #4

@leungigi

Description

@leungigi

Scenarios:

Sometimes, enduser need to run longterm traffic (more than 2 hours), and ixia client socket will idle after send out traffic, some network gateway or linux server maybe close ixia client socket due to no any response during that time, then script will crash due to socket closed.

Solution:

Use "setsockopt" to set socket as keepalived, detail pls refer Python socket.TCP_KEEPINTVL() Examples

Code change as below:

def connect(self):
        log.debug('Opening connection to %s:%d', self.host, self.port)
        fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        fd.connect((self.host, self.port))
        self.fd = fd
        self.set_socket_keepalive 
        self.call('package req IxTclHal')

def set_socket_keepalive(self):
        self.fd.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
        self.fd.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 1)
        self.fd.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 60)
        self.fd.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions