int client_init(char *nn_ip, int nn_port, int write_cache_size, int write_cache_count, int read_cache_size, int read_cache_count, int read_async_block_count) { if(nn_ip == NULL || nn_port < 0) { nb_log("client init", NB_LOG_ERROR, "client ini is error."); return -1; } //client to ds get really data. read write. // p_net_client is gloal var. p_net_client = net_client_init(client_close_callback); if(p_net_client == NULL) { nb_log("client", NB_LOG_ERROR, "client init is error."); return -1; } //client to nn include heartbeat and get meta info. client_net_t *p_net = net_client_init(hb_close_callback); int ret = start_hb_thread(p_net, nn_ip, nn_port, TIME_HB_GAP, hb_send_data_fun, hb_recv_callback_fun); if(ret != 0) { nb_log("client", NB_LOG_ERROR, "heartbeat thread start error."); return -1; } // -- init file info lock para // -- file info list // -- it is a big lock . pthread_mutex_init(&m_file_info_list_lock, NULL); INIT_LIST_HEAD(&m_file_info_list); // -- write read // 初始化读,初始化数据结构,开启读线程,缓冲块回收线程 ret = init_read(p_net_client, read_cache_size, read_cache_count, read_async_block_count); if(ret != 0) { nb_log("", NB_LOG_ERROR, "%s 启动失败,init_read 失败"); return -1; } // 初始化写,开启写线程,数据刷新线程 ret = init_write(p_net_client, write_cache_size, write_cache_count); if(ret != 0) { nb_log("", NB_LOG_ERROR, "%s 启动失败,init_write 失败"); return -1; } return 0; }
static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *devaddr, const char *opts_str) { QemuOpts *opts; int ret; opts = qemu_opts_parse(&qemu_net_opts, opts_str ? opts_str : "", NULL); if (!opts) { monitor_printf(mon, "parsing network options '%s' failed\n", opts_str ? opts_str : ""); return NULL; } qemu_opt_set(opts, "type", "nic"); ret = net_client_init(mon, opts, 0); if (ret < 0) return NULL; if (nd_table[ret].devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); return NULL; } return pci_nic_init(&nd_table[ret], "rtl8139", devaddr); }
static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *devaddr, const char *opts_str) { QemuOpts *opts; PCIBus *bus; int ret, devfn; bus = pci_get_bus_devfn(&devfn, devaddr); if (!bus) { monitor_printf(mon, "Invalid PCI device address %s\n", devaddr); return NULL; } if (!((BusState*)bus)->allow_hotplug) { monitor_printf(mon, "PCI bus doesn't support hotplug\n"); return NULL; } opts = qemu_opts_parse(qemu_find_opts("net"), opts_str ? opts_str : "", 0); if (!opts) { return NULL; } qemu_opt_set(opts, "type", "nic"); ret = net_client_init(mon, opts, 0); if (ret < 0) return NULL; if (nd_table[ret].devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); return NULL; } return pci_nic_init(&nd_table[ret], "rtl8139", devaddr); }
/****************************************************************************** * 函数: sdev_net_setconfig * 功能: 配置网络客户端功能 * 参数: * 返回: 0 - 成功 -ESYS - 系统错误 -ERR_INVAL - 参数无效 -ERR_NOINIT - 没有初始化 * 说明: 无 ******************************************************************************/ int sdev_net_setconfig(u8 cmd, void *cfg) { int ret; memcpy(netstate.ip, ((struct netfig *)cfg)->ip,sizeof(((struct netfig *)cfg)->ip)); netstate.port = ((struct netfig *)cfg) -> port; netstate.timeout = ((struct netfig *)cfg) ->timeout; netstate.index = ((struct netfig *)cfg) -> index; ret = net_client_init(netstate.timeout); if (ret){ goto error; } netstate.init = 1; error: return(ret); }
static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, const char *devaddr, const char *opts_str) { Error *local_err = NULL; QemuOpts *opts; PCIBus *root = pci_find_primary_bus(); PCIBus *bus; int ret, devfn; if (!root) { monitor_printf(mon, "no primary PCI bus (if there are multiple" " PCI roots, you must use device_add instead)"); return NULL; } bus = pci_get_bus_devfn(&devfn, root, devaddr); if (!bus) { monitor_printf(mon, "Invalid PCI device address %s\n", devaddr); return NULL; } if (!((BusState*)bus)->allow_hotplug) { monitor_printf(mon, "PCI bus doesn't support hotplug\n"); return NULL; } opts = qemu_opts_parse(qemu_find_opts("net"), opts_str ? opts_str : "", 0); if (!opts) { return NULL; } qemu_opt_set(opts, "type", "nic"); ret = net_client_init(opts, 0, &local_err); if (error_is_set(&local_err)) { qerror_report_err(local_err); error_free(local_err); return NULL; } if (nd_table[ret].devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); return NULL; } return pci_nic_init(&nd_table[ret], root, "rtl8139", devaddr); }
int _engine_authorize_connection(engine *p, network_command cmd) { net_client* p_cli; network_command cmd_out; my_byte reintroduce; int socket = cmd.origin_socket; if (cmd.type != NCT_LEAD_INTRODUCE) { glog(LOG_FINE, "Authorization of connection %02d failed because command" "type was not correct. Expected %d, got %d", socket, NCT_LEAD_INTRODUCE, cmd.type); return 1; } if (cmd.length < 2) { glog(LOG_FINE, "Authorization of connection %02d failed because command" " was too short", socket); return 1; } reintroduce = read_hex_byte(cmd.data); if (reintroduce) { p_cli = engine_client_by_secret(p, cmd.data + 2); if (p_cli == NULL) { reintroduce = 0; } else { if (p_cli->status != NET_CLIENT_STATUS_DISCONNECTED) { glog(LOG_FINE, "Reauthorization of connection %02d failed " "because command client is not disconnected", socket); return 1; } } } if (!reintroduce) { p_cli = engine_first_free_client_offset(p); } if (p_cli == NULL) { glog(LOG_FINE, "Authorization of socket %02d failed because there" "was no more room for new client", socket); return 1; } p->resources->con_to_cli[socket] = p_cli - p->resources->clients; if (!reintroduce) { net_client_init(p_cli, p->resources->connections + socket); strrand(p_cli->connection_secret, NET_CLIENT_SECRET_LENGTH); p_cli->connection_secret[NET_CLIENT_SECRET_LENGTH] = '\0'; p_cli->room_id = ITEM_EMPTY; } else { p_cli->connection = p->resources->connections + socket; } p_cli->status = NET_CLIENT_STATUS_CONNECTED; network_command_prepare(&cmd_out, NCT_LEAD_INTRODUCE); write_hex_byte(cmd_out.data, reintroduce); memcpy(cmd_out.data + 2, p_cli->connection_secret, NET_CLIENT_SECRET_LENGTH); netadapter_send_command(p->p_netadapter, p_cli->connection, &cmd_out); if (reintroduce) { _engine_authorize_reconnect(p, p_cli); } else { glog(LOG_INFO, "Connection %02d authorized as client %02d", socket, p->resources->con_to_cli[socket]); } return 0; }