Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Fixed slow upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Adamski committed Jan 9, 2019
1 parent f797dcd commit d8185bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion idarling/core/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import ctypes
# import ctypes

import ida_auto
import ida_bytes
Expand Down
12 changes: 6 additions & 6 deletions idarling/interface/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class StatusWidget(QWidget):
@staticmethod
def ida_to_python(c):
# IDA colors are 0xBBGGRR.
r = (c & 255) / 255.
g = ((c >> 8) & 255) / 255.
b = ((c >> 16) & 255) / 255.
r = (c & 255) / 255.0
g = ((c >> 8) & 255) / 255.0
b = ((c >> 16) & 255) / 255.0
return r, g, b

@staticmethod
Expand All @@ -41,7 +41,7 @@ def python_to_qt(r, g, b):
r = int(r * 255) << 16
g = int(g * 255) << 8
b = int(b * 255)
return 0xff000000 | r | g | b
return 0xFF000000 | r | g | b

@staticmethod
def make_icon(template, color):
Expand All @@ -62,9 +62,9 @@ def make_icon(template, color):
for x in range(image.width()):
for y in range(image.height()):
c = image.pixel(x, y)
if (c & 0xffffff) == 0xffffff:
if (c & 0xFFFFFF) == 0xFFFFFF:
image.setPixel(x, y, light)
if (c & 0xffffff) == 0x000000:
if (c & 0xFFFFFF) == 0x000000:
image.setPixel(x, y, dark)
return QPixmap(image)

Expand Down
20 changes: 14 additions & 6 deletions idarling/shared/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PacketEvent(QEvent):
def __init__(self):
super(PacketEvent, self).__init__(PacketEvent.EVENT_TYPE)


class ClientSocket(QObject):
"""
This class is acts a bridge between a client socket and the Qt event loop.
Expand All @@ -54,6 +55,7 @@ def __init__(self, logger, parent=None):
self._read_packet = None

self._write_buffer = bytearray()
self._write_cursor = 0
self._write_notifier = None
self._write_packet = None

Expand Down Expand Up @@ -233,7 +235,7 @@ def _notify_write(self):
if not self._check_socket():
return

if not self._write_buffer:
if self._write_cursor >= len(self._write_buffer):
if not self._outgoing:
return # No more packets to send
self._write_packet = self._outgoing.popleft()
Expand All @@ -249,17 +251,20 @@ def _notify_write(self):
return

# Write the container's content
self._write_buffer.extend(bytearray(line))
self._write_buffer = bytearray(line)
self._write_cursor = 0
if isinstance(self._write_packet, Container):
data = self._write_packet.content
self._write_buffer.extend(bytearray(data))
self._write_packet.size += len(line)

# Send as many bytes as possible
try:
count = min(len(self._write_buffer), ClientSocket.MAX_DATA_SIZE)
sent = self._socket.send(self._write_buffer[:count])
del self._write_buffer[:sent]
pos = self._write_cursor
avail = len(self._write_buffer) - pos
count = min(avail, ClientSocket.MAX_DATA_SIZE)
data = self._write_buffer[pos : pos + count] # noqa: E203
self._write_cursor += self._socket.send(data)
except socket.error as e:
if (
e.errno not in (errno.EAGAIN, errno.EWOULDBLOCK)
Expand All @@ -279,7 +284,10 @@ def _notify_write(self):
sent = max(total - self._write_packet.size, 0)
self._write_packet.upback(sent, total)

if not self._write_buffer and not self._outgoing:
if (
self._write_cursor >= len(self._write_buffer)
and not self._outgoing
):
self._write_notifier.setEnabled(False)

def event(self, event):
Expand Down

0 comments on commit d8185bc

Please sign in to comment.