diff options
author | David 'Digit' Turner <digit@android.com> | 2011-04-14 14:13:44 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@android.com> | 2011-04-14 14:13:44 +0200 |
commit | 9bdeb24279a840dc75379b76828e6904f7edcd79 (patch) | |
tree | 0e07fca5dc5b39ee5e4a45d98118964dcb7cae76 /emulator/tests/test-qemud-pipes.c | |
parent | 58f6f27bacf15d066e5f453f40c8a9630119ba63 (diff) | |
download | sdk-9bdeb24279a840dc75379b76828e6904f7edcd79.zip sdk-9bdeb24279a840dc75379b76828e6904f7edcd79.tar.gz sdk-9bdeb24279a840dc75379b76828e6904f7edcd79.tar.bz2 |
Revert 183675b74e5a58211e5d9a90a9ca86546ed3e245
Unfortunately, we need to keep the duplicate libraries here to prevent
breaking a few internal branches for now.
Remove obsolete emulator modules
The corresponding modules have all been moved to development/tools/emulator/system/
already. Note that we use a global variable Make trick to prevent the same module
from being built twice, so removing these files doesn't break the builds.
Another patch should remove the global variable Make trick from
development/tools/emulator/system after this patch.
Change-Id: I97332216b311608de61919cb75f4b760b249c0d9
Diffstat (limited to 'emulator/tests/test-qemud-pipes.c')
-rw-r--r-- | emulator/tests/test-qemud-pipes.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/emulator/tests/test-qemud-pipes.c b/emulator/tests/test-qemud-pipes.c new file mode 100644 index 0000000..f5db531 --- /dev/null +++ b/emulator/tests/test-qemud-pipes.c @@ -0,0 +1,113 @@ +/* This program is used to test the QEMUD fast pipes. + * See external/qemu/docs/ANDROID-QEMUD-PIPES.TXT for details. + * + * The program acts as a simple TCP server that accepts data and sends + * them back to the client. + */ + +#include <sys/socket.h> +#include <net/inet.h> +#include <stdio.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> + +#define DEFAULT_PORT 8012 + +static void +socket_close(int sock) +{ + int old_errno = errno; + close(sock); + errno = old_errno; +} + +static int +socket_loopback_server( int port, int type ) +{ + struct sockaddr_in addr; + + int sock = socket(AF_INET, type, 0); + if (sock < 0) { + return -1; + } + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + + int n = 1; + setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)); + + if (TEMP_FAILURE_RETRY(bind(sock, &addr, sizeof(addr))) < 0) { + socket_close(sock); + return -1; + } + + if (type == SOCK_STREAM) { + if (TEMP_FAILURE_RETRY(listen(sock, 4)) < 0) { + socket_close(sock); + return -1; + } + } + + return sock; +} + +int main(void) +{ + int sock, client; + int port = DEFAULT_PORT; + + printf("Starting pipe test server on local port %d\n", port); + sock = socket_loopback_server( port, SOCK_STREAM ); + if (sock < 0) { + fprintf(stderr, "Could not start server: %s\n", strerror(errno)); + return 1; + } + + client = accept(sock, NULL, NULL); + if (client < 0) { + fprintf(stderr, "Server error: %s\n", strerror(errno)); + return 2; + } + printf("Client connected!\n"); + + /* Now, accept any incoming data, and send it back */ + for (;;) { + char buff[1024], *p; + int ret, count; + + do { + ret = read(client, buff, sizeof(buff)); + } while (ret < 0 && errno == EINTR); + + if (ret < 0) { + fprintf(stderr, "Client read error: %s\n", strerror(errno)); + close(client); + return 3; + } + count = ret; + p = buff; + printf(" received: %d bytes\n", count); + + while (count > 0) { + do { + ret = write(client, p, count); + } while (ret < 0 && errno == EINTR); + + if (ret < 0) { + fprintf(stderr, "Client write error: %s\n", strerror(errno)); + close(client); + return 4; + } + printf(" sent: %d bytes\n", ret); + + p += ret; + count -= ret; + } + } + + return 0; +} |