本文整理汇总了Python中shadowsocks.shell.print_exception函数的典型用法代码示例。如果您正苦于以下问题:Python print_exception函数的具体用法?Python print_exception怎么用?Python print_exception使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_exception函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run_server
def run_server():
def child_handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
list(map(lambda s: s.close(next_tick=True),
tcp_servers + udp_servers))
"""
getattr(object, name[, default]) 如果 siganl.SIGQUIT 不存在,即注册 SIGTERM 事件
SIGTERM 终止进程,但终止前会允许 handler 被执行,SIGKILL 不会
SIGQUIT 在 SIGTERM 的基础上,还生成了一份 core dump 文件记录了进程信息
http://programmergamer.blogspot.jp/2013/05/clarification-on-sigint-sigterm-sigkill.html
"""
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM),
child_handler)
# 中断处理函数,如果接受到键盘中断信号,则异常退出
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
try:
# 定义新事件循环
loop = eventloop.EventLoop()
# 添加 dns 解析器到事件循环中
dns_resolver.add_to_loop(loop)
# 批量地将所有 tcp_server 和 udp_server 加入事件循环中
list(map(lambda s: s.add_to_loop(loop), tcp_servers + udp_servers))
# 使守护进程以设置中 user 的名义执行
daemon.set_user(config.get('user', None))
# 启动事件循环
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
开发者ID:xh4n3,项目名称:decode_ss,代码行数:33,代码来源:server.py
示例2: run_server
def run_server():
def child_handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
list(map(lambda s: s.close(next_tick=True),
tcp_servers + udp_servers))
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM),
child_handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
pid = os.getpid();
logging.info("pid-file=%s,pid=%d", config['pid-file'], pid);
try:
with open(config['pid-file'], 'w') as f:
f.write(str(pid));
f.close();
except IOError:
logging.warn('error on write pid to pid-file..%s, %d', config['pid-file'], pid)
sys.exit(1)
try:
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
list(map(lambda s: s.add_to_loop(loop), tcp_servers + udp_servers))
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
开发者ID:wyyxdgm,项目名称:shadowsocks-python,代码行数:32,代码来源:server.py
示例3: handle_event
def handle_event(self, sock, fd, event):
# handle events and dispatch to handlers
if sock:
logging.log(shell.VERBOSE_LEVEL, 'fd %d %s', fd,
eventloop.EVENT_NAMES.get(event, event))
if sock == self._server_socket:
if event & eventloop.POLL_ERR:
# TODO
raise Exception('server_socket error')
try:
logging.debug('accept')
conn = self._server_socket.accept()
TCPRelayHandler(self, self._fd_to_handlers,
self._eventloop, conn[0], self._config,
self._dns_resolver, self._is_local)
except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK):
return
else:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
else:
if sock:
handler = self._fd_to_handlers.get(fd, None)
if handler:
handler.handle_event(sock, event)
else:
logging.warn('poll removed fd')
开发者ID:EvilCult,项目名称:shadowsocks,代码行数:31,代码来源:tcprelay.py
示例4: run_server
def run_server():
def child_handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
list(map(lambda s: s.close(next_tick=True),
tcp_servers + udp_servers))
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM),
child_handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
def hup_handler(signum, _):
users = shell.get_user_dict(config['users-file'])
for tcp_server in tcp_servers:
tcp_server.set_users(users)
signal.signal(signal.SIGHUP, hup_handler)
try:
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
list(map(lambda s: s.add_to_loop(loop), tcp_servers + udp_servers))
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
开发者ID:sleeplessman,项目名称:shadowsocks,代码行数:28,代码来源:server.py
示例5: write_pid_file
def write_pid_file(pid_file, pid):
import fcntl
import stat
try:
fd = os.open(pid_file, os.O_RDWR | os.O_CREAT, stat.S_IRUSR | stat.S_IWUSR)
except OSError as e:
shell.print_exception(e)
return -1
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
assert flags != -1
flags |= fcntl.FD_CLOEXEC
r = fcntl.fcntl(fd, fcntl.F_SETFD, flags)
assert r != -1
# There is no platform independent way to implement fcntl(fd, F_SETLK, &fl)
# via fcntl.fcntl. So use lockf instead
try:
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB, 0, 0, os.SEEK_SET)
except IOError:
r = os.read(fd, 32)
if r:
logging.error('already started at pid %s' % common.to_str(r))
else:
logging.error('already started')
os.close(fd)
return -1
os.ftruncate(fd, 0)
os.write(fd, common.to_bytes(str(pid)))
return 0
开发者ID:JustAFakeName,项目名称:ss,代码行数:29,代码来源:daemon.py
示例6: handle_event
def handle_event(self, sock, fd, event):
if sock == self._server_socket:
if event & eventloop.POLL_ERR:
logging.error('UDP server_socket err')
try:
self._handle_server()
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
elif sock and (fd in self._sockets):
if event & eventloop.POLL_ERR:
logging.error('UDP client_socket err')
try:
self._handle_client(sock)
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
else:
if sock:
handler = self._fd_to_handlers.get(fd, None)
if handler:
handler.handle_event(sock, event)
else:
logging.warn('poll removed fd')
开发者ID:chasenn,项目名称:Shadowsowcks1Click,代码行数:26,代码来源:udprelay.py
示例7: run
def run(self):
events = []
while not self._stopping:
asap = False
try:
events = self.poll(TIMEOUT_PRECISION)
except (OSError, IOError) as e:
if errno_from_exception(e) in (errno.EPIPE, errno.EINTR):
# EPIPE: Happens when the client closes the connection
# EINTR: Happens when received a signal
# handles them as soon as possible
asap = True
logging.debug('poll:%s', e)
else:
logging.error('poll:%s', e)
import traceback
traceback.print_exc()
continue
for sock, fd, event in events:
handler = self._fdmap.get(fd, None)
if handler is not None:
handler = handler[1]
try:
handler.handle_event(sock, fd, event)
except (OSError, IOError) as e:
shell.print_exception(e)
now = time.time()
if asap or now - self._last_time >= TIMEOUT_PRECISION:
for callback in self._periodic_callbacks:
callback()
self._last_time = now
开发者ID:luffySaw,项目名称:shadowsocks-R,代码行数:32,代码来源:eventloop.py
示例8: _on_remote_read
def _on_remote_read(self):
logging.debug("Running in the TCPRelayHandler class. [_on_remote_read]")
# handle all remote read events
data = None
try:
data = self._remote_sock.recv(BUF_SIZE)
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) in (errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK):
return
if not data:
self.destroy()
return
self._update_activity(len(data))
if self._is_local:
data = self._encryptor.decrypt(data)
else:
data = self._encryptor.encrypt(data)
try:
self._write_to_sock(data, self._local_sock)
# if not self._is_local:
# if self._config.has_key('port_limit') and self._config['port_limit'] != "" and os.path.exists(self._config['port_limit']):
# port_limits = json.loads(open(self._config['port_limit']).read())
# if str(self._server._listen_port) in port_limits:
# port_limits['%s' % self._server._listen_port]['used'] = port_limits['%s' % self._server._listen_port]['used'] + len(data) + BUF_SIZE
# open('%s' % self._config['port_limit'],"w").write("%s" % json.dumps(port_limits,indent=4,ensure_ascii=False,sort_keys=True))
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
# TODO use logging when debug completed
self.destroy()
开发者ID:JustAFakeName,项目名称:ss,代码行数:33,代码来源:tcprelay.py
示例9: run
def run(self):
events = []
while self._ref_handlers:
try:
events = self.poll(1)
except (OSError, IOError) as e:
if errno_from_exception(e) in (errno.EPIPE, errno.EINTR):
# EPIPE: Happens when the client closes the connection
# EINTR: Happens when received a signal
# handles them as soon as possible
logging.debug('poll:%s', e)
else:
logging.error('poll:%s', e)
import traceback
traceback.print_exc()
continue
self._iterating = True
for handler in self._handlers:
# TODO when there are a lot of handlers
try:
handler(events)
except (OSError, IOError) as e:
shell.print_exception(e)
if self._handlers_to_remove:
for handler in self._handlers_to_remove:
self._handlers.remove(handler)
self._handlers_to_remove = []
self._iterating = False
开发者ID:1ookup,项目名称:shadowsocks,代码行数:28,代码来源:eventloop.py
示例10: _on_remote_read
def _on_remote_read(self):
# handle all remote read events
data = None
try:
data = self._remote_sock.recv(BUF_SIZE)
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) in \
(errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK):
return
if not data:
self.destroy()
return
self._update_activity(len(data))
if self._is_local:
data = self._encryptor.decrypt(data)
else:
data = self._encryptor.encrypt(data)
try:
self._write_to_sock(data, self._local_sock)
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
# TODO use logging when debug completed
self.destroy()
开发者ID:EvilCult,项目名称:shadowsocks,代码行数:26,代码来源:tcprelay.py
示例11: _on_remote_read
def _on_remote_read(self):
# handle all remote read events
data = None
try:
data = self._remote_sock.recv(BUF_SIZE)
except socket.error as err:
error_no = err.args[0]
if sys.platform == "win32":
if error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK, errno.WSAEWOULDBLOCK):
return
elif error_no in (errno.EAGAIN, errno.EINPROGRESS,
errno.EWOULDBLOCK):
return
if not data:
self.destroy()
return
self._update_activity(len(data))
if self._is_local:
data = self._encryptor.decrypt(data)
else:
data = self._encryptor.encrypt(data)
try:
self._write_to_sock(data, self._local_sock)
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
# TODO use logging when debug completed
self.destroy()
开发者ID:ambjlon,项目名称:shadowsocks,代码行数:31,代码来源:tcprelay.py
示例12: _on_remote_read
def _on_remote_read(self):
logging.debug('on remote read')
# handle all remote read events
data = None
try:
data = self._remote_sock.recv(BUF_SIZE)
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) in \
(errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK):
return
if not data:
self.destroy()
return
self._update_activity(len(data))
if self._is_local:
data = self._encryptor.decrypt(data)
else:
# logging.debug('received data:[%s]' % data)
# data = 'HTTP/1.1 302 Found\nLocation: https://ashadowsocks.com/'
data = self._encryptor.encrypt(data)
try:
self._write_to_sock(data, self._local_sock)
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
# TODO use logging when debug completed
self.destroy()
开发者ID:yeweishuai,项目名称:shadowsocks-1,代码行数:29,代码来源:tcprelay.py
示例13: write_pid_file
def write_pid_file(pid_file, pid):
"""
pidfile
通常在 /var/run 目录中会看到很多进程的 pid 文件, 其实这些文件就是一个记录着进程的 PID 号的文本文件。
它的作用是防止程序启动多个副本,只有获得 pid 文件写入权限的进程才能正常启动并把进程 PID 写入到该文件,
而同一程序的其他进程则会检测到该文件无法写入退出。
"""
# 文件描述符控制
import fcntl
# 获取文件信息
import stat
try:
# O_RDWR | O_CREAT 如果文件存在,打开文件以读取写入,否则创建该文件,并使其拥有以下权限
# S_IRUSR 文件所有者具可读取权限
# S_IWUSR 文件所有者具可写入权限
fd = os.open(pid_file, os.O_RDWR | os.O_CREAT,
stat.S_IRUSR | stat.S_IWUSR)
except OSError as e:
shell.print_exception(e)
return -1
# F_GETFD 获取文件描述符标记
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
assert flags != -1
flags |= fcntl.FD_CLOEXEC
r = fcntl.fcntl(fd, fcntl.F_SETFD, flags)
assert r != -1
# There is no platform independent way to implement fcntl(fd, F_SETLK, &fl)
# via fcntl.fcntl. So use lockf instead
try:
"""
文件锁
LOCK_EX exclusive 独占锁
LOCK_NB non-blocking 非阻塞锁
在独占锁的情况下,同一时间只有一个进程可以锁住这个文件。
在有其他进程占有该锁时,
如果是阻塞锁,lockf 函数会一直阻塞,直到获得锁,而非阻塞锁使 lockf 函数直接返回 IOError。
fcntl.lockf(fd, operation[, length[, start[, whence]]])
start 和 length 标记了要锁住的区域的起始位置和长度,而 whence 标记了整个锁区域的偏移量。
SEEK_SET SEEK_CUR SEEK_END 分别表示文件开头,当前指针位置和文件结尾
"""
fcntl.lockf(fd, fcntl.LOCK_EX | fcntl.LOCK_NB, 0, 0, os.SEEK_SET)
except IOError:
# pidfile 被其他进程锁住的情况,读取该 pidfile 内容
r = os.read(fd, 32)
if r:
logging.error('already started at pid %s' % common.to_str(r))
else:
logging.error('already started')
os.close(fd)
return -1
# 把 fd 对应文件修剪为长度为 0,即清空该文件
os.ftruncate(fd, 0)
# 将当前进程的 pid 文件写入到 fd 对应文件中
os.write(fd, common.to_bytes(str(pid)))
return 0
开发者ID:7uk0n,项目名称:decode_ss,代码行数:58,代码来源:daemon.py
示例14: _write_to_sock
def _write_to_sock(self, data, sock):
logging.debug("Running in the TCPRelayHandler class. [_write_to_sock]")
# write data to sock
# if only some of the data are written, put remaining in the buffer
# and update the stream to wait for writing
if not data or not sock:
return False
uncomplete = False
try:
l = len(data)
if sock == self._local_sock and self._is_local and self._stage == STAGE_INIT:
logging.info("[Client] Received data from browser and just sending 'hello' back to [browser] ! data length is: [%s]" % l)
elif sock == self._remote_sock and self._is_local and self._stage == STAGE_STREAM:
logging.info("[Client] Received data from browser and just sending -encrypted- data to [VPS] ! data length is: [%s]" % l)
elif sock == self._local_sock and self._is_local and self._stage == STAGE_STREAM:
logging.info("[Client] Received data from VPS and just sending -decrypted- data to [browser] ! data length is: [%s]" % l)
elif sock == self._remote_sock and not self._is_local and self._stage == STAGE_STREAM:
logging.info("[Server] Received data from client and going to send -decrypted- data to [INTERNET] ! data length is: [%s]" % l)
elif sock == self._local_sock and not self._is_local and self._stage == STAGE_STREAM:
logging.info("[Server] Received data from INTERNET and going to send -encrypted- data to [client] ! data length is: [%s]" % l)
if not self._is_local:
if self._config.has_key('port_limit') and self._config['port_limit'] != "" and os.path.exists(self._config['port_limit']):
port_limits = json.loads(open(self._config['port_limit']).read())
if str(self._server._listen_port) in port_limits:
port_limits['%s' % self._server._listen_port]['used'] = port_limits['%s' % self._server._listen_port]['used'] + len(data)
open('%s' % self._config['port_limit'],"w").write("%s" % json.dumps(port_limits,indent=4,ensure_ascii=False,sort_keys=True))
s = sock.send(data)
if s < l:
data = data[s:]
uncomplete = True
except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS, errno.EWOULDBLOCK):
uncomplete = True
else:
shell.print_exception(e)
self.destroy()
return False
if uncomplete:
if sock == self._local_sock:
self._data_to_write_to_local.append(data)
self._update_stream(STREAM_DOWN, WAIT_STATUS_WRITING)
elif sock == self._remote_sock:
self._data_to_write_to_remote.append(data)
self._update_stream(STREAM_UP, WAIT_STATUS_WRITING)
else:
logging.error('write_all_to_sock:unknown socket')
common.error_to_file('write_all_to_sock:unknown socket',self._config)
else:
if sock == self._local_sock:
self._update_stream(STREAM_DOWN, WAIT_STATUS_READING)
elif sock == self._remote_sock:
self._update_stream(STREAM_UP, WAIT_STATUS_READING)
else:
logging.error('write_all_to_sock:unknown socket')
common.error_to_file('write_all_to_sock:unknown socket',self._config)
return True
开发者ID:JustAFakeName,项目名称:ss,代码行数:57,代码来源:tcprelay.py
示例15: parse_response
def parse_response(data):
try:
if len(data) >= 12:
# analyse Header
header = parse_header(data)
if not header:
return None
res_id, res_qr, res_tc, res_ra, res_rcode, res_qdcount, \
res_ancount, res_nscount, res_arcount = header
qds = [] # [(name, None, record_type, record_class, None, None)]
ans = [] # [(name, ip, record_type, record_class, record_ttl)]
offset = 12
# extract all questions and answers, and store them
# l is the length of either one Question or one Answer section
# analyse Question section
for i in range(0, res_qdcount):
l, r = parse_record(data, offset, True)
# update offset
# Question section contains QDCOUNT entries
offset += l
if r:
qds.append(r)
# analyse Answer section
for i in range(0, res_ancount):
l, r = parse_record(data, offset)
# Answer section contains ANCOUNT entries
offset += l
if r:
ans.append(r)
# not used
for i in range(0, res_nscount):
l, r = parse_record(data, offset)
offset += l
for i in range(0, res_arcount):
l, r = parse_record(data, offset)
offset += l
response = DNSResponse()
if qds:
response.hostname = qds[0][0] # name
for an in qds:
response.questions.append((an[1], an[2], an[3])) # [(None, record_type, record_class)]
for an in ans:
response.answers.append((an[1], an[2], an[3])) # [(ip, record_type, record_class)]
return response
except Exception as e:
shell.print_exception(e)
return None
开发者ID:whenhecry,项目名称:shadowsocks,代码行数:55,代码来源:asyncdns.py
示例16: _handle_dns_resolved
def _handle_dns_resolved(self, result, error):
if error:
self._log_error(error)
self.destroy()
return
# when domain name is resolved
if result:
ip = result[1]
if ip:
try:
self._stage = STAGE_CONNECTING
remote_addr = ip
# port is not included in the result
if self._is_local:
remote_port = self._chosen_server[1]
else:
remote_port = self._remote_address[1]
# for fastopen sslocal:
# sslocal reads from client
if self._is_local and self._config['fast_open']:
self._stage = STAGE_CONNECTING
# we don't have to wait for remote since it's not created
self._update_stream(STREAM_UP, WAIT_STATUS_READING)
# TODO when there is already data in this packet
# for non-fastopen sslocal,
# 1. connect to ssremote, add to loop, set event as ERR|OUT
# 2. sslocal relays up stream
# for ssremote,
# 1. connect to dest, add to loop, set event as ERR|OUT
# 2. ssremote reads from dest
else:
remote_sock = self._create_remote_socket(remote_addr,
remote_port)
try:
remote_sock.connect((remote_addr, remote_port))
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) == \
errno.EINPROGRESS:
pass
self._loop.add(remote_sock,
eventloop.POLL_ERR | eventloop.POLL_OUT,
self._server)
self._stage = STAGE_CONNECTING
self._update_stream(STREAM_UP, WAIT_STATUS_READWRITING)
self._update_stream(STREAM_DOWN, WAIT_STATUS_READING)
return
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
self.destroy()
开发者ID:whenhecry,项目名称:shadowsocks,代码行数:55,代码来源:tcprelay.py
示例17: daemon_start
def daemon_start(pid_file, log_file):
# 启动一个 daemon
def handle_exit(signum, _):
# 如果信号为 SIGTERM,则 sys.exit(0),其中 0 代表正常退出
if signum == signal.SIGTERM:
sys.exit(0)
# 否则为异常退出
sys.exit(1)
# 设置当接收到 SIGINIT 或者 SIGTERM 信号时,调用 handle_exit 函数
signal.signal(signal.SIGINT, handle_exit)
signal.signal(signal.SIGTERM, handle_exit)
# fork only once because we are sure parent will exit
pid = os.fork()
# 断言 fork 函数返回正常
assert pid != -1
# 此处为父进程执行
if pid > 0:
# parent waits for its child
# 睡眠 5 秒后正常退出
time.sleep(5)
sys.exit(0)
# child signals its parent to exit
# 获得父进程 pid
ppid = os.getppid()
# 获得子进程 pid
pid = os.getpid()
# 将子进程 PID 写入 pid 文件
if write_pid_file(pid_file, pid) != 0:
# 如果写入失败则杀死父进程,同时子进程退出自己
# 写入失败原因可能是有另一进程已经启动,控制了 pid 文件
os.kill(ppid, signal.SIGINT)
sys.exit(1)
# setsid() 以后,子进程就不会因为父进程的退出而终止
os.setsid()
# SIGHUP 挂起信号,SIG_IGN 为忽略该挂起信号
signal.signal(signal.SIGHUP, signal.SIG_IGN)
print('started')
# 使用 SIGTERM 信号杀掉父进程,SIGTERM 给了程序一个处理任务的机会,SIGKILL 会直接杀死进程
os.kill(ppid, signal.SIGTERM)
# 关闭标准输入,相当于 os.close(sys.stdin.fileno())
sys.stdin.close()
try:
# 以追加的方式将 stdout 和 stderr 重定向到 log_file
freopen(log_file, 'a', sys.stdout)
freopen(log_file, 'a', sys.stderr)
except IOError as e:
shell.print_exception(e)
sys.exit(1)
开发者ID:7uk0n,项目名称:decode_ss,代码行数:54,代码来源:daemon.py
示例18: _handle_dns_resolved
def _handle_dns_resolved(self, result, error):
"""
DNS请求解析完成后调用该函数
result: (addr, ip)
error: error
"""
if error:
self._log_error(error)
self.destroy()
return
if result:
ip = result[1]
if ip:
try:
self._stage = STAGE_CONNECTING
remote_addr = ip
# 若为sslocal,则remote_socket连接的端口为初始化文件中的服务器端口
# 若为ssserver,则remote_socket连接的端口为解析出的remote_address的地址
if self._is_local:
remote_port = self._chosen_server[1]
else:
remote_port = self._remote_address[1]
if self._is_local and self._config['fast_open']:
# for fastopen:
# wait for more data to arrive and send them in one SYN
self._stage = STAGE_CONNECTING
# we don't have to wait for remote since it's not
# created
self._update_stream(STREAM_UP, WAIT_STATUS_READING)
# TODO when there is already data in this packet
else:
# else do connect
remote_sock = self._create_remote_socket(remote_addr,
remote_port)
try:
remote_sock.connect((remote_addr, remote_port))
except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) == \
errno.EINPROGRESS:
pass
self._loop.add(remote_sock,
eventloop.POLL_ERR | eventloop.POLL_OUT,
self._server)
self._stage = STAGE_CONNECTING
self._update_stream(STREAM_UP, WAIT_STATUS_READWRITING)
self._update_stream(STREAM_DOWN, WAIT_STATUS_READING)
return
except Exception as e:
shell.print_exception(e)
if self._config['verbose']:
traceback.print_exc()
self.destroy()
开发者ID:ncs19960831,项目名称:shadowsocks-analysis,代码行数:54,代码来源:tcprelay.py
示例19: run_server
def run_server():
try:
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
list(map(lambda s: s.add_to_loop(loop), tcp_servers))
daemon.set_user(config.get('user', None))
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
开发者ID:BroncoTc,项目名称:p2pproxy,代码行数:11,代码来源:Client.py
示例20: main
def main():
shell.check_python()
# fix py2exe
if hasattr(sys, "frozen") and sys.frozen in \
("windows_exe", "console_exe"):
p = os.path.dirname(os.path.abspath(sys.executable))
os.chdir(p)
config = shell.get_config(True)
daemon.daemon_exec(config)
try:
logging.info("starting local at %s:%d" %
(config['local_address'], config['local_port']))
dns_resolver = asyncdns.DNSResolver()
tcp_server = tcprelay.TCPRelay(config, dns_resolver, True,
stat_callback=stat_handler)
a_config = config.copy()
if a_config.get('port_password', None):
a_config['server_port'] = random.choice(
a_config['port_password'].keys())
a_config['password'] = a_config['port_password']\
[a_config['server_port']]
udp_server = udprelay.UDPRelay(a_config, dns_resolver, True,
stat_callback=stat_handler)
loop = eventloop.EventLoop()
dns_resolver.add_to_loop(loop)
tcp_server.add_to_loop(loop)
udp_server.add_to_loop(loop)
def handler(signum, _):
logging.warn('received SIGQUIT, doing graceful shutting down..')
tcp_server.close(next_tick=True)
udp_server.close(next_tick=True)
signal.signal(getattr(signal, 'SIGQUIT', signal.SIGTERM), handler)
def int_handler(signum, _):
sys.exit(1)
signal.signal(signal.SIGINT, int_handler)
daemon.set_user(config.get('user', None))
t = threading.Thread(target=monitor, args=(), name='monitor')
t.daemon = True
t.start()
loop.run()
except Exception as e:
shell.print_exception(e)
sys.exit(1)
开发者ID:ultimate010,项目名称:shadowsocks,代码行数:54,代码来源:local.py
注:本文中的shadowsocks.shell.print_exception函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论