File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 55
66from abc import ABC , abstractmethod
77from typing import Iterator , Union
8+ import fcntl
89import json
910import logging
1011import socket
1112import ssl
13+ import struct
14+ import termios
15+ import time
1216
1317from requests .auth import HTTPBasicAuth
1418import pylogbeat
@@ -122,9 +126,19 @@ def _convert_data_to_send(self, data):
122126 def _close (self , force = False ):
123127 if not self ._keep_connection or force :
124128 if self ._sock :
129+ while not self ._is_sock_write_buff_empty ():
130+ time .sleep (0.05 )
125131 self ._sock .close ()
126132 self ._sock = None
127133
134+ # ----------------------------------------------------------------------
135+ def _is_sock_write_buff_empty (self ):
136+ socket_fd = self ._sock .fileno ()
137+ buffer_size = struct .pack ('I' , 0 )
138+ ioctl_result = fcntl .ioctl (socket_fd , termios .TIOCOUTQ , buffer_size )
139+ buffer_size = struct .unpack ('I' , ioctl_result )[0 ]
140+ return not buffer_size
141+
128142 # ----------------------------------------------------------------------
129143 def close (self ):
130144 self ._close (force = True )
You can’t perform that action at this time.
0 commit comments