Merge lp:~facundo/txstatsd/non-blocking-sockets into lp:txstatsd

Proposed by Facundo Batista
Status: Merged
Approved by: Sidnei da Silva
Approved revision: 45
Merged at revision: 45
Proposed branch: lp:~facundo/txstatsd/non-blocking-sockets
Merge into: lp:txstatsd
Diff against target: 42 lines (+8/-2)
2 files modified
txstatsd/client.py (+3/-2)
txstatsd/tests/test_client.py (+5/-0)
To merge this branch: bzr merge lp:~facundo/txstatsd/non-blocking-sockets
Reviewer Review Type Date Requested Status
Sidnei da Silva Approve
Review via email: mp+80011@code.launchpad.net

Commit message

Make the UDP socket not blocking.

Description of the change

Make the UDP socket not blocking.

Tests included.

To post a comment you must log in.
Revision history for this message
Sidnei da Silva (sidnei) wrote :

Looks good!

I'll merge it manually since there's a typo in the test function name.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'txstatsd/client.py'
2--- txstatsd/client.py 2011-09-06 15:24:29 +0000
3+++ txstatsd/client.py 2011-10-20 22:59:24 +0000
4@@ -62,7 +62,7 @@
5
6 def write(self, data, callback=None):
7 """Send the metric to the StatsD server.
8-
9+
10 @param data: The data to be sent.
11 @param callback: The callback to which the result should be sent.
12 B{Note}: The C{callback} will be called in the C{reactor}
13@@ -72,7 +72,7 @@
14
15 def _write(self, data, callback):
16 """Send the metric to the StatsD server.
17-
18+
19 @param data: The data to be sent.
20 @param callback: The callback to which the result should be sent.
21 @raise twisted.internet.error.MessageLengthError: If the size of data
22@@ -113,6 +113,7 @@
23 def connect(self):
24 """Connect to the StatsD server."""
25 self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
26+ self.socket.setblocking(0)
27
28 def disconnect(self):
29 """Disconnect from the StatsD server."""
30
31=== modified file 'txstatsd/tests/test_client.py'
32--- txstatsd/tests/test_client.py 2011-09-08 12:52:16 +0000
33+++ txstatsd/tests/test_client.py 2011-10-20 22:59:24 +0000
34@@ -64,3 +64,8 @@
35 UdpStatsDClient, 'localhost', 'malformed')
36 self.assertRaises(ValueError,
37 UdpStatsDClient, 0, 8000)
38+
39+ def test_idpstatsd_socket_nonblocking(self):
40+ client = UdpStatsDClient('localhost', 8000)
41+ client.connect()
42+ self.assertEqual(client.socket.gettimeout(), 0.0)

Subscribers

People subscribed via source and target branches