diff options
author | Josh Gao <jmgao@google.com> | 2019-04-18 16:39:30 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2019-04-24 12:59:42 -0700 |
commit | 6bc77009177ba2de4c25a2c8f17bee826c0540a3 (patch) | |
tree | 97b63d6b7c86394ab0a1dc40eedca8f7ce305378 /adb_io.h | |
parent | 4c0c9c90e1ae4fb8ef7312833a825bc3c3bee62b (diff) | |
download | adb-6bc77009177ba2de4c25a2c8f17bee826c0540a3.tar.gz |
Add a way to turn off unique_fd's operator int.
unique_fd's implicit conversion to int has led to tons of problems (see
all of the overloads for close, fdopen, fdopendir, etc.). Add a switch
that can turn it off, and reduce the ridiculous amount of work to fix up
callers by introducing a borrowed_fd type that can be constructed from
either int or unique_fd.
Test: treehugger
Change-Id: If77cf5cbcaddacdaec5919a15b3520fb68f51a62
Diffstat (limited to 'adb_io.h')
-rw-r--r-- | adb_io.h | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -25,16 +25,16 @@ #include "adb_unique_fd.h" // Sends the protocol "OKAY" message. -bool SendOkay(int fd); +bool SendOkay(borrowed_fd fd); // Sends the protocol "FAIL" message, with the given failure reason. -bool SendFail(int fd, std::string_view reason); +bool SendFail(borrowed_fd fd, std::string_view reason); // Writes a protocol-format string; a four hex digit length followed by the string data. -bool SendProtocolString(int fd, std::string_view s); +bool SendProtocolString(borrowed_fd fd, std::string_view s); // 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); +bool ReadProtocolString(borrowed_fd fd, std::string* s, std::string* error); // Reads exactly len bytes from fd into buf. // @@ -42,7 +42,7 @@ bool ReadProtocolString(int fd, std::string* s, std::string* error); // 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); +bool ReadFdExactly(borrowed_fd fd, void* buf, size_t len); // Given a client socket, wait for orderly/graceful shutdown. Call this: // @@ -60,19 +60,19 @@ bool ReadFdExactly(int fd, void* buf, size_t len); // connect()s from the client to fail with WSAEADDRINUSE on Windows. // Returns true if it is sure that orderly/graceful shutdown has occurred with // no additional data read from the server. -bool ReadOrderlyShutdown(int fd); +bool ReadOrderlyShutdown(borrowed_fd fd); // 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); +bool WriteFdExactly(borrowed_fd fd, const void* buf, size_t len); // Same as above, but for strings. -bool WriteFdExactly(int fd, const char* s); -bool WriteFdExactly(int fd, const std::string& s); +bool WriteFdExactly(borrowed_fd fd, const char* s); +bool WriteFdExactly(borrowed_fd fd, const std::string& s); // Same as above, but formats the string to send. -bool WriteFdFmt(int fd, const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))); +bool WriteFdFmt(borrowed_fd fd, const char* fmt, ...) __attribute__((__format__(__printf__, 2, 3))); #endif /* ADB_IO_H */ |