diff --git a/example_config/super_mode/n1_test_fd_mode.py b/example_config/super_mode/n1_test_fd_mode.py index 440eabd..2555640 100644 --- a/example_config/super_mode/n1_test_fd_mode.py +++ b/example_config/super_mode/n1_test_fd_mode.py @@ -19,22 +19,19 @@ def signal_handler(sig, frame): def read_loop(fd): print("Main Start read fd:",fd) - with os.fdopen(fd, 'rb') as fdfile: - while True: - text = fdfile.read() - if len(text) == 0: - print("EOF!!!!!!!!!!!!!!!!!!!!!!!!") - break - print("Main: RECEIVED:",text) + while True: + text = os.read(fd, 65535) + if len(text) == 0: + print("EOF!!!!!!!!!!!!!!!!!!!!!!!!") + break + print("Main: RECEIVED:",text) def write_loop(fd): - with os.fdopen(fd, 'wb') as fdfile: - while True: - print("Main Write fd:",fd) - text = b'\xff\xff\xff\xff\xff\xff\xaa\xaa\xaa\xaa\xaa\xaa' + b'm'*88 - fdfile.write(text) - fdfile.flush() - time.sleep(1) + while True: + print("Main Write fd:",fd) + text = b'\xff\xff\xff\xff\xff\xff\xaa\xaa\xaa\xaa\xaa\xaa' + b'm'*88 + os.write(fd,text) + time.sleep(1) tr = threading.Thread(target = read_loop, args=(pr,)) tr.start() @@ -48,8 +45,8 @@ os.environ["EG_FD_TX"] = str(ew) print(str(er), str(ew)) #p = subprocess.Popen('./etherguard-go -config example_config/super_mode/n1_fd.yaml -mode edge'.split(" "),pass_fds=[er,ew]) -#p = subprocess.Popen('python3 example_config/super_mode/n1_test_fd_mode2.py'.split(" "),pass_fds=[er,ew]) -p = subprocess.Popen('example_config/super_mode/n1_test_fd_mode2'.split(" "),pass_fds=[er,ew]) +p = subprocess.Popen('python3 example_config/super_mode/n1_test_fd_mode2.py'.split(" "),pass_fds=[er,ew]) +#p = subprocess.Popen('example_config/super_mode/n1_test_fd_mode2'.split(" "),pass_fds=[er,ew]) os.close(er) os.close(ew) diff --git a/example_config/super_mode/n1_test_fd_mode2.py b/example_config/super_mode/n1_test_fd_mode2.py index 69ea5bd..b214d13 100644 --- a/example_config/super_mode/n1_test_fd_mode2.py +++ b/example_config/super_mode/n1_test_fd_mode2.py @@ -19,22 +19,19 @@ def signal_handler(sig, frame): def read_loop(fd): print("Sub: Start read fd:",fd) - with os.fdopen(fd, 'rb') as fdfile: - while True: - text = fdfile.read() - if len(text) == 0: - print("EOF!!!!!!!!!!!!!!!!!!!!!!!!") - break - print("Sub RECEIVED:",text) + while True: + text = os.read(fd, 65535) + if len(text) == 0: + print("EOF!!!!!!!!!!!!!!!!!!!!!!!!") + break + print("Sub RECEIVED:",text) def write_loop(fd): - with os.fdopen(fd, 'wb') as fdfile: - while True: - print("Sub: Write fd:",fd) - text = b'\xff\xff\xff\xff\xff\xff\xaa\xaa\xaa\xaa\xaa\xaa' + b's'*88 - fdfile.write(text) - fdfile.flush() - time.sleep(1) + while True: + print("Sub: Write fd:",fd) + text = b'\xff\xff\xff\xff\xff\xff\xaa\xaa\xaa\xaa\xaa\xaa' + b's'*88 + os.write(fd,text) + time.sleep(1) tr = threading.Thread(target = read_loop, args=(er,)) tr.start() diff --git a/tap/tap_sock.go b/tap/tap_sock.go index d0c34ab..99b0bc1 100644 --- a/tap/tap_sock.go +++ b/tap/tap_sock.go @@ -53,6 +53,9 @@ func CreateSockTAP(iconfig config.InterfaceConf, protocol string, NodeID config. if iconfig.SendAddr != "" { client, err := net.Dial(protocol, iconfig.SendAddr) if err != nil { + if tap.server != nil { + (*tap.server).Close() + } return nil, err } tap.connTx = &client