Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions riak/transports/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def _new_connection(self):

class Socket(object):

# Allow extending classes to affect how sockets are created through options
_options = {}

def __init__(self, host, port):
self.host = host
self.port = port
Expand All @@ -161,6 +164,8 @@ def __init__(self, host, port):
def maybe_connect(self):
if self.sock is None:
self.sock = s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if "timeout" in self._options:
self.sock.settimeout(self._options["timeout"])

try:
s.connect((self.host, self.port))
Expand Down
8 changes: 8 additions & 0 deletions riak/transports/pbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import errno
import socket
import struct
import types

try:
import json
Expand Down Expand Up @@ -160,6 +161,13 @@ class RiakPbcTransport(RiakTransport):
# The ConnectionManager class that this transport prefers.
default_cm = connection.cm_using(SocketWithId)

@staticmethod
def with_timeout(timeout):
socket_with_timeout = type("SocketWithIdAndTimeout", (SocketWithId,), {"_options":dict(SocketWithId._options)})
socket_with_timeout._options["timeout"] = timeout
cm_with_timeout = connection.cm_using(socket_with_timeout)
return type("RiackPbcTransportWithTimeout", (RiakPbcTransport,), {"default_cm":cm_with_timeout})

def __init__(self, cm, client_id=None, max_attempts=1, **unused_options):
"""
Construct a new RiakPbcTransport object.
Expand Down