int main(int argc, char* argv[]) { if (argc < 5) { printf("Usage: %s address port workload output\n", argv[0]); exit(EXIT_FAILURE); } struct info *inf = info_new(); struct evdns_base *dns_base; struct bufferevent *bev; struct event *ev_monitor; inf->base = event_base_new(); dns_base = evdns_base_new(inf->base, 1); int port = atoi(argv[2]); bev = bufferevent_socket_new(inf->base, -1, BEV_OPT_CLOSE_ON_FREE); bufferevent_setcb(bev, readcb, NULL, eventcb, inf); if (bufferevent_socket_connect_hostname(bev, dns_base, AF_INET, argv[1], port) < 0) { perror("connect failed.\n"); } ev_monitor = event_new(inf->base, -1, EV_TIMEOUT|EV_PERSIST, monitor, inf); struct timeval one_second = {1, 0}; event_add(ev_monitor, &one_second); // read_input(inf, argv[3]); inf->fp = fopen(argv[4], "w+"); event_base_dispatch(inf->base); bufferevent_free(bev); info_free(inf); return 0; }
static void do_info(struct info_options *opts, int client_sock) { struct info *info = info_new(); struct ipc_manager *manager; manager = ipc_manager_new(client_sock); ipc_manager_add_handler(manager, IPC_MSG_ID_INFO_MODULE, ipc_handler_info_module, info); ipc_manager_add_handler(manager, IPC_MSG_ID_INFO_END, ipc_handler_info_end, info); ipc_manager_msg_send(manager, IPC_MSG_ID_INFO, IPC_NONE_T); while (ipc_manager_receive(manager) > 0) ; ipc_manager_free(manager); if (opts->output_xml) info_save_to_xml(info); else info_save_to_stdout(info); info_free(info); }
/* since a lot of routines depend on the current_panel variable */ void set_display_type (int num, int type) { int x, y, cols, lines; int the_other; /* Index to the other panel */ char *file_name = 0; /* For Quick view */ Widget *new_widget, *old_widget; WPanel *the_other_panel; x =y = cols = lines = 0; old_widget = 0; if (num >= MAX_VIEWS){ fprintf (stderr, "Could not allocate more that %d views\n", MAX_VIEWS); abort (); } /* Check that we will have a WPanel * at least */ the_other = 0; if (type != view_listing){ the_other = num == 0 ? 1 : 0; if (panels [the_other].type != view_listing) return; } /* Get rid of it */ if (panels [num].widget){ Widget *w = panels [num].widget; WPanel *panel = (WPanel *) panels [num].widget; x = w->x; y = w->y; cols = w->cols; lines = w->lines; old_widget = panels [num].widget; if (panels [num].type == view_listing){ if (panel->frame_size == frame_full && type != view_listing){ cols = COLS - first_panel_size; if (num == 1) x = first_panel_size; } } #ifdef HAVE_TK tk_evalf ("container_clean %s", panel->widget.wcontainer); #endif } new_widget = 0; switch (type){ case view_listing: new_widget = (Widget *) panel_new (get_nth_panel_name (num)); break; case view_info: new_widget = (Widget *) info_new (); break; case view_tree: new_widget = (Widget *) tree_new (1, 0, 0, 0, 0); break; case view_quick: new_widget = (Widget *) view_new (0, 0, 0, 0, 1); the_other_panel = (WPanel *) panels [the_other].widget; if (the_other_panel) file_name = the_other_panel->dir.list[the_other_panel->selected].fname; else file_name = ""; view_init ((WView *) new_widget, 0, file_name, 0); break; } panels [num].type = type; panels [num].widget = (Widget *) new_widget; /* We set the same size the old widget had */ widget_set_size ((Widget *) new_widget, y, x, lines, cols); /* We wanna the new widget at the same position */ /* XView sets wcontainer to !0 <- Not XView, but we, when we create it */ /* Ok, the XView support code does it */ if (old_widget && old_widget->wcontainer){ new_widget->wcontainer = old_widget->wcontainer; new_widget->area = old_widget->area; } /* We use replace to keep the circular list of the dialog in the */ /* same state. Maybe we could just kill it and then replace it */ if (midnight_dlg && old_widget){ dlg_replace_widget (midnight_dlg, old_widget, panels [num].widget); } if (type == view_listing){ if (num == 0) left_panel = (WPanel *) new_widget; else right_panel = (WPanel *) new_widget; } if (type == view_tree) the_tree = (WTree *) new_widget; /* Prevent current_panel's value from becoming invalid. * It's just a quick hack to prevent segfaults. Comment out and * try following: * - select left panel * - invoke menue left/tree * - as long as you stay in the left panel almost everything that uses * cpanel causes segfault, e.g. C-Enter, C-x c, ... */ if (type != view_listing) if (cpanel == (WPanel *) old_widget) current_panel = num == 0 ? right_panel : left_panel; }
void set_display_type (int num, panel_view_mode_t type) { int x = 0, y = 0, cols = 0, lines = 0; unsigned int the_other = 0; /* Index to the other panel */ const char *file_name = NULL; /* For Quick view */ Widget *new_widget = NULL, *old_widget = NULL; panel_view_mode_t old_type = view_listing; WPanel *the_other_panel = NULL; if (num >= MAX_VIEWS) { fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS); abort (); } /* Check that we will have a WPanel * at least */ if (type != view_listing) { the_other = num == 0 ? 1 : 0; if (panels[the_other].type != view_listing) return; } /* Get rid of it */ if (panels[num].widget != NULL) { Widget *w = panels[num].widget; WPanel *panel = PANEL (w); x = w->x; y = w->y; cols = w->cols; lines = w->lines; old_widget = w; old_type = panels[num].type; if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing) { if (panels_layout.horizontal_split) { cols = COLS; x = 0; } else { cols = COLS - panels_layout.left_panel_size; if (num == 1) x = panels_layout.left_panel_size; } } } /* Restoring saved path from panels.ini for nonlist panel */ /* when it's first creation (for example view_info) */ if (old_widget == NULL && type != view_listing) { char *panel_dir; panel_dir = _vfs_get_cwd (); panels[num].last_saved_dir = g_strdup (panel_dir); g_free (panel_dir); } switch (type) { case view_nothing: case view_listing: new_widget = restore_into_right_dir_panel (num, old_widget); widget_set_size (new_widget, y, x, lines, cols); break; case view_info: new_widget = WIDGET (info_new (y, x, lines, cols)); break; case view_tree: new_widget = WIDGET (tree_new (y, x, lines, cols, TRUE)); break; case view_quick: new_widget = WIDGET (mcview_new (y, x, lines, cols, TRUE)); the_other_panel = PANEL (panels[the_other].widget); if (the_other_panel != NULL) file_name = the_other_panel->dir.list[the_other_panel->selected].fname; else file_name = ""; mcview_load ((struct mcview_struct *) new_widget, 0, file_name, 0, 0, 0); break; default: break; } if (type != view_listing) /* Must save dir, for restoring after change type to */ /* view_listing */ save_panel_dir (num); panels[num].type = type; panels[num].widget = new_widget; /* We use replace to keep the circular list of the dialog in the */ /* same state. Maybe we could just kill it and then replace it */ if ((midnight_dlg != NULL) && (old_widget != NULL)) { if (old_type == view_listing) { /* save and write directory history of panel * ... and other histories of midnight_dlg */ dlg_save_history (midnight_dlg); } widget_replace (old_widget, new_widget); } if (type == view_listing) { WPanel *panel = PANEL (new_widget); /* if existing panel changed type to view_listing, then load history */ if (old_widget != NULL) { ev_history_load_save_t event_data = { NULL, new_widget }; mc_event_raise (midnight_dlg->event_group, MCEVENT_HISTORY_LOAD, &event_data); } if (num == 0) left_panel = panel; else right_panel = panel; /* forced update format after set new sizes */ set_panel_formats (panel); } if (type == view_tree) the_tree = (WTree *) new_widget; /* Prevent current_panel's value from becoming invalid. * It's just a quick hack to prevent segfaults. Comment out and * try following: * - select left panel * - invoke menue left/tree * - as long as you stay in the left panel almost everything that uses * current_panel causes segfault, e.g. C-Enter, C-x c, ... */ if ((type != view_listing) && (current_panel == PANEL (old_widget))) current_panel = num == 0 ? right_panel : left_panel; g_free (old_widget); }