Plugin Helper: Socket
The socket
plugin helper creates various types of socket instances.
Here is an example:
The socket
plugin helper does not manage the lifecycle of the socket. User must close the socket when it is no longer needed.
Methods
socket_create(proto, host, port, **kwargs, &block)
socket_create(proto, host, port, **kwargs, &block)
This method creates a socket instance with the given protocol type.
If the block is given, it will be invoked with the socket instance as a parameter, and the socket will automatically be closed when the block terminates.
proto
: protocol type. {:tcp
,:udp
,:tls
}host
: host name or IP addressport
: port numberkwargs
: extra options. For more details, see methods below.block
: customize socket
Code example:
socket_create_tcp(host, port, **kwargs, &block)
socket_create_tcp(host, port, **kwargs, &block)
This method creates socket instance for TCP.
If the block is given, it will be invoked with the socket instance as a parameter, and the socket will automatically be closed when the block terminates.
host
: hostname or IP addressport
: port numberkwargs
: extra optionsresolve_name
: iftrue
, resolve the hostnamenonblock
: iftrue
, use non-blocking I/Olinger_timeout
: the timeout (seconds) to setSO_LINGER
recv_timeout
: the timeout (seconds) to setSO_RECVTIMEO
send_timeout
: the timeout (seconds) to setSO_SNDTIMEO
send_keepalive_packet
: iftrue
, enable TCP keep-alive viaSO_KEEPALIVE
connect_timeout
: the timeout for socket connect. When the connectiontimed out during establishment,
Errno::ETIMEDOUT
is raised.
send_keepalive_packet
Use Case
send_keepalive_packet
Use CaseIf you set true
to send_keepalive_packet
, you also need to configure keep-alive related kernel parameters:
This parameter mitigates half-open connection issue with load balancers. Check also this issue for AWS NLB case.
socket_create_udp(host, port, **kwargs, &block)
socket_create_udp(host, port, **kwargs, &block)
This method creates socket instance for UDP.
If block is given, it will be invoked with the socket instance as a parameter, and socket will automatically be closed when the block terminates.
host
: host name or IP addressport
: port numberkwargs
: extra optionsresolve_name
: iftrue
, resolve the hostnameconnect
: iftrue
, connect to hostnonblock
: iftrue
, use non-blocking I/Olinger_timeout
: the timeout (seconds) to setSO_LINGER
recv_timeout
: the timeout (seconds) to setSO_RECVTIMEO
send_timeout
: the timeout (seconds) to setSO_SNDTIMEO
socket_create_tls(host, port, **kwargs, &block)
socket_create_tls(host, port, **kwargs, &block)
This method creates socket instance for TLS.
If block is given, it will be invoked with the socket instance as a parameter, and socket will automatically be closed when the block terminates.
host
: host name or IP addressport
: port numberkwargs
: extra optionsversion
: set TLS version:TLSv1_1
or:TLSv1_2
. (default::TLSv1_2
)ciphers
: set the list of available cipher suites. (default:"ALL:!aNULL:!eNULL:!SSLv2"
)insecure
: iftrue
, set TLS verify modeNONE
verify_fqdn
: iftrue
, validate the server certificate for the hostnamefqdn
: set FQDNenable_system_cert_store
: iftrue
, enable system default cert storeallow_self_signed_cert
: iftrue
, allow self-signed certificatecert_paths
: files contain PEM-encoded certificatesprivate_key_path
: set the client private key pathprivate_key_passphrase
: set the client private key passphrasecert_thumbprint
: set the certificate thumbprint for searching from Windows system certstorecert_logical_store_name
: set the certificate logical store name on Windows system certstorecert_use_enterprise_store
: iftrue
, enable to use certificate enterprise store on Windows system certstoreSupport more parameters same as socket_create_tcp's
kwargs
Plugins using socket
socket
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is an open-source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.
Last updated