Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: mojo/devtools/common/android_gdb/remote_file_connection.py

Issue 1209593002: GDB support for Android in devtools' debugger. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import socket
6 import struct
7
8
9 class RemoteFileConnectionException(Exception):
10 def __init__(self, *args, **kwargs):
11 Exception.__init__(self, *args, **kwargs)
12
13
14 class RemoteFileConnection(object):
15 """Client for remote_file_reader server, allowing to read files on an
16 remote device.
17 """
18 def __init__(self, host, port):
19 self._host = host
20 self._port = port
21 self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
22 self._size_struct = struct.Struct("!i")
23
24 def __del__(self):
25 self.disconnect()
26
27 def connect(self):
28 self._socket.connect((self._host, self._port))
29
30 def disconnect(self):
31 self._socket.close()
32
33 def open(self, filename):
34 self._send("O %s\n" % filename)
35 result = self._receive(1)
36 if result != 'O':
37 raise RemoteFileConnectionException("Unable to open file " + filename)
38
39 def seek(self, pos, mode=0):
40 self._send("S %d %d\n" % (pos, mode))
41 result = self._receive(1)
42 if result != 'O':
43 raise RemoteFileConnectionException("Unable to seek in file.")
44
45 def read(self, size=0):
46 assert size > 0
47 self._send("R %d\n" % size)
48 result = self._receive(1)
49 if result != 'O':
50 raise RemoteFileConnectionException("Unable to read file.")
51 read_size = self._size_struct.unpack(self._receive(4))[0]
52 return self._receive(read_size)
53
54 def _send(self, data):
55 while len(data) > 0:
56 sent = self._socket.send(data)
57 if sent == 0:
58 raise RemoteFileConnectionException("Socket connection broken.")
59 data = data[sent:]
60
61 def _receive(self, length):
62 result = []
63 while length > 0:
64 chunk = self._socket.recv(length)
65 if chunk == '':
66 raise RemoteFileConnectionException("Socket connection broken.")
67 result.append(chunk)
68 length -= len(chunk)
69 return ''.join(result)
OLDNEW
« no previous file with comments | « mojo/devtools/common/android_gdb/install_remote_file_reader.py ('k') | mojo/devtools/common/android_gdb/session.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698