Introducing iomgr.
Move eventmanager and platform dependent endpoint functionality into a single
library called 'iomgr'.
This is primarily to prepare for a Windows port - where posix socket semantics
lead to poor quality code.
Mostly this is a code movement CL, with some small changes to help prepare the
way for porting:
- em style fd objects can only be held internally in iomgr, and own their memory
- added grpc_iomgr_create_endpoint_pair() to accomodate the common pattern of
creating a tcp endpoint from the output of socketpair - this will help keep
our tests portable
- separated em alarm interface into a separate file, as this part of event
manager is needed higher up the stack
- made the eventmanager bits a true singleton, simplifying API's across the
stack as there's no longer a reason to carry a pointer there.
Initial design document is here:
https://docs.google.com/document/d/1VmafcHvvrP5kwtQkz84R5yXF7u7fW-9Pn0bkSUQHDt8/edit?disco=AAAAARNByxg
Change on 2014/12/09 by ctiller <ctiller@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81716456
diff --git a/test/core/end2end/fixtures/chttp2_socket_pair.c b/test/core/end2end/fixtures/chttp2_socket_pair.c
index 593ff78..7ec17e3 100644
--- a/test/core/end2end/fixtures/chttp2_socket_pair.c
+++ b/test/core/end2end/fixtures/chttp2_socket_pair.c
@@ -32,25 +32,15 @@
*/
#include "test/core/end2end/end2end_tests.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
#include "src/core/channel/client_channel.h"
#include "src/core/channel/connected_channel.h"
#include "src/core/channel/http_filter.h"
#include "src/core/channel/http_server_filter.h"
-#include "src/core/eventmanager/em.h"
+#include "src/core/iomgr/endpoint_pair.h"
+#include "src/core/iomgr/iomgr.h"
#include "src/core/surface/channel.h"
#include "src/core/surface/client.h"
#include "src/core/surface/server.h"
-#include "src/core/surface/surface_em.h"
#include "src/core/transport/chttp2_transport.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@@ -60,15 +50,6 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
-static void create_sockets(int sv[2]) {
- int flags;
- GPR_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);
- flags = fcntl(sv[0], F_GETFL, 0);
- GPR_ASSERT(fcntl(sv[0], F_SETFL, flags | O_NONBLOCK) == 0);
- flags = fcntl(sv[1], F_GETFL, 0);
- GPR_ASSERT(fcntl(sv[1], F_SETFL, flags | O_NONBLOCK) == 0);
-}
-
/* chttp2 transport that is immediately available (used for testing
connected_channel without a client_channel */
@@ -102,11 +83,9 @@
grpc_channel_get_channel_stack(channel), transport);
}
-typedef struct socketpair_fixture_data { int sv[2]; } socketpair_fixture_data;
-
static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
grpc_channel_args *client_args, grpc_channel_args *server_args) {
- socketpair_fixture_data *sfd = gpr_malloc(sizeof(socketpair_fixture_data));
+ grpc_endpoint_pair *sfd = gpr_malloc(sizeof(grpc_endpoint_pair));
grpc_end2end_test_fixture f;
f.fixture_data = sfd;
@@ -115,31 +94,27 @@
f.server = grpc_server_create_from_filters(f.server_cq, NULL, 0, server_args);
f.client = NULL;
- create_sockets(sfd->sv);
+ *sfd = grpc_iomgr_create_endpoint_pair(65536);
return f;
}
static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args) {
- socketpair_fixture_data *sfd = f->fixture_data;
- grpc_endpoint *cli_tcp;
+ grpc_endpoint_pair *sfd = f->fixture_data;
sp_client_setup cs;
cs.client_args = client_args;
cs.f = f;
- cli_tcp = grpc_tcp_create_dbg(sfd->sv[0], grpc_surface_em(), 65536);
grpc_create_chttp2_transport(client_setup_transport, &cs, client_args,
- cli_tcp, NULL, 0, grpc_mdctx_create(), 1);
+ sfd->client, NULL, 0, grpc_mdctx_create(), 1);
GPR_ASSERT(f->client);
}
static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
grpc_channel_args *server_args) {
- socketpair_fixture_data *sfd = f->fixture_data;
- grpc_endpoint *svr_tcp;
- svr_tcp = grpc_tcp_create_dbg(sfd->sv[1], grpc_surface_em(), 65536);
- grpc_create_chttp2_transport(server_setup_transport, f, server_args, svr_tcp,
- NULL, 0, grpc_mdctx_create(), 0);
+ grpc_endpoint_pair *sfd = f->fixture_data;
+ grpc_create_chttp2_transport(server_setup_transport, f, server_args,
+ sfd->server, NULL, 0, grpc_mdctx_create(), 0);
}
static void chttp2_tear_down_socketpair(grpc_end2end_test_fixture *f) {