summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2011-08-03 10:50:58 -0700
committerAndroid Code Review <code-review@android.com>2011-08-03 10:50:58 -0700
commitda51d1ca145b8cc82588d97ea33e81d6a0cda408 (patch)
tree82fe4a703c2597dbe889fa864fdb14829829bff8
parent61659b21b512a4d1e26a1843738e0486a68be36b (diff)
parent08ab51b65c0dd868b5024220c11b69f433668b64 (diff)
downloadlibhardware-da51d1ca145b8cc82588d97ea33e81d6a0cda408.tar.gz
Merge "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 */