driver_console_t *driver_console_create(select_group_t *group) /*, char *name, char *download, int first_chunk)*/ { driver_console_t *driver = (driver_console_t*) safe_malloc(sizeof(driver_console_t)); driver->group = group; driver->is_shutdown = FALSE; driver->outgoing_data = buffer_create(BO_LITTLE_ENDIAN); #ifdef WIN32 /* On Windows, the stdin_handle is quite complicated, and involves a sub-thread. */ HANDLE stdin_handle = get_stdin_handle(); select_group_add_pipe(group, -1, stdin_handle, driver); select_set_recv(group, -1, console_stdin_recv); select_set_closed(group, -1, console_stdin_closed); #else /* On Linux, the stdin_handle is easy. */ int stdin_handle = STDIN_FILENO; select_group_add_socket(group, stdin_handle, SOCKET_TYPE_STREAM, driver); select_set_recv(group, stdin_handle, console_stdin_recv); select_set_closed(group, stdin_handle, console_stdin_closed); #endif return driver; }
driver_console_t *driver_console_create(select_group_t *group, char *name, char *download, int first_chunk) { driver_console_t *driver = (driver_console_t*) safe_malloc(sizeof(driver_console_t)); message_options_t options[4]; #ifdef WIN32 /* On Windows, the stdin_handle is quite complicated, and involves a sub-thread. */ HANDLE stdin_handle = get_stdin_handle(); select_group_add_pipe(group, -1, stdin_handle, driver); select_set_recv(group, -1, console_stdin_recv); select_set_closed(group, -1, console_stdin_closed); #else /* On Linux, the stdin_handle is easy. */ int stdin_handle = STDIN_FILENO; select_group_add_socket(group, stdin_handle, SOCKET_TYPE_STREAM, driver); select_set_recv(group, stdin_handle, console_stdin_recv); select_set_closed(group, stdin_handle, console_stdin_closed); #endif driver->name = name ? name : "[unnamed console]"; driver->download = download; driver->first_chunk = first_chunk; /* Subscribe to the messages we care about. */ message_subscribe(MESSAGE_DATA_IN, handle_message, driver); options[0].name = "name"; options[0].value.s = driver->name; if(driver->download) { options[1].name = "download"; options[1].value.s = driver->download; options[2].name = "first_chunk"; options[2].value.i = driver->first_chunk; } else { options[1].name = NULL; } options[3].name = NULL; driver->session_id = message_post_create_session(options); return driver; }
void sessions_attach_stdin(sessions_t *sessions) { #ifdef WIN32 /* On Windows, the stdin_handle is quire complicated, and involves a sub-thread. */ HANDLE stdin_handle = get_stdin_handle(); select_group_add_pipe(sessions->select_group, -1, stdin_handle, sessions); select_set_recv(sessions->select_group, -1, stdin_callback); select_set_closed(sessions->select_group, -1, stdin_closed_callback); #else /* On Linux, the stdin_handle is easy. */ int stdin_handle = STDIN_FILENO; select_group_add_socket(sessions->select_group, stdin_handle, SOCKET_TYPE_STREAM, sessions); select_set_recv(sessions->select_group, stdin_handle, stdin_callback); select_set_closed(sessions->select_group, stdin_handle, stdin_closed_callback); #endif }