summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2011-08-03 18:16:35 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-08-03 18:16:35 -0700
commit7c7a29401f0773cc995a142ce89f31eda1bf041d (patch)
treea64e7222d0b0796375562e1fb175f345573578a2
parented9928c76d107d02452a25a0d62803197c47f673 (diff)
parentd9f2f74e1939eb268ec557171149375f220628d2 (diff)
downloadlibhardware-7c7a29401f0773cc995a142ce89f31eda1bf041d.tar.gz
am d9f2f74e: am da51d1ca: Merge "Inline implementation of qemu_pipe_open"
* commit 'd9f2f74e1939eb268ec557171149375f220628d2': Inline implementation of qemu_pipe_open
-rw-r--r--include/hardware/qemu_pipe.h49
1 files changed, 46 insertions, 3 deletions
diff --git a/include/hardware/qemu_pipe.h b/include/hardware/qemu_pipe.h
index fb0bf2f8..570af705 100644
--- a/include/hardware/qemu_pipe.h
+++ b/include/hardware/qemu_pipe.h
@@ -17,8 +17,18 @@
#define ANDROID_INCLUDE_HARDWARE_QEMU_PIPE_H
#include <sys/cdefs.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <hardware/qemud.h>
+#include <hardware/qemu_pipe.h>
+#include <pthread.h> /* for pthread_once() */
+#include <stdlib.h>
+#include <stdio.h>
-__BEGIN_DECLS
+#ifndef D
+# define D(...) do{}while(0)
+#endif
/* Try to open a new Qemu fast-pipe. This function returns a file descriptor
* that can be used to communicate with a named service managed by the
@@ -42,8 +52,41 @@ __BEGIN_DECLS
* except for a few special cases (e.g. GSM modem), where EBUSY will be
* returned if more than one client tries to connect to it.
*/
-extern int qemu_pipe_open(const char* pipeName);
+static __inline__ int
+qemu_pipe_open(const char* pipeName)
+{
+ char buff[256];
+ int buffLen;
+ int fd, ret;
-__END_DECLS
+ if (pipeName == NULL || pipeName[0] == '\0') {
+ errno = EINVAL;
+ return -1;
+ }
+
+ snprintf(buff, sizeof buff, "pipe:%s", pipeName);
+
+ fd = open("/dev/qemu_pipe", O_RDWR);
+ if (fd < 0) {
+ D("%s: Could not open /dev/qemu_pipe: %s", __FUNCTION__, strerror(errno));
+ errno = ENOSYS;
+ return -1;
+ }
+
+ buffLen = strlen(buff);
+
+ ret = TEMP_FAILURE_RETRY(write(fd, buff, buffLen+1));
+ if (ret != buffLen+1) {
+ D("%s: Could not connect to %s pipe service: %s", __FUNCTION__, pipeName, strerror(errno));
+ if (ret == 0) {
+ errno = ECONNRESET;
+ } else if (ret > 0) {
+ errno = EINVAL;
+ }
+ return -1;
+ }
+
+ return fd;
+}
#endif /* ANDROID_INCLUDE_HARDWARE_QEMUD_PIPE_H */