static void migrate_ft_trans_connect(FdMigrationState *s, int old_vm_running) { /* close buffered_file and open ft_trans_file * NB: fd won't get closed, and reused by ft_trans_file */ qemu_fclose(s->file); s->file = qemu_fopen_ops_ft_trans(s, migrate_fd_put_buffer, migrate_fd_get_buffer, migrate_ft_trans_put_ready, migrate_ft_trans_get_ready, migrate_fd_wait_for_unfreeze, migrate_fd_close, 1); socket_set_nodelay(s->fd); /* events are tapped from now */ if (event_tap_register(migrate_ft_trans_put_ready) < 0) { migrate_ft_trans_error(s); } event_tap_schedule_suspend(); if (old_vm_running) { vm_start(); } }
static void connect_peer(struct peer* p) { bufferevent_enable(p->bev, EV_READ|EV_WRITE); bufferevent_socket_connect(p->bev, (struct sockaddr*)&p->addr, sizeof(p->addr)); socket_set_nodelay(bufferevent_getfd(p->bev)); paxos_log_info("Connect to %s:%d", inet_ntoa(p->addr.sin_addr), ntohs(p->addr.sin_port)); }
SysChannel sys_channel_create_tcp_client( const char* hostname, int port ) { SysChannel channel = sys_channel_alloc(); channel->fd = socket_network_client( hostname, port, SOCKET_STREAM ); if (channel->fd < 0) { sys_channel_free(channel); return NULL; }; /* set to non-blocking and disable Nagle algorithm */ socket_set_nonblock( channel->fd ); socket_set_nodelay( channel->fd ); return channel; }
SysChannel sys_channel_create_tcp_handler( SysChannel server_channel ) { SysChannel channel = sys_channel_alloc(); D( "%s: creating handler from server channel %p:%d\n", __FUNCTION__, server_channel, server_channel->fd ); channel->fd = socket_accept_any( server_channel->fd ); if (channel->fd < 0) { perror( "accept" ); sys_channel_free( channel ); return NULL; } /* disable Nagle algorithm */ socket_set_nodelay( channel->fd ); D( "%s: handler %p:%d created from server %p:%d\n", __FUNCTION__, server_channel, server_channel->fd, channel, channel->fd ); return channel; }
static void* openglesPipe_init( void* hwpipe, void* _looper, const char* args ) { char temp[32]; NetPipe *pipe; if (!_opengles_init) { /* This should never happen, unless there is a bug in the * emulator's initialization, or the system image. */ D("Trying to open the OpenGLES pipe without GPU emulation!"); return NULL; } /* For now, simply connect through tcp */ snprintf(temp, sizeof temp, "%d", ANDROID_OPENGLES_BASE_PORT); pipe = (NetPipe *)netPipe_initTcp(hwpipe, _looper, temp); if (pipe != NULL) { // Disable TCP nagle algorithm to improve throughput of small packets socket_set_nodelay(pipe->io->fd); // On Win32, adjust buffer sizes #ifdef _WIN32 { int sndbuf = 128 * 1024; int len = sizeof(sndbuf); if (setsockopt(pipe->io->fd, SOL_SOCKET, SO_SNDBUF, (char*)&sndbuf, len) == SOCKET_ERROR) { D("Failed to set SO_SNDBUF to %d error=0x%x\n", sndbuf, WSAGetLastError()); } } #endif /* _WIN32 */ } return pipe; }
static void on_accept(struct evconnlistener *l, evutil_socket_t fd, struct sockaddr* addr, int socklen, void *arg) { struct peer* peer; struct peers* peers = arg; peers->clients = realloc(peers->clients, sizeof(struct peer*) * (peers->clients_count+1)); peers->clients[peers->clients_count] = make_peer(peers, peers->clients_count, (struct sockaddr_in*)addr); peer = peers->clients[peers->clients_count]; bufferevent_setfd(peer->bev, fd); bufferevent_setcb(peer->bev, on_read, NULL, on_client_event, peer); bufferevent_enable(peer->bev, EV_READ|EV_WRITE); socket_set_nodelay(fd); paxos_log_info("Accepted connection from %s:%d", inet_ntoa(((struct sockaddr_in*)addr)->sin_addr), ntohs(((struct sockaddr_in*)addr)->sin_port)); peers->clients_count++; }
static void* openglesPipe_init( void* hwpipe, void* _looper, const char* args ) { NetPipe *pipe; if (!_opengles_init) { /* This should never happen, unless there is a bug in the * emulator's initialization, or the system image. */ D("Trying to open the OpenGLES pipe without GPU emulation!"); return NULL; } char server_addr[PATH_MAX]; android_gles_server_path(server_addr, sizeof(server_addr)); #ifndef _WIN32 if (android_gles_fast_pipes) { pipe = (NetPipe *)netPipe_initUnix(hwpipe, _looper, server_addr); D("Creating Unix OpenGLES pipe for GPU emulation: %s", server_addr); } else { #else /* _WIN32 */ { #endif /* Connect through TCP as a fallback */ pipe = (NetPipe *)netPipe_initTcp(hwpipe, _looper, server_addr); D("Creating TCP OpenGLES pipe for GPU emulation!"); } if (pipe != NULL) { // Disable TCP nagle algorithm to improve throughput of small packets socket_set_nodelay(pipe->io->fd); // On Win32, adjust buffer sizes #ifdef _WIN32 { int sndbuf = 128 * 1024; int len = sizeof(sndbuf); if (setsockopt(pipe->io->fd, SOL_SOCKET, SO_SNDBUF, (char*)&sndbuf, len) == SOCKET_ERROR) { D("Failed to set SO_SNDBUF to %d error=0x%x\n", sndbuf, WSAGetLastError()); } } #endif /* _WIN32 */ } return pipe; } static const GoldfishPipeFuncs openglesPipe_funcs = { openglesPipe_init, netPipe_closeFromGuest, netPipe_sendBuffers, netPipe_recvBuffers, netPipe_poll, netPipe_wakeOn, NULL, /* we can't save these */ NULL, /* we can't load these */ }; void android_net_pipes_init(void) { Looper* looper = looper_newCore(); goldfish_pipe_add_type( "tcp", looper, &netPipeTcp_funcs ); #ifndef _WIN32 goldfish_pipe_add_type( "unix", looper, &netPipeUnix_funcs ); #endif goldfish_pipe_add_type( "opengles", looper, &openglesPipe_funcs ); }