Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
am d9f2f74: am da51d1c: Merge "Inline implementation of qemu_pipe_open"
Browse files Browse the repository at this point in the history
* commit 'd9f2f74e1939eb268ec557171149375f220628d2':
  Inline implementation of qemu_pipe_open
  • Loading branch information
Vladimir Chtchetkine authored and Android Git Automerger committed Aug 4, 2011
2 parents ed9928c + d9f2f74 commit 7c7a294
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions include/hardware/qemu_pipe.h
Expand Up @@ -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
Expand All @@ -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 */

0 comments on commit 7c7a294

Please sign in to comment.