Loading adb/SERVICES.TXT +1 −1 Original line number Diff line number Diff line Loading @@ -237,7 +237,7 @@ track-jdwp Note that there is no single-shot service to retrieve the list only once. sync: This starts the file synchronisation service, used to implement "adb push" This starts the file synchronization service, used to implement "adb push" and "adb pull". Since this service is pretty complex, it will be detailed in a companion document named SYNC.TXT Loading adb/SYNC.TXT +7 −10 Original line number Diff line number Diff line Loading @@ -25,12 +25,9 @@ follows as described in SERVICES.TXT. The following sync requests are accepted: LIST - List the files in a folder RECV - Retrieve a file from device SEND - Send a file to device RECV - Retreive a file from device Not yet documented: STAT - Stat a file ULNK - Unlink (remove) a file. (Not currently supported) For all of the sync request above the must be followed by length number of bytes containing an utf-8 string with a remote filename. Loading @@ -40,7 +37,7 @@ Lists files in the directory specified by the remote filename. The server will respond with zero or more directory entries or "dents". The directory entries will be returned in the following form 1. A four-byte sync response id beeing "DENT" 1. A four-byte sync response id "DENT" 2. A four-byte integer representing file mode. 3. A four-byte integer representing file size. 4. A four-byte integer representing last modified time. Loading @@ -60,13 +57,13 @@ the transfer fails. Some file types will not be deleted, which allows adb push disk_image /some_block_device to work. After this the actual file is sent in chunks. Each chucks has the following After this the actual file is sent in chunks. Each chunk has the following format. A sync request with id "DATA" and length equal to the chunk size. After follows chunk size number of bytes. This is repeated until the file is transfered. Each chunk must not be larger than 64k. transferred. Each chunk must not be larger than 64k. When the file is tranfered a sync request "DONE" is sent, where length is set When the file is transferred a sync request "DONE" is sent, where length is set to the last modified time for the file. The server responds to this last request (but not to chuck requests) with an "OKAY" sync response (length can be ignored). Loading @@ -77,8 +74,8 @@ Retrieves a file from device to a local file. The remote path is the path to the file that will be returned. Just as for the SEND sync request the file received is split up into chunks. The sync response id is "DATA" and length is the chuck size. After follows chunk size number of bytes. This is repeated until the file is transfered. Each chuck will not be larger than 64k. until the file is transferred. Each chuck will not be larger than 64k. When the file is transfered a sync resopnse "DONE" is retrieved where the When the file is transferred a sync response "DONE" is retrieved where the length can be ignored. adb/adb_client.cpp +1 −23 Original line number Diff line number Diff line Loading @@ -44,28 +44,6 @@ static const char* __adb_serial = NULL; static int __adb_server_port = DEFAULT_ADB_PORT; static const char* __adb_server_name = NULL; static std::string perror_str(const char* msg) { return android::base::StringPrintf("%s: %s", msg, strerror(errno)); } static bool ReadProtocolString(int fd, std::string* s, std::string* error) { char buf[5]; if (!ReadFdExactly(fd, buf, 4)) { *error = perror_str("protocol fault (couldn't read status length)"); return false; } buf[4] = 0; unsigned long len = strtoul(buf, 0, 16); s->resize(len, '\0'); if (!ReadFdExactly(fd, &(*s)[0], len)) { *error = perror_str("protocol fault (couldn't read status message)"); return false; } return true; } void adb_set_transport(TransportType type, const char* serial) { __adb_transport = type; Loading adb/adb_io.cpp +21 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,27 @@ bool SendProtocolString(int fd, const std::string& s) { length = 0xffff; } return WriteFdFmt(fd, "%04x", length) && WriteFdExactly(fd, s); // The cost of sending two strings outweighs the cost of formatting. // "adb sync" performance is affected by this. return WriteFdFmt(fd, "%04x%.*s", length, length, s.c_str()); } bool ReadProtocolString(int fd, std::string* s, std::string* error) { char buf[5]; if (!ReadFdExactly(fd, buf, 4)) { *error = perror_str("protocol fault (couldn't read status length)"); return false; } buf[4] = 0; unsigned long len = strtoul(buf, 0, 16); s->resize(len, '\0'); if (!ReadFdExactly(fd, &(*s)[0], len)) { *error = perror_str("protocol fault (couldn't read status message)"); return false; } return true; } bool SendOkay(int fd) { Loading adb/adb_io.h +16 −17 Original line number Diff line number Diff line Loading @@ -30,23 +30,22 @@ bool SendFail(int fd, const std::string& reason); // Writes a protocol-format string; a four hex digit length followed by the string data. bool SendProtocolString(int fd, const std::string& s); /* * Reads exactly len bytes from fd into buf. * * Returns false if there is an error or if EOF was reached before len bytes * were read. If EOF was found, errno will be set to 0. * * If this function fails, the contents of buf are undefined. */ // Reads a protocol-format string; a four hex digit length followed by the string data. bool ReadProtocolString(int fd, std::string* s, std::string* error); // Reads exactly len bytes from fd into buf. // // Returns false if there is an error or if EOF was reached before len bytes // were read. If EOF was found, errno will be set to 0. // // If this function fails, the contents of buf are undefined. bool ReadFdExactly(int fd, void* buf, size_t len); /* * Writes exactly len bytes from buf to fd. * * Returns false if there is an error or if the fd was closed before the write * completed. If the other end of the fd (such as in a socket, pipe, or fifo), * is closed, errno will be set to 0. */ // Writes exactly len bytes from buf to fd. // // Returns false if there is an error or if the fd was closed before the write // completed. If the other end of the fd (such as in a socket, pipe, or fifo), // is closed, errno will be set to 0. bool WriteFdExactly(int fd, const void* buf, size_t len); // Same as above, but for strings. Loading Loading
adb/SERVICES.TXT +1 −1 Original line number Diff line number Diff line Loading @@ -237,7 +237,7 @@ track-jdwp Note that there is no single-shot service to retrieve the list only once. sync: This starts the file synchronisation service, used to implement "adb push" This starts the file synchronization service, used to implement "adb push" and "adb pull". Since this service is pretty complex, it will be detailed in a companion document named SYNC.TXT Loading
adb/SYNC.TXT +7 −10 Original line number Diff line number Diff line Loading @@ -25,12 +25,9 @@ follows as described in SERVICES.TXT. The following sync requests are accepted: LIST - List the files in a folder RECV - Retrieve a file from device SEND - Send a file to device RECV - Retreive a file from device Not yet documented: STAT - Stat a file ULNK - Unlink (remove) a file. (Not currently supported) For all of the sync request above the must be followed by length number of bytes containing an utf-8 string with a remote filename. Loading @@ -40,7 +37,7 @@ Lists files in the directory specified by the remote filename. The server will respond with zero or more directory entries or "dents". The directory entries will be returned in the following form 1. A four-byte sync response id beeing "DENT" 1. A four-byte sync response id "DENT" 2. A four-byte integer representing file mode. 3. A four-byte integer representing file size. 4. A four-byte integer representing last modified time. Loading @@ -60,13 +57,13 @@ the transfer fails. Some file types will not be deleted, which allows adb push disk_image /some_block_device to work. After this the actual file is sent in chunks. Each chucks has the following After this the actual file is sent in chunks. Each chunk has the following format. A sync request with id "DATA" and length equal to the chunk size. After follows chunk size number of bytes. This is repeated until the file is transfered. Each chunk must not be larger than 64k. transferred. Each chunk must not be larger than 64k. When the file is tranfered a sync request "DONE" is sent, where length is set When the file is transferred a sync request "DONE" is sent, where length is set to the last modified time for the file. The server responds to this last request (but not to chuck requests) with an "OKAY" sync response (length can be ignored). Loading @@ -77,8 +74,8 @@ Retrieves a file from device to a local file. The remote path is the path to the file that will be returned. Just as for the SEND sync request the file received is split up into chunks. The sync response id is "DATA" and length is the chuck size. After follows chunk size number of bytes. This is repeated until the file is transfered. Each chuck will not be larger than 64k. until the file is transferred. Each chuck will not be larger than 64k. When the file is transfered a sync resopnse "DONE" is retrieved where the When the file is transferred a sync response "DONE" is retrieved where the length can be ignored.
adb/adb_client.cpp +1 −23 Original line number Diff line number Diff line Loading @@ -44,28 +44,6 @@ static const char* __adb_serial = NULL; static int __adb_server_port = DEFAULT_ADB_PORT; static const char* __adb_server_name = NULL; static std::string perror_str(const char* msg) { return android::base::StringPrintf("%s: %s", msg, strerror(errno)); } static bool ReadProtocolString(int fd, std::string* s, std::string* error) { char buf[5]; if (!ReadFdExactly(fd, buf, 4)) { *error = perror_str("protocol fault (couldn't read status length)"); return false; } buf[4] = 0; unsigned long len = strtoul(buf, 0, 16); s->resize(len, '\0'); if (!ReadFdExactly(fd, &(*s)[0], len)) { *error = perror_str("protocol fault (couldn't read status message)"); return false; } return true; } void adb_set_transport(TransportType type, const char* serial) { __adb_transport = type; Loading
adb/adb_io.cpp +21 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,27 @@ bool SendProtocolString(int fd, const std::string& s) { length = 0xffff; } return WriteFdFmt(fd, "%04x", length) && WriteFdExactly(fd, s); // The cost of sending two strings outweighs the cost of formatting. // "adb sync" performance is affected by this. return WriteFdFmt(fd, "%04x%.*s", length, length, s.c_str()); } bool ReadProtocolString(int fd, std::string* s, std::string* error) { char buf[5]; if (!ReadFdExactly(fd, buf, 4)) { *error = perror_str("protocol fault (couldn't read status length)"); return false; } buf[4] = 0; unsigned long len = strtoul(buf, 0, 16); s->resize(len, '\0'); if (!ReadFdExactly(fd, &(*s)[0], len)) { *error = perror_str("protocol fault (couldn't read status message)"); return false; } return true; } bool SendOkay(int fd) { Loading
adb/adb_io.h +16 −17 Original line number Diff line number Diff line Loading @@ -30,23 +30,22 @@ bool SendFail(int fd, const std::string& reason); // Writes a protocol-format string; a four hex digit length followed by the string data. bool SendProtocolString(int fd, const std::string& s); /* * Reads exactly len bytes from fd into buf. * * Returns false if there is an error or if EOF was reached before len bytes * were read. If EOF was found, errno will be set to 0. * * If this function fails, the contents of buf are undefined. */ // Reads a protocol-format string; a four hex digit length followed by the string data. bool ReadProtocolString(int fd, std::string* s, std::string* error); // Reads exactly len bytes from fd into buf. // // Returns false if there is an error or if EOF was reached before len bytes // were read. If EOF was found, errno will be set to 0. // // If this function fails, the contents of buf are undefined. bool ReadFdExactly(int fd, void* buf, size_t len); /* * Writes exactly len bytes from buf to fd. * * Returns false if there is an error or if the fd was closed before the write * completed. If the other end of the fd (such as in a socket, pipe, or fifo), * is closed, errno will be set to 0. */ // Writes exactly len bytes from buf to fd. // // Returns false if there is an error or if the fd was closed before the write // completed. If the other end of the fd (such as in a socket, pipe, or fifo), // is closed, errno will be set to 0. bool WriteFdExactly(int fd, const void* buf, size_t len); // Same as above, but for strings. Loading