mirror of https://github.com/python/cpython.git
socket.py
This commit is contained in:
parent
50d5e8a23a
commit
5510dc23f9
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
# Internal constants
|
# Internal constants
|
||||||
|
|
||||||
_BUFSIZE = 4096 # Size of TCP/UDP input buffer
|
_BUFSIZE = 15*1024 # Size of TCP/UDP input buffer
|
||||||
|
|
||||||
_myaddress = None
|
_myaddress = None
|
||||||
_myname = None
|
_myname = None
|
||||||
|
@ -74,21 +74,21 @@ def _gethostaddress():
|
||||||
|
|
||||||
def socket(family, type, *which):
|
def socket(family, type, *which):
|
||||||
if family <> AF_INET:
|
if family <> AF_INET:
|
||||||
raise my_error, 'Protocol family %d not supported' % type
|
raise _myerror, 'Protocol family %d not supported' % type
|
||||||
if type == SOCK_DGRAM:
|
if type == SOCK_DGRAM:
|
||||||
return _udpsocket()
|
return _udpsocket()
|
||||||
elif type == SOCK_STREAM:
|
elif type == SOCK_STREAM:
|
||||||
return _tcpsocket()
|
return _tcpsocket()
|
||||||
raise my_error, 'Protocol type %d not supported' % type
|
raise _myerror, 'Protocol type %d not supported' % type
|
||||||
|
|
||||||
|
|
||||||
def fromfd(*args):
|
def fromfd(*args):
|
||||||
raise my_error, 'Operation not supported on a mac'
|
raise _myerror, 'Operation not supported on a mac'
|
||||||
|
|
||||||
|
|
||||||
class _socket:
|
class _socket:
|
||||||
def unsupported(self, *args):
|
def unsupported(self, *args):
|
||||||
raise my_error, 'Operation not supported on this socket'
|
raise _myerror, 'Operation not supported on this socket'
|
||||||
|
|
||||||
accept = unsupported
|
accept = unsupported
|
||||||
bind = unsupported
|
bind = unsupported
|
||||||
|
@ -121,7 +121,7 @@ def __init__(self):
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
if not self.listening:
|
if not self.listening:
|
||||||
raise my_error, 'Not listening'
|
raise _myerror, 'Not listening'
|
||||||
self.listening = 0
|
self.listening = 0
|
||||||
self.stream.wait()
|
self.stream.wait()
|
||||||
self.accepted = 1
|
self.accepted = 1
|
||||||
|
@ -169,7 +169,7 @@ def makefile(self, rw = 'r'):
|
||||||
|
|
||||||
def recv(self, bufsize, flags=0):
|
def recv(self, bufsize, flags=0):
|
||||||
if flags:
|
if flags:
|
||||||
raise my_error, 'recv flags not yet supported on mac'
|
raise _myerror, 'recv flags not yet supported on mac'
|
||||||
if not self.databuf:
|
if not self.databuf:
|
||||||
try:
|
try:
|
||||||
self.databuf, urg, mark = self.stream.Rcv(0)
|
self.databuf, urg, mark = self.stream.Rcv(0)
|
||||||
|
@ -207,7 +207,7 @@ def __init__(self):
|
||||||
class _socketfile:
|
class _socketfile:
|
||||||
|
|
||||||
def __init__(self, sock, rw):
|
def __init__(self, sock, rw):
|
||||||
if rw not in ('r', 'w'): raise ValueError, "mode must be 'r' or 'w'"
|
if rw not in ('r', 'w'): raise _myerror, "mode must be 'r' or 'w'"
|
||||||
self.sock = sock
|
self.sock = sock
|
||||||
self.rw = rw
|
self.rw = rw
|
||||||
self.buf = ''
|
self.buf = ''
|
||||||
|
|
Loading…
Reference in New Issue