From 18b49ab914ea5a57f22ed6d77520cd7d4372749b Mon Sep 17 00:00:00 2001
From: ctiller <ctiller@google.com>
Date: Tue, 9 Dec 2014 14:39:16 -0800
Subject: 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
---
 test/core/end2end/fixtures/chttp2_fake_security.c  |  5 ---
 test/core/end2end/fixtures/chttp2_fullstack.c      |  2 -
 .../end2end/fixtures/chttp2_simple_ssl_fullstack.c |  5 ---
 .../chttp2_simple_ssl_with_oauth2_fullstack.c      |  6 +--
 test/core/end2end/fixtures/chttp2_socket_pair.c    | 43 +++++-----------------
 .../chttp2_socket_pair_one_byte_at_a_time.c        | 43 +++++-----------------
 6 files changed, 19 insertions(+), 85 deletions(-)

(limited to 'test/core/end2end/fixtures')

diff --git a/test/core/end2end/fixtures/chttp2_fake_security.c b/test/core/end2end/fixtures/chttp2_fake_security.c
index aaca56336f..ff249ce7aa 100644
--- a/test/core/end2end/fixtures/chttp2_fake_security.c
+++ b/test/core/end2end/fixtures/chttp2_fake_security.c
@@ -37,7 +37,6 @@
 #include <string.h>
 
 #include "src/core/channel/channel_args.h"
-#include "src/core/eventmanager/em.h"
 #include "src/core/security/credentials.h"
 #include "src/core/security/security_context.h"
 #include <grpc/support/alloc.h>
@@ -47,8 +46,6 @@
 #include "test/core/util/port.h"
 #include "test/core/end2end/data/ssl_test_data.h"
 
-static grpc_em em;
-
 typedef struct fullstack_secure_fixture_data {
   char *localaddr;
 } fullstack_secure_fixture_data;
@@ -124,13 +121,11 @@ int main(int argc, char **argv) {
   grpc_test_init(argc, argv);
 
   grpc_init();
-  grpc_em_init(&em);
 
   for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
     grpc_end2end_tests(configs[i]);
   }
 
-  GPR_ASSERT(grpc_em_destroy(&em) == GRPC_EM_OK);
   grpc_shutdown();
 
   return 0;
diff --git a/test/core/end2end/fixtures/chttp2_fullstack.c b/test/core/end2end/fixtures/chttp2_fullstack.c
index da75d61e66..169032f6ba 100644
--- a/test/core/end2end/fixtures/chttp2_fullstack.c
+++ b/test/core/end2end/fixtures/chttp2_fullstack.c
@@ -46,11 +46,9 @@
 #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/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/host_port.h>
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
index 57c9141d95..7b0adb2e8c 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
@@ -37,7 +37,6 @@
 #include <string.h>
 
 #include "src/core/channel/channel_args.h"
-#include "src/core/eventmanager/em.h"
 #include "src/core/security/credentials.h"
 #include "src/core/security/security_context.h"
 #include <grpc/support/alloc.h>
@@ -47,8 +46,6 @@
 #include "test/core/util/port.h"
 #include "test/core/end2end/data/ssl_test_data.h"
 
-static grpc_em em;
-
 typedef struct fullstack_secure_fixture_data {
   char *localaddr;
 } fullstack_secure_fixture_data;
@@ -131,13 +128,11 @@ int main(int argc, char **argv) {
   grpc_test_init(argc, argv);
 
   grpc_init();
-  grpc_em_init(&em);
 
   for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
     grpc_end2end_tests(configs[i]);
   }
 
-  GPR_ASSERT(grpc_em_destroy(&em) == GRPC_EM_OK);
   grpc_shutdown();
 
   return 0;
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c b/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
index 8d5585312a..04a8795b38 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
+++ b/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
@@ -37,7 +37,7 @@
 #include <string.h>
 
 #include "src/core/channel/channel_args.h"
-#include "src/core/eventmanager/em.h"
+#include "src/core/iomgr/iomgr.h"
 #include "src/core/security/credentials.h"
 #include "src/core/security/security_context.h"
 #include <grpc/support/alloc.h>
@@ -47,8 +47,6 @@
 #include "test/core/util/port.h"
 #include "test/core/end2end/data/ssl_test_data.h"
 
-static grpc_em em;
-
 typedef struct fullstack_secure_fixture_data {
   char *localaddr;
 } fullstack_secure_fixture_data;
@@ -138,13 +136,11 @@ int main(int argc, char **argv) {
   grpc_test_init(argc, argv);
 
   grpc_init();
-  grpc_em_init(&em);
 
   for (i = 0; i < sizeof(configs) / sizeof(*configs); i++) {
     grpc_end2end_tests(configs[i]);
   }
 
-  GPR_ASSERT(grpc_em_destroy(&em) == GRPC_EM_OK);
   grpc_shutdown();
 
   return 0;
diff --git a/test/core/end2end/fixtures/chttp2_socket_pair.c b/test/core/end2end/fixtures/chttp2_socket_pair.c
index 593ff78ba8..7ec17e3cc5 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 @@ static grpc_transport_setup_result client_setup_transport(
       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 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
   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) {
diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c
index 9287364c48..3e18de9b91 100644
--- a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c
+++ b/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.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 @@ static grpc_transport_setup_result client_setup_transport(
       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 @@ static grpc_end2end_test_fixture chttp2_create_fixture_socketpair(
   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(1);
 
   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(), 1);
   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(), 1);
-  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) {
-- 
cgit v1.2.3