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 5
5
6
6
from abc import ABC , abstractmethod
7
7
from typing import Iterator , Union
8
+ import fcntl
8
9
import json
9
10
import logging
10
11
import socket
11
12
import ssl
13
+ import struct
14
+ import termios
15
+ import time
12
16
13
17
from requests .auth import HTTPBasicAuth
14
18
import pylogbeat
@@ -122,9 +126,19 @@ def _convert_data_to_send(self, data):
122
126
def _close (self , force = False ):
123
127
if not self ._keep_connection or force :
124
128
if self ._sock :
129
+ while not self ._is_sock_write_buff_empty ():
130
+ time .sleep (0.05 )
125
131
self ._sock .close ()
126
132
self ._sock = None
127
133
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
+
128
142
# ----------------------------------------------------------------------
129
143
def close (self ):
130
144
self ._close (force = True )
You can’t perform that action at this time.
0 commit comments