use pipe to abort select on Linux as well as macOS

This commit is contained in:
Benjamin Sergeant 2019-03-15 17:46:40 -07:00
parent 4c78b94cd8
commit 68e397ab34
3 changed files with 39 additions and 9 deletions

View File

@ -33,6 +33,7 @@ set( IXWEBSOCKET_SOURCES
ixwebsocket/IXHttpClient.cpp
ixwebsocket/IXUrlParser.cpp
ixwebsocket/IXSelectInterrupt.cpp
ixwebsocket/IXSelectInterruptPipe.cpp
ixwebsocket/IXSelectInterruptFactory.cpp
)
@ -59,14 +60,13 @@ set( IXWEBSOCKET_HEADERS
ixwebsocket/IXHttpClient.h
ixwebsocket/IXUrlParser.h
ixwebsocket/IXSelectInterrupt.h
ixwebsocket/IXSelectInterruptPipe.h
ixwebsocket/IXSelectInterruptFactory.h
)
# Platform specific code
if (APPLE)
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/apple/IXSetThreadName_apple.cpp)
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSelectInterruptPipe.cpp)
list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSelectInterruptPipe.h)
elseif (WIN32)
list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/windows/IXSetThreadName_windows.cpp)
else()

View File

@ -6,9 +6,7 @@
#include "IXSelectInterruptFactory.h"
#if defined(__linux__)
# include <ixwebsocket/IXSelectInterruptEventFd.h>
#elif defined(__APPLE__)
#if defined(__linux__) || defined(__APPLE__)
# include <ixwebsocket/IXSelectInterruptPipe.h>
#else
# include <ixwebsocket/IXSelectInterrupt.h>
@ -18,9 +16,7 @@ namespace ix
{
std::shared_ptr<SelectInterrupt> createSelectInterrupt()
{
#if defined(__linux__)
return std::make_shared<SelectInterruptEventFd>();
#elif defined(__APPLE__)
#if defined(__linux__) || defined(__APPLE__)
return std::make_shared<SelectInterruptPipe>();
#else
return std::make_shared<SelectInterrupt>();

View File

@ -2,6 +2,39 @@ import os
import platform
import shutil
import subprocess
import threading
class Command(object):
"""Run system commands with timeout
From http://www.bo-yang.net/2016/12/01/python-run-command-with-timeout
Python3 might have a builtin way to do that.
"""
def __init__(self, cmd):
self.cmd = cmd
self.process = None
def run_command(self, capture = False):
self.process = subprocess.Popen(self.cmd, shell=True)
self.process.communicate()
def run(self, timeout = 5 * 60):
'''5 minutes default timeout'''
thread = threading.Thread(target=self.run_command, args=())
thread.start()
thread.join(timeout)
if thread.is_alive():
print 'Command timeout, kill it: ' + self.cmd
self.process.terminate()
thread.join()
return False, 255
else:
return True, self.process.returncode
osName = platform.system()
print('os name = {}'.format(osName))
@ -81,5 +114,6 @@ shutil.copy(os.path.join(
# lldb = "lldb --batch -o 'run' -k 'thread backtrace all' -k 'quit 1'"
lldb = "" # Disabled for now
testCommand = '{} {} {}'.format(lldb, testBinary, os.getenv('TEST', ''))
ret = os.system(testCommand)
command = Command(testCommand)
timedout, ret = command.run()
assert ret == 0, 'Test command failed'