Commit 2838fac9 authored by Denis Bilenko's avatar Denis Bilenko

move wait_reader and wait_writer from greenlet.py to socket.py

parent 275b4165
import sys import sys
import os import os
import traceback import traceback
import _socket # for timeout
from gevent import core from gevent import core
...@@ -501,29 +500,3 @@ class DispatchExit(Exception): ...@@ -501,29 +500,3 @@ class DispatchExit(Exception):
Exception.__init__(self, code) Exception.__init__(self, code)
def _wait_helper(ev, evtype):
current, timeout_exc = ev.arg
if evtype & core.EV_TIMEOUT:
current.throw(timeout_exc)
else:
current.switch(ev)
def wait_reader(fileno, timeout=-1, timeout_exc=_socket.timeout):
evt = core.read(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc))
try:
switch_result = get_hub().switch()
assert evt is switch_result, 'Invalid switch into wait_reader(): %r' % (switch_result, )
finally:
evt.cancel()
def wait_writer(fileno, timeout=-1, timeout_exc=_socket.timeout):
evt = core.write(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc))
try:
switch_result = get_hub().switch()
assert evt is switch_result, 'Invalid switch into wait_writer(): %r' % (switch_result, )
finally:
evt.cancel()
...@@ -35,10 +35,38 @@ import sys ...@@ -35,10 +35,38 @@ import sys
import errno import errno
import time import time
from gevent.greenlet import wait_reader, wait_writer, spawn from gevent.greenlet import spawn, getcurrent, get_hub
from gevent import core
BUFFER_SIZE = 4096 BUFFER_SIZE = 4096
def _wait_helper(ev, evtype):
current, timeout_exc = ev.arg
if evtype & core.EV_TIMEOUT:
current.throw(timeout_exc)
else:
current.switch(ev)
def wait_reader(fileno, timeout=-1, timeout_exc=_socket.timeout):
evt = core.read(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc))
try:
switch_result = get_hub().switch()
assert evt is switch_result, 'Invalid switch into wait_reader(): %r' % (switch_result, )
finally:
evt.cancel()
def wait_writer(fileno, timeout=-1, timeout_exc=_socket.timeout):
evt = core.write(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc))
try:
switch_result = get_hub().switch()
assert evt is switch_result, 'Invalid switch into wait_writer(): %r' % (switch_result, )
finally:
evt.cancel()
try: try:
from OpenSSL import SSL from OpenSSL import SSL
except ImportError: except ImportError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment