diff options
author | ctiller <ctiller@google.com> | 2015-01-07 14:03:30 -0800 |
---|---|---|
committer | Tim Emiola <temiola@google.com> | 2015-01-08 13:01:56 -0800 |
commit | 1a277ecd93e908a47a905d323a4a1a77287cede1 (patch) | |
tree | d1648196ca8201d778e73c7c9e59a8ac90613763 /src/core/security | |
parent | 3040cb7c434e83c0e70839ac20218f1c2d77e1eb (diff) |
Remove libevent.
Fixed any exposed bugs across the stack.
Add a poll() based implementation. Heavily leverages pollset infrastructure to allow small polls to be the norm. Exposes a mechanism to plug in epoll/kqueue for platforms where we have them.
Simplify iomgr callbacks to return one bit of success or failure (instead of the multi valued result that was mostly unused previously). This will ease the burden on new implementations, and the previous system provided no real value anyway.
Removed timeouts on endpoint read/write routines. This simplifies porting burden by providing a more orthogonal interface, and the functionality can always be replicated when desired by using an alarm combined with endpoint_shutdown. I'm fairly certain we ended up with this interface because it was convenient to do from libevent.
Things that need attention still:
- adding an fd to a pollset is O(n^2) - but this is probably ok given that we'll not
use this for multipolling once platform specific implementations are added.
- we rely on the backup poller too often - especially for SSL handshakes and for client
connection establishment we should have a better mechanism ([] []
- Linux needs to use epoll for multiple fds, FreeBSD variants (including
Darwin) need to use kqueue. ([] []
- Linux needs to use eventfd for poll kicking. ([]
Change on 2015/01/07 by ctiller <ctiller@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83461069
Diffstat (limited to 'src/core/security')
-rw-r--r-- | src/core/security/credentials.c | 5 | ||||
-rw-r--r-- | src/core/security/secure_endpoint.c | 15 | ||||
-rw-r--r-- | src/core/security/secure_transport_setup.c | 12 | ||||
-rw-r--r-- | src/core/security/server_secure_chttp2.c | 4 |
4 files changed, 17 insertions, 19 deletions
diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index 442d2fa624..c99ac8021d 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -555,12 +555,11 @@ static int fake_oauth2_has_request_metadata_only( return 1; } -void on_simulated_token_fetch_done(void *user_data, - grpc_iomgr_cb_status status) { +void on_simulated_token_fetch_done(void *user_data, int success) { grpc_credentials_metadata_request *r = (grpc_credentials_metadata_request *)user_data; grpc_fake_oauth2_credentials *c = (grpc_fake_oauth2_credentials *)r->creds; - GPR_ASSERT(status == GRPC_CALLBACK_SUCCESS); + GPR_ASSERT(success); r->cb(r->user_data, &c->access_token_md, 1, GRPC_CREDENTIALS_OK); grpc_credentials_metadata_request_destroy(r); } diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c index cab09ca49d..7f0fdf73c9 100644 --- a/src/core/security/secure_endpoint.c +++ b/src/core/security/secure_endpoint.c @@ -184,8 +184,7 @@ static void on_read(void *user_data, gpr_slice *slices, size_t nslices, } static void endpoint_notify_on_read(grpc_endpoint *secure_ep, - grpc_endpoint_read_cb cb, void *user_data, - gpr_timespec deadline) { + grpc_endpoint_read_cb cb, void *user_data) { secure_endpoint *ep = (secure_endpoint *)secure_ep; ep->read_cb = cb; ep->read_user_data = user_data; @@ -200,7 +199,7 @@ static void endpoint_notify_on_read(grpc_endpoint *secure_ep, return; } - grpc_endpoint_notify_on_read(ep->wrapped_ep, on_read, ep, deadline); + grpc_endpoint_notify_on_read(ep->wrapped_ep, on_read, ep); } static void flush_write_staging_buffer(secure_endpoint *ep, gpr_uint8 **cur, @@ -217,9 +216,11 @@ static void on_write(void *data, grpc_endpoint_cb_status error) { secure_endpoint_unref(ep); } -static grpc_endpoint_write_status endpoint_write( - grpc_endpoint *secure_ep, gpr_slice *slices, size_t nslices, - grpc_endpoint_write_cb cb, void *user_data, gpr_timespec deadline) { +static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep, + gpr_slice *slices, + size_t nslices, + grpc_endpoint_write_cb cb, + void *user_data) { int i = 0; int output_buffer_count = 0; tsi_result result = TSI_OK; @@ -308,7 +309,7 @@ static grpc_endpoint_write_status endpoint_write( /* Need to keep the endpoint alive across a transport */ secure_endpoint_ref(ep); status = grpc_endpoint_write(ep->wrapped_ep, ep->output_buffer.slices, - output_buffer_count, on_write, ep, deadline); + output_buffer_count, on_write, ep); if (status != GRPC_ENDPOINT_WRITE_PENDING) { secure_endpoint_unref(ep); } diff --git a/src/core/security/secure_transport_setup.c b/src/core/security/secure_transport_setup.c index eb11251912..3df91ed8e7 100644 --- a/src/core/security/secure_transport_setup.c +++ b/src/core/security/secure_transport_setup.c @@ -105,6 +105,7 @@ static void check_peer(grpc_secure_transport_setup *s) { grpc_security_status peer_status; tsi_peer peer; tsi_result result = tsi_handshaker_extract_peer(s->handshaker, &peer); + if (result != TSI_OK) { gpr_log(GPR_ERROR, "Peer extraction failed with error %s", tsi_result_to_string(result)); @@ -152,9 +153,8 @@ static void send_handshake_bytes_to_peer(grpc_secure_transport_setup *s) { gpr_slice_from_copied_buffer((const char *)s->handshake_buffer, offset); /* TODO(klempner,jboeuf): This should probably use the client setup deadline */ - write_status = - grpc_endpoint_write(s->endpoint, &to_send, 1, - on_handshake_data_sent_to_peer, s, gpr_inf_future); + write_status = grpc_endpoint_write(s->endpoint, &to_send, 1, + on_handshake_data_sent_to_peer, s); if (write_status == GRPC_ENDPOINT_WRITE_ERROR) { gpr_log(GPR_ERROR, "Could not send handshake data to peer."); secure_transport_setup_done(s, 0); @@ -200,8 +200,7 @@ static void on_handshake_data_received_from_peer( /* TODO(klempner,jboeuf): This should probably use the client setup deadline */ grpc_endpoint_notify_on_read(s->endpoint, - on_handshake_data_received_from_peer, setup, - gpr_inf_future); + on_handshake_data_received_from_peer, setup); cleanup_slices(slices, nslices); return; } else { @@ -258,8 +257,7 @@ static void on_handshake_data_sent_to_peer(void *setup, /* TODO(klempner,jboeuf): This should probably use the client setup deadline */ grpc_endpoint_notify_on_read(s->endpoint, - on_handshake_data_received_from_peer, setup, - gpr_inf_future); + on_handshake_data_received_from_peer, setup); } else { check_peer(s); } diff --git a/src/core/security/server_secure_chttp2.c b/src/core/security/server_secure_chttp2.c index 28b56dd4c9..9d7c0e5e5a 100644 --- a/src/core/security/server_secure_chttp2.c +++ b/src/core/security/server_secure_chttp2.c @@ -77,9 +77,9 @@ static void on_accept(void *server, grpc_endpoint *tcp) { /* Note: the following code is the same with server_chttp2.c */ /* Server callback: start listening on our ports */ -static void start(grpc_server *server, void *tcpp) { +static void start(grpc_server *server, void *tcpp, grpc_pollset *pollset) { grpc_tcp_server *tcp = tcpp; - grpc_tcp_server_start(tcp, on_accept, server); + grpc_tcp_server_start(tcp, pollset, on_accept, server); } /* Server callback: destroy the tcp listener (so we don't generate further |