machinarium: add readahead test
*/
#include <machinarium.h>
-#include <uv.h>
+#include <machinarium_private.h>
#include <string.h>
#include <assert.h>
@@ -19,36 +19,43 @@ server(void *arg)
machine_io_t server = machine_create_io(machine);
struct sockaddr_in sa;
- uv_ip4_addr("127.0.0.1", 7778, &sa);
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = inet_addr("127.0.0.1");
+ sa.sin_port = htons(7778);
int rc;
rc = machine_bind(server, (struct sockaddr*)&sa);
if (rc < 0) {
- printf("server: bind failed\n");
+ printf("server: bind failed: %s\n", machine_error(server));
machine_close(server);
+ machine_free_io(server);
return;
}
printf("server: waiting for connections (127.0.0.1:7778)\n");
machine_io_t client;
- rc = machine_accept(server, 16, &client);
+ rc = machine_accept(server, &client, 16, 0);
if (rc < 0) {
- printf("accept error.\n");
+ printf("accept error: %s\n", machine_error(server));
machine_close(server);
+ machine_free_io(server);
return;
}
char msg[] = "hello world" "HELLO WORLD" "a" "b" "c" "333";
rc = machine_write(client, msg, sizeof(msg), 0);
if (rc < 0) {
- printf("server: write error.\n");
+ printf("server: write error: %s\n", machine_error(client));
machine_close(client);
+ machine_free_io(client);
machine_close(server);
+ machine_free_io(server);
return;
}
-
machine_close(client);
+ machine_free_io(client);
machine_close(server);
+ machine_free_io(server);
printf("server: done\n");
}
@@ -61,7 +68,9 @@ client(void *arg)
machine_io_t client = machine_create_io(machine);
struct sockaddr_in sa;
- uv_ip4_addr("127.0.0.1", 7778, &sa);
+ sa.sin_family = AF_INET;
+ sa.sin_addr.s_addr = inet_addr("127.0.0.1");
+ sa.sin_port = htons(7778);
int rc;
rc = machine_connect(client, (struct sockaddr*)&sa, 0);
@@ -105,17 +114,17 @@ client(void *arg)
buf = machine_read_buf(client);
assert(*buf == 'c');
- rc = machine_read(client, NULL, 3, 0);
+ rc = machine_read(client, NULL, 4, 0);
assert(rc == 0);
buf = machine_read_buf(client);
- assert(memcmp(buf, "333", 3) == 0);
+ assert(memcmp(buf, "333", 4) == 0);
/* eof */
rc = machine_read(client, NULL, 1, 0);
- if (rc < 0) {
- }
+ assert(rc == 1);
machine_close(client);
+ machine_free_io(client);
printf("client: done\n");
machine_stop(machine);
