Skip to content

Commit

Permalink
server: fix do_read() enough to run bench_sendall() PY3
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Apr 29, 2014
1 parent 4c173c7 commit 564a7fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions gevent/_socket3.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def accept(self):
# Python Issue #7995: if no default timeout is set and the listening
# socket had a (non-zero) timeout, force the new socket in blocking
# mode to override platform-specific socket flags inheritance.
# XXX do we need to do this?
if getdefaulttimeout() is None and self.gettimeout():
sock.setblocking(True)
return sock, addr
Expand Down
42 changes: 30 additions & 12 deletions gevent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import _socket
from gevent.baseserver import BaseServer
from gevent.socket import EWOULDBLOCK, socket
from gevent.hub import PYPY
from gevent.hub import PYPY, PY3
if PY3:
from io import BlockingIOError


__all__ = ['StreamServer', 'DatagramServer']
Expand Down Expand Up @@ -89,17 +91,33 @@ def get_listener(self, address, backlog=None, family=None):
backlog = self.backlog
return _tcp_listener(address, backlog=backlog, reuse_addr=self.reuse_addr, family=family)

def do_read(self):
try:
client_socket, address = self.socket.accept()
except _socket.error as err:
if err.args[0] == EWOULDBLOCK:
return
raise
sockobj = socket(_sock=client_socket)
if PYPY:
client_socket._drop()
return sockobj, address
if PY3:

def do_read(self):
sock = self.socket
try:
fd, address = sock._accept()
except BlockingIOError:
if sock.timeout == 0.0:
return
raise
sock = socket(sock.family, sock.type, sock.proto, fileno=fd)
# XXX Python issue #7995?
return sock, address

else:

def do_read(self):
try:
client_socket, address = self.socket.accept()
except _socket.error as err:
if err.args[0] == EWOULDBLOCK:
return
raise
sockobj = socket(_sock=client_socket)
if PYPY:
client_socket._drop()
return sockobj, address

def do_close(self, socket, *args):
socket.close()
Expand Down

0 comments on commit 564a7fa

Please sign in to comment.