Skip to content

Commit aea33fb

Browse files
committed
Wait for empty socket write buffer only if "fnctl" is available
Closes #82.
1 parent 16957ca commit aea33fb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

logstash_async/transport.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,21 @@
55

66
from abc import ABC, abstractmethod
77
from typing import Iterator, Union
8-
import fcntl
98
import json
109
import logging
1110
import socket
1211
import ssl
13-
import struct
14-
import termios
1512
import time
1613

14+
15+
# Use fcntl to control socket buffering if available
16+
try:
17+
import fcntl
18+
import struct
19+
import termios
20+
except ImportError:
21+
fcntl = None
22+
1723
from requests.auth import HTTPBasicAuth
1824
import pylogbeat
1925
import requests
@@ -145,6 +151,9 @@ def _wait_for_socket_buffer_empty(self):
145151

146152
# ----------------------------------------------------------------------
147153
def _is_sock_write_buff_empty(self):
154+
if fcntl is None:
155+
return True
156+
148157
socket_fd = self._sock.fileno()
149158
buffer_size = struct.pack('I', 0)
150159
ioctl_result = fcntl.ioctl(socket_fd, termios.TIOCOUTQ, buffer_size)

0 commit comments

Comments
 (0)