diff options
author | Selim Gurun <sgurun@google.com> | 2012-02-27 16:04:37 -0800 |
---|---|---|
committer | Selim Gurun <sgurun@google.com> | 2012-03-07 16:19:52 -0800 |
commit | 7bf4c45f842ded6d6ad6b2d80e052ddf56969723 (patch) | |
tree | 4c5d19db79c7a141062dd81288be0209f8079924 /include/sysutils/SocketClient.h | |
parent | 78f6bcf853db3dd9b9b37a0ca4d4ee0374f6835a (diff) | |
download | core-7bf4c45f842ded6d6ad6b2d80e052ddf56969723.tar.gz core-7bf4c45f842ded6d6ad6b2d80e052ddf56969723.tar.bz2 core-7bf4c45f842ded6d6ad6b2d80e052ddf56969723.zip |
Add a utility function to send a code + binary msg
Add a utility function to SocketClient to send a c-string code
prepended to a binary message. This is necessary to be able to
send a binary message while keeping compatible with underlying
text-based protocol.
Change-Id: Ifc6562003a687577d7deb50260533a5147ae4f97
Diffstat (limited to 'include/sysutils/SocketClient.h')
-rw-r--r-- | include/sysutils/SocketClient.h | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h index 65a5b1b67..a298f25e4 100644 --- a/include/sysutils/SocketClient.h +++ b/include/sysutils/SocketClient.h @@ -45,7 +45,18 @@ public: int sendMsg(int code, const char *msg, bool addErrno); int sendMsg(int code, const char *msg, bool addErrno, bool useCmdNum); - //Sending binary data: + // Provides a mechanism to send a response code to the client. The message uses + // the same format as in sendMsg method above. + // Sends the code, a space, and a null character. + int sendCode(int code); + + // Provides a mechanism to send binary data to client. The message uses the + // same format as in sendMsg method above. + // Sends the code, a space, and a null character, followed by 4 bytes of + // big-endian length, and the data. + int sendBinaryMsg(int code, const void *data, int len); + + // Sending binary data: int sendData(const void *data, int len); // Optional reference counting. Reference count starts at 1. If @@ -59,6 +70,12 @@ private: // Send null-terminated C strings int sendMsg(const char *msg); void init(int socket, bool owned, bool useCmdNum); + + // Sending binary data. The caller should use make sure this is protected + // from multiple threads entering simultaneously. + // returns 0 if successful, -1 if there is a 0 byte write and -2 if any other + // error occurred (use errno to get the error) + int sendDataLocked(const void *data, int len); }; typedef android::sysutils::List<SocketClient *> SocketClientCollection; |