aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/tcp.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/tcp.py')
-rw-r--r--netlib/tcp.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 22cd0965..b05e84f5 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -265,6 +265,24 @@ class Reader(_FileLike):
)
return result
+ def peek(self, length):
+ """
+ Tries to peek into the underlying file object.
+
+ Returns:
+ Up to the next N bytes if peeking is successful.
+ None, otherwise.
+
+ Raises:
+ NetLibSSLError if there was an error with pyOpenSSL.
+ """
+ if isinstance(self.o, SSL.Connection) or isinstance(self.o, socket._fileobject):
+ try:
+ return self.o._sock.recv(length, socket.MSG_PEEK)
+ except SSL.Error as e:
+ raise NetLibSSLError(str(e))
+
+
class Address(object):