#ifdef GRPC_WINSOCK_SOCKET
-#include "src/core/lib/iomgr/sockaddr.h"
-
#include <inttypes.h>
#include <io.h>
+#include <vector>
+
+#include "absl/strings/str_cat.h"
+
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/log_windows.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
+#include "src/core/lib/address_utils/sockaddr_utils.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/iocp_windows.h"
#include "src/core/lib/iomgr/pollset_windows.h"
#include "src/core/lib/iomgr/resolve_address.h"
-#include "src/core/lib/iomgr/sockaddr_utils.h"
+#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/socket_windows.h"
#include "src/core/lib/iomgr/tcp_server.h"
#include "src/core/lib/iomgr/tcp_windows.h"
+#include "src/core/lib/slice/slice_internal.h"
#define MIN_SAFE_ACCEPT_QUEUE_SIZE 100
grpc_closure* shutdown_complete;
grpc_channel_args* channel_args;
+ grpc_slice_allocator_factory* slice_allocator_factory;
};
/* Public function. Allocates the proper data structures to hold a
grpc_tcp_server. */
-static grpc_error* tcp_server_create(grpc_closure* shutdown_complete,
- const grpc_channel_args* args,
- grpc_tcp_server** server) {
+static grpc_error_handle tcp_server_create(
+ grpc_closure* shutdown_complete, const grpc_channel_args* args,
+ grpc_slice_allocator_factory* slice_allocator_factory,
+ grpc_tcp_server** server) {
grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server));
s->channel_args = grpc_channel_args_copy(args);
gpr_ref_init(&s->refs, 1);
s->shutdown_starting.head = NULL;
s->shutdown_starting.tail = NULL;
s->shutdown_complete = shutdown_complete;
+ s->slice_allocator_factory = slice_allocator_factory;
*server = s;
return GRPC_ERROR_NONE;
}
-static void destroy_server(void* arg, grpc_error* error) {
+static void destroy_server(void* arg, grpc_error_handle error) {
grpc_tcp_server* s = (grpc_tcp_server*)arg;
/* Now that the accepts have been aborted, we can destroy the sockets.
static void finish_shutdown_locked(grpc_tcp_server* s) {
if (s->shutdown_complete != NULL) {
- GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE);
+ grpc_core::ExecCtx::Run(DEBUG_LOCATION, s->shutdown_complete,
+ GRPC_ERROR_NONE);
}
- GRPC_CLOSURE_SCHED(
+ grpc_core::ExecCtx::Run(
+ DEBUG_LOCATION,
GRPC_CLOSURE_CREATE(destroy_server, s, grpc_schedule_on_exec_ctx),
GRPC_ERROR_NONE);
}
static void tcp_server_destroy(grpc_tcp_server* s) {
grpc_tcp_listener* sp;
gpr_mu_lock(&s->mu);
-
+ grpc_slice_allocator_factory_destroy(s->slice_allocator_factory);
/* First, shutdown all fd's. This will queue abortion calls for all
of the pending accepts due to the normal operation mechanism. */
if (s->active_ports == 0) {
if (gpr_unref(&s->refs)) {
grpc_tcp_server_shutdown_listeners(s);
gpr_mu_lock(&s->mu);
- GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting);
+ grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &s->shutdown_starting);
gpr_mu_unlock(&s->mu);
tcp_server_destroy(s);
}
}
/* Prepare (bind) a recently-created socket for listening. */
-static grpc_error* prepare_socket(SOCKET sock,
- const grpc_resolved_address* addr,
- int* port) {
+static grpc_error_handle prepare_socket(SOCKET sock,
+ const grpc_resolved_address* addr,
+ int* port) {
grpc_resolved_address sockname_temp;
- grpc_error* error = GRPC_ERROR_NONE;
+ grpc_error_handle error = GRPC_ERROR_NONE;
int sockname_temp_len;
error = grpc_tcp_prepare_socket(sock);
failure:
GPR_ASSERT(error != GRPC_ERROR_NONE);
- char* tgtaddr = grpc_sockaddr_to_uri(addr);
grpc_error_set_int(
- grpc_error_set_str(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
- "Failed to prepare server socket", &error, 1),
- GRPC_ERROR_STR_TARGET_ADDRESS,
- grpc_slice_from_copied_string(tgtaddr)),
+ grpc_error_set_str(
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
+ "Failed to prepare server socket", &error, 1),
+ GRPC_ERROR_STR_TARGET_ADDRESS,
+ grpc_slice_from_cpp_string(grpc_sockaddr_to_uri(addr))),
GRPC_ERROR_INT_FD, (intptr_t)sock);
- gpr_free(tgtaddr);
GRPC_ERROR_UNREF(error);
if (sock != INVALID_SOCKET) closesocket(sock);
return error;
/* In order to do an async accept, we need to create a socket first which
will be the one assigned to the new incoming connection. */
-static grpc_error* start_accept_locked(grpc_tcp_listener* port) {
+static grpc_error_handle start_accept_locked(grpc_tcp_listener* port) {
SOCKET sock = INVALID_SOCKET;
BOOL success;
DWORD addrlen = sizeof(grpc_sockaddr_in6) + 16;
DWORD bytes_received = 0;
- grpc_error* error = GRPC_ERROR_NONE;
+ grpc_error_handle error = GRPC_ERROR_NONE;
if (port->shutting_down) {
return GRPC_ERROR_NONE;
}
/* Event manager callback when reads are ready. */
-static void on_accept(void* arg, grpc_error* error) {
+static void on_accept(void* arg, grpc_error_handle error) {
grpc_tcp_listener* sp = (grpc_tcp_listener*)arg;
SOCKET sock = sp->new_socket;
grpc_winsocket_callback_info* info = &sp->socket->read_info;
grpc_endpoint* ep = NULL;
grpc_resolved_address peer_name;
- char* peer_name_string;
- char* fd_name;
DWORD transfered_bytes;
DWORD flags;
BOOL wsa_success;
this is necessary in the read/write case, it's useless for the accept
case. We only need to adjust the pending callback count */
if (error != GRPC_ERROR_NONE) {
- const char* msg = grpc_error_string(error);
- gpr_log(GPR_INFO, "Skipping on_accept due to error: %s", msg);
+ gpr_log(GPR_INFO, "Skipping on_accept due to error: %s",
+ grpc_error_std_string(error).c_str());
gpr_mu_unlock(&sp->server->mu);
return;
}
-
/* The IOCP notified us of a completed operation. Let's grab the results,
and act accordingly. */
transfered_bytes = 0;
closesocket(sock);
} else {
if (!sp->shutting_down) {
- peer_name_string = NULL;
err = setsockopt(sock, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT,
(char*)&sp->socket->socket, sizeof(sp->socket->socket));
if (err) {
int peer_name_len = (int)peer_name.len;
err = getpeername(sock, (grpc_sockaddr*)peer_name.addr, &peer_name_len);
peer_name.len = (size_t)peer_name_len;
+ std::string peer_name_string;
if (!err) {
peer_name_string = grpc_sockaddr_to_uri(&peer_name);
} else {
gpr_log(GPR_ERROR, "getpeername error: %s", utf8_message);
gpr_free(utf8_message);
}
- gpr_asprintf(&fd_name, "tcp_server:%s", peer_name_string);
- ep = grpc_tcp_create(grpc_winsocket_create(sock, fd_name),
- sp->server->channel_args, peer_name_string);
- gpr_free(fd_name);
- gpr_free(peer_name_string);
+ std::string fd_name = absl::StrCat("tcp_server:", peer_name_string);
+ ep = grpc_tcp_create(
+ grpc_winsocket_create(sock, fd_name.c_str()),
+ sp->server->channel_args, peer_name_string.c_str(),
+ grpc_slice_allocator_factory_create_slice_allocator(
+ sp->server->slice_allocator_factory, peer_name_string));
} else {
closesocket(sock);
}
gpr_mu_unlock(&sp->server->mu);
}
-static grpc_error* add_socket_to_server(grpc_tcp_server* s, SOCKET sock,
- const grpc_resolved_address* addr,
- unsigned port_index,
- grpc_tcp_listener** listener) {
+static grpc_error_handle add_socket_to_server(grpc_tcp_server* s, SOCKET sock,
+ const grpc_resolved_address* addr,
+ unsigned port_index,
+ grpc_tcp_listener** listener) {
grpc_tcp_listener* sp = NULL;
int port = -1;
int status;
GUID guid = WSAID_ACCEPTEX;
DWORD ioctl_num_bytes;
LPFN_ACCEPTEX AcceptEx;
- grpc_error* error = GRPC_ERROR_NONE;
+ grpc_error_handle error = GRPC_ERROR_NONE;
/* We need to grab the AcceptEx pointer for that port, as it may be
interface-dependent. We'll cache it to avoid doing that again. */
gpr_log(GPR_ERROR, "on_connect error: %s", utf8_message);
gpr_free(utf8_message);
closesocket(sock);
- return NULL;
+ return GRPC_ERROR_NONE;
}
error = prepare_socket(sock, addr, &port);
return GRPC_ERROR_NONE;
}
-static grpc_error* tcp_server_add_port(grpc_tcp_server* s,
- const grpc_resolved_address* addr,
- int* port) {
+static grpc_error_handle tcp_server_add_port(grpc_tcp_server* s,
+ const grpc_resolved_address* addr,
+ int* port) {
grpc_tcp_listener* sp = NULL;
SOCKET sock;
grpc_resolved_address addr6_v4mapped;
grpc_resolved_address* allocated_addr = NULL;
grpc_resolved_address sockname_temp;
unsigned port_index = 0;
- grpc_error* error = GRPC_ERROR_NONE;
+ grpc_error_handle error = GRPC_ERROR_NONE;
if (s->tail != NULL) {
port_index = s->tail->port_index + 1;
gpr_free(allocated_addr);
if (error != GRPC_ERROR_NONE) {
- grpc_error* error_out = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
- "Failed to add port to server", &error, 1);
+ grpc_error_handle error_out =
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
+ "Failed to add port to server", &error, 1);
GRPC_ERROR_UNREF(error);
error = error_out;
*port = -1;
return error;
}
-static void tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset,
- size_t pollset_count,
+static void tcp_server_start(grpc_tcp_server* s,
+ const std::vector<grpc_pollset*>* /*pollsets*/,
grpc_tcp_server_cb on_accept_cb,
void* on_accept_cb_arg) {
grpc_tcp_listener* sp;