Changeset 5068 for pjproject


Ignore:
Timestamp:
Apr 13, 2015 12:31:46 PM (9 years ago)
Author:
nanang
Message:

Re #1842: Minor update on python test to reduce possibility of EADDRINUSE error in running pjsua.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/tests/pjsua/inc_cfg.py

    r2237 r5068  
    22import random 
    33import config_site 
     4import socket 
     5import errno 
    46 
    57DEFAULT_ECHO = True 
     
    4749                # Give random sip_port if it's not specified 
    4850                if sip_port==0: 
    49                         self.sip_port = random.randint(DEFAULT_START_SIP_PORT, 65534) 
     51                        # avoid port conflict 
     52                        cnt = 0 
     53                        port = 0 
     54                        while cnt < 10: 
     55                                cnt = cnt + 1 
     56                                port = random.randint(DEFAULT_START_SIP_PORT, 65534) 
     57                                s = socket.socket(socket.AF_INET) 
     58                                try: 
     59                                        s.bind(("0.0.0.0", port)) 
     60                                except socket.error as serr: 
     61                                        s.close() 
     62                                        if serr.errno ==  errno.EADDRINUSE: 
     63                                                continue 
     64                                s.close() 
     65                                break; 
     66                        self.sip_port = port 
    5067                else: 
    5168                        self.sip_port = sip_port 
Note: See TracChangeset for help on using the changeset viewer.