1010import riemann_client .riemann_pb2
1111
1212
13+ # Default arguments
14+ HOST = 'localhost'
15+ PORT = 5555
16+ TIMEOUT = None
17+
18+
1319def socket_recvall (socket , length , bufsize = 4096 ):
1420 """Recives bytes from a socket until the buffer is the requested length"""
1521 data = ""
@@ -51,7 +57,7 @@ def send(self):
5157class SocketTransport (Transport ):
5258 """Provides common functionality for Transports using sockets"""
5359
54- def __init__ (self , host = 'localhost' , port = 5555 ):
60+ def __init__ (self , host = HOST , port = PORT ):
5561 self .host = host
5662 self .port = port
5763
@@ -74,6 +80,7 @@ def socket(self, value):
7480class UDPTransport (SocketTransport ):
7581 def connect (self ):
7682 self .socket = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
83+ self .socket .settimeout (self .timeout )
7784
7885 def disconnect (self ):
7986 self .socket .close ()
@@ -84,9 +91,12 @@ def send(self, message):
8491
8592
8693class TCPTransport (SocketTransport ):
94+ def __init__ (self , host = HOST , port = PORT , timeout = TIMEOUT ):
95+ super (TCPTransport , self ).__init__ (host , port )
96+ self .timeout = timeout
97+
8798 def connect (self ):
88- self .socket = socket .create_connection (self .address )
89- self .socket .setblocking (True )
99+ self .socket = socket .create_connection (self .address , self .timeout )
90100
91101 def disconnect (self ):
92102 self .socket .close ()
@@ -106,8 +116,8 @@ def send(self, message):
106116
107117
108118class TLSTransport (TCPTransport ):
109- def __init__ (self , host = 'localhost' , port = 5554 , ca_certs = None ):
110- super (TLSTransport , self ).__init__ (host , port )
119+ def __init__ (self , host = HOST , port = PORT , timeout = TIMEOUT , ca_certs = None ):
120+ super (TLSTransport , self ).__init__ (host , port , timeout )
111121 self .ca_certs = ca_certs
112122
113123 def connect (self ):
0 commit comments