-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce method for send buffer size and extract module
Signed-off-by: Pedro Tanaka <[email protected]>
- Loading branch information
1 parent
fc59717
commit 55e0c2b
Showing
3 changed files
with
47 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module StatsD | ||
module Instrument | ||
module ConnectionBehavior | ||
def close | ||
@socket&.close | ||
rescue IOError, SystemCallError => e | ||
StatsD.logger.debug do | ||
"[#{self.class.name}] Error closing socket: #{e.class}: #{e.message}" | ||
end | ||
ensure | ||
@socket = nil | ||
end | ||
|
||
def send_buffer_size | ||
if socket | ||
socket.getsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF).int | ||
else | ||
@max_packet_size | ||
end | ||
end | ||
|
||
private | ||
|
||
def setup_socket(socket) | ||
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, @max_packet_size.to_i) | ||
socket | ||
rescue IOError => e | ||
StatsD.logger.debug do | ||
"[#{self.class.name}] Failed to create socket: #{e.class}: #{e.message}" | ||
end | ||
nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters