static void scan_wins(void) { int i; uint num; XWindow *wins; XWindowAttributes wa; XWindow d1, d2; if(XQueryTree(display, scr.root.xid, &d1, &d2, &wins, &num)) { for(i = 0; i < num; i++) { if(!XGetWindowAttributes(display, wins[i], &wa)) continue; /* Skip transients. */ if(wa.override_redirect || XGetTransientForHint(display, wins[i], &d1)) continue; if(wa.map_state == IsViewable) client_create(wins[i], &wa); } /* Manage transients. */ for(i = 0; i < num; i++) { if(!XGetWindowAttributes(display, wins[i], &wa)) continue; if((XGetTransientForHint(display, wins[i], &d1)) && (wa.map_state == IsViewable)) client_create(wins[i], &wa); } } if(wins) XFree(wins); }
void handle_server_event(Connection *a_server) { Client *client = NULL; if (connection_get_type(a_server) == TCP) { Connection *conn = connection_tcp_accept(connection_get_fd(a_server)); if (conn) { client = client_create(conn); vector_add(_s_clients, client); } } else { char buf[BUF_SIZE] = {0}; char straddr[BUF_SIZE] = {0}; struct sockaddr_in *addr = NULL; connection_udp_receive_with_addr(a_server, buf, BUF_SIZE, (struct sockaddr **)&addr); assert(addr); client = vector_get_first_equal(_s_clients, addr, cmp_clients_by_addr); if (client == NULL) { Connection *cl_conn = connection_create_raw(UDP, connection_get_fd(a_server), addr); client = client_create(cl_conn); vector_add(_s_clients, client); } sprintf(straddr, "%s:%d", inet_ntoa(addr->sin_addr), addr->sin_port); handle_client_data(client, buf, straddr); } }
static void client_connected_finish(const struct master_service_connection *conn) { struct client *client; struct ssl_proxy *proxy; struct ip_addr local_ip; const struct login_settings *set; const struct master_service_ssl_settings *ssl_set; unsigned int local_port; pool_t pool; int fd_ssl; void **other_sets; if (net_getsockname(conn->fd, &local_ip, &local_port) < 0) { memset(&local_ip, 0, sizeof(local_ip)); local_port = 0; } pool = pool_alloconly_create("login client", 8*1024); set = login_settings_read(pool, &local_ip, &conn->remote_ip, NULL, &ssl_set, &other_sets); if (!ssl_connections && !conn->ssl) { client = client_create(conn->fd, FALSE, pool, set, ssl_set, other_sets, &local_ip, &conn->remote_ip); } else { fd_ssl = ssl_proxy_alloc(conn->fd, &conn->remote_ip, pool, set, ssl_set, &proxy); if (fd_ssl == -1) { net_disconnect(conn->fd); pool_unref(&pool); master_service_client_connection_destroyed(master_service); return; } client = client_create(fd_ssl, TRUE, pool, set, ssl_set, other_sets, &local_ip, &conn->remote_ip); client->ssl_proxy = proxy; ssl_proxy_set_client(proxy, client); ssl_proxy_start(proxy); } client->real_remote_port = client->remote_port = conn->remote_port; client->real_local_port = client->local_port = local_port; if (auth_client_to != NULL) timeout_remove(&auth_client_to); }
void MainWindow::on_test_90_2_clicked() { struct fileinfo finfo = { finfo.copysize=1, finfo.filetype=NORMAL_FILE, finfo.blocklength=BLOCKLENGTH, }; memcpy(finfo.name,"test_90_2",100); long long testfid = client_create(&finfo); int testfd = client_open(testfid,O_READ); client_close(testfd); // char buff[BUFFSIZE]; int buffSize = atoi(ui->lineEdit_buffSize->text().toAscii()); char* buff = new char [buffSize*1024*1024]; int result = client_read(testfd,buff,(buffSize*1024*1024)*sizeof(char)); qDebug()<<result; if(result == -1 and testfd != -1){ char name1[100]; int errcode = getlasterror(testfd,name1,100); qDebug()<<"ERROR:"<<errcode<<name1; if(errcode == 102){ ui->textEdit->append(QString::number(lineCount) + " -----> read to the closed file test OK"); lineCount++; } else{ ui->textEdit->append(QString::number(lineCount) + " -----> read to the closed file test FAIL"); lineCount++; } } delete [] buff; }
int st_init(void) { int res; memset(&pool, 0, sizeof(pool)); #ifdef RPC_DUMP st_rpc_fd = open(RPC_DUMP, O_CREAT|O_WRONLY); if(st_rpc_fd < 0) { exit(110); } #endif if((res = client_create(&pool.socket, ELCD_SOCKET_FILE, NULL, NULL, NULL, NULL)) != 0) { eprintf("%s: failed to connect elcd socket\n", __FUNCTION__); return res; } res = pthread_create(&pool.thread, NULL, st_poolThread, NULL); if(res != 0) { eprintf("%s: (!) failed to create pool thread: %s\n", __FUNCTION__, strerror(res)); } #ifdef ENABLE_FUSION #define FUSION_PREFERRED_FMT "1080i50" //eprintf("%s: st_setVideoFormat %s\n", __FUNCTION__, FUSION_PREFERRED_FMT); //st_setVideoFormat("main", FUSION_PREFERRED_FMT); #endif return res; }
/* Accept a connection from new client. */ static void listener_cb (flux_t h, flux_fd_watcher_t *w, int fd, int revents, void *arg) { ctx_t *ctx = arg; if (revents & FLUX_POLLIN) { client_t *c; int cfd; if ((cfd = accept4 (fd, NULL, NULL, SOCK_CLOEXEC)) < 0) { flux_log (h, LOG_ERR, "accept: %s", strerror (errno)); goto done; } if (!(c = client_create (ctx, cfd))) { close (cfd); goto done; } if (zlist_append (ctx->clients, c) < 0) oom (); } if (revents & ZMQ_POLLERR) { flux_log (h, LOG_ERR, "poll listen fd: %s", strerror (errno)); } done: return; }
client_t * extract_json(char *text) { json_t *root, *rtinfo, *node; json_error_t error; unsigned int i; client_t *clients; if(!(root = json_loads(text, 0, &error))) { display_error("json errors\n"); return NULL; } json_check_object(root); rtinfo = json_object_get(root, "rtinfo"); json_check_array(rtinfo); clients = client_create(json_array_size(rtinfo)); for(i = 0; i < json_array_size(rtinfo); i++) { node = json_array_get(rtinfo, i); json_check_object(node); extract_json_head(node, &clients->clients[i]); extract_json_summary(node, &clients->clients[i]); extract_json_network(node, &clients->clients[i]); extract_json_disk(node, &clients->clients[i]); } json_decref(root); return clients; }
static void register_client(client_t *c, srs_req_register_t *req) { static srs_client_ops_t ops = { .notify_focus = focus_notify, .notify_command = command_notify, .notify_render = voice_notify, }; srs_context_t *srs = c->s->self->srs; char *name = req->name; char *appcls = req->appclass; char **cmds = req->commands; int ncmd = req->ncommand; char id[64]; snprintf(id, sizeof(id), "native-client-%d", c->id); mrp_debug("received register request from native client #%d", c->id); c->c = client_create(srs, SRS_CLIENT_TYPE_EXTERNAL, name, appcls, cmds, ncmd, id, &ops, c); if (c->c != NULL) reply_register(c, req->reqno, SRS_STATUS_OK, "OK"); else { reply_register(c, req->reqno, SRS_STATUS_FAILED, "failed"); destroy_client(c); } }
static int client_create_from_input(const struct mail_storage_service_input *input, const struct master_login_client *login_client, int fd_in, int fd_out, const buffer_t *input_buf, const char **error_r) { struct mail_storage_service_user *user; struct mail_user *mail_user; struct client *client; struct imap_settings *set; enum mail_auth_request_flags flags; if (mail_storage_service_lookup_next(storage_service, input, &user, &mail_user, error_r) <= 0) return -1; restrict_access_allow_coredumps(TRUE); set = mail_storage_service_user_get_set(user)[1]; if (set->verbose_proctitle) verbose_proctitle = TRUE; settings_var_expand(&imap_setting_parser_info, set, mail_user->pool, mail_user_var_expand_table(mail_user)); client = client_create(fd_in, fd_out, input->session_id, mail_user, user, set); T_BEGIN { client_add_input(client, input_buf); } T_END; flags = login_client->auth_req.flags; if ((flags & MAIL_AUTH_REQUEST_FLAG_TLS_COMPRESSION) != 0) client->tls_compression = TRUE; return 0; }
Client *network_create_client(const char *name, IO *io) { Client *client; // append to client array client = array_append(&_clients); if (client == NULL) { log_error("Could not append to client array: %s (%d)", get_errno_name(errno), errno); return NULL; } // create new client that takes ownership of the I/O object if (client_create(client, name, io, _next_authentication_nonce++, NULL) < 0) { array_remove(&_clients, _clients.count - 1, NULL); return NULL; } log_info("Added new client ("CLIENT_SIGNATURE_FORMAT")", client_expand_signature(client)); return client; }
static int connection_client_setup (connection_queue_t *node) { int err; err = -ENOENT; if (node->con->con_timeout <= time(NULL)) return err; global_lock(); err = client_create (&node->client, node->con, node->parser); if (err < 0) goto out_fail; if (sock_set_blocking (node->con->sock, 0) || sock_set_nodelay (node->con->sock)) { if (! sock_recoverable(sock_error())) { node->con->error = 1; err = -EINVAL; goto out_fail; } err = -EINPROGRESS; client_send_403 (node->client, "failed to set tcp options on client connection, dropping"); goto out_fail; } global_unlock(); return 0; out_fail: global_unlock(); return err; }
int clients_start(context_t *ctx) { srs_plugin_t *pl; srs_context_t *srs; clients_t *clients; srs_client_ops_t callbacks; if (!ctx || !(pl = ctx->plugin) || !(srs = pl->srs) || !(clients = ctx->clients)) return -1; callbacks.notify_focus = notify_focus; callbacks.notify_command = notify_command; clients->srs_client = client_create(srs, SRS_CLIENT_TYPE_BUILTIN, PLUGIN_NAME, "player", commands, ncommand, PLUGIN_NAME, &callbacks, ctx); mrp_htbl_foreach(clients->player.name, player_register, (void *)ctx); client_request_focus(clients->srs_client, SRS_VOICE_FOCUS_SHARED); return 0; }
static int client_create_from_input(const struct mail_storage_service_input *input, int fd_in, int fd_out, const buffer_t *input_buf, const char **error_r) { const char *lookup_error_str = "-ERR [SYS/TEMP] "MAIL_ERRSTR_CRITICAL_MSG"\r\n"; struct mail_storage_service_user *user; struct mail_user *mail_user; struct client *client; const struct pop3_settings *set; if (mail_storage_service_lookup_next(storage_service, input, &user, &mail_user, error_r) <= 0) { (void)write(fd_out, lookup_error_str, strlen(lookup_error_str)); return -1; } restrict_access_allow_coredumps(TRUE); set = mail_storage_service_user_get_set(user)[1]; if (set->verbose_proctitle) verbose_proctitle = TRUE; if (client_create(fd_in, fd_out, input->session_id, mail_user, user, set, &client) == 0) client_add_input(client, input_buf); return 0; }
static void client_connected(struct master_service_connection *conn) { if (conn->fifo) (void)fifo_input_connection_create(conn->fd); else (void)client_create(conn->fd); master_service_client_connection_accept(conn); }
static void client_connected(struct master_service_connection *conn) { master_service_client_connection_accept(conn); if (ipc_socket_is_client(conn->name)) (void)client_create(conn->fd); else (void)ipc_connection_create(conn->listen_fd, conn->fd); }
static void main_init(void) { struct master_service_connection conn; if (IS_STANDALONE()) { memset(&conn, 0, sizeof(conn)); (void)client_create(STDIN_FILENO, STDOUT_FILENO, &conn); } dns_client_socket_path = t_abspath(DNS_CLIENT_SOCKET_PATH); }
int main(int argc, char **argv) { int sock_fd; int ret; char *precv_buf; client_t *pclient; struct sockaddr_in cli_addr; struct sockaddr_in serv_addr; sock_fd = socket(AF_INET,SOCK_DGRAM,0); ERROR(sock_fd < 0,"socket()"); bzero(&serv_addr,sizeof(struct sockaddr_in)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(SERV_PORT); serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); ret = bind(sock_fd,(void *)&serv_addr,sizeof(struct sockaddr_in)); ERROR(ret < 0,"bind"); pclient = client_create(); ERROR(pclient == NULL,"client_create()"); while(1) { if(recvfrom_data(sock_fd,&cli_addr,&precv_buf) == -1) continue; if(*(int *)precv_buf == QQ_LOGIN) { login(sock_fd,pclient,&cli_addr,precv_buf + 4); } else if(*(int *)precv_buf == QQ_MSG) { client_insert_msg(pclient,inet_ntoa(cli_addr.sin_addr), precv_buf + 4); } else { free_recvfrom_data(precv_buf); continue; } free_recvfrom_data(precv_buf); if(fork() == 0) { client_send(sock_fd,pclient); close(sock_fd); exit(0); } } return 0; }
void interprocess::send_msg(std::string msg) { client_create(); msg = on_msg_send(msg); int size = msg.size(); std::lock_guard<std::mutex> lock(read_mutex); DWORD kur; WriteFile(pipe_handle, (const char*)(&size), sizeof(size), &kur, NULL); WriteFile(pipe_handle, msg.c_str(), size, &kur, NULL); }
void rpc_call_2048(char *host, half_long_string hl1) { CLIENT *clnt; long_string *result_2; clnt = client_create(host); result_2 = rpc_call_2048_1(&hl1, clnt); if (result_2 == (long_string *) NULL) { clnt_perror(clnt, "call failed"); } clnt_destroy(clnt); }
static void client_connected(struct master_service_connection *conn) { if (conn->fifo) { if (mail_server_conn != NULL) { i_error("Received another mail-server connection"); return; } mail_server_conn = mail_server_connection_create(conn->fd); } else { (void)client_create(conn->fd); } master_service_client_connection_accept(conn); }
static void ready(struct connection *self, struct event_loop *loop, uint32_t mask) { char ip[16]; int port; if (mask & E_READABLE) { int fd = socket_accept(self->fd, ip, sizeof(ip), &port); logger(DEBUG, "accepted %s:%d", ip, port); struct connection *client = client_create(self->ctx, fd); event_register(loop, client); } }
static int wrtc_setup(wrtc_t *wrtc) { static srs_client_ops_t ops = { .notify_focus = focus_cb, .notify_command = command_cb }; srs_context_t *srs = wrtc->srs; char *cmds[] = { (char *)wrtc->config.play, (char *)wrtc->config.stop, (char *)wrtc->config.pause, (char *)wrtc->config.next, (char *)wrtc->config.prev }; int ncmd = (int)MRP_ARRAY_SIZE(cmds); const char *name = "wrt-media-client"; const char *appcls = "player"; const char *id = "wrt-media-client"; if (!strcmp(wrtc->config.bus, "session")) wrtc->gdbus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); else if (!strcmp(wrtc->config.bus, "system")) wrtc->gdbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); else { int flags = G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION; wrtc->gdbus = g_dbus_connection_new_for_address_sync(wrtc->config.bus, flags, NULL, NULL, NULL); } if (wrtc->gdbus == NULL) return FALSE; wrtc->gnrq = g_bus_own_name(G_BUS_TYPE_SESSION, "org.tizen.srs", 0, NULL, name_acquired_cb, name_lost_cb, wrtc, NULL); wrtc->c = client_create(srs, SRS_CLIENT_TYPE_BUILTIN, name, appcls, cmds, ncmd, id, &ops, wrtc); if (wrtc->c == NULL) { wrtc_cleanup(wrtc); return FALSE; } client_request_focus(wrtc->c, SRS_VOICE_FOCUS_SHARED); return TRUE; }
static void client_connected_finish(const struct master_service_connection *conn) { struct client *client; struct ssl_proxy *proxy; const struct login_settings *set; const struct master_service_ssl_settings *ssl_set; pool_t pool; int fd_ssl; void **other_sets; pool = pool_alloconly_create("login client", 8*1024); set = login_settings_read(pool, &conn->local_ip, &conn->remote_ip, NULL, &ssl_set, &other_sets); if (!ssl_connections && !conn->ssl) { (void)client_create(conn->fd, FALSE, pool, conn, set, ssl_set, other_sets); } else { fd_ssl = ssl_proxy_alloc(conn->fd, &conn->remote_ip, pool, set, ssl_set, &proxy); if (fd_ssl == -1) { net_disconnect(conn->fd); pool_unref(&pool); master_service_client_connection_destroyed(master_service); return; } client = client_create(fd_ssl, TRUE, pool, conn, set, ssl_set, other_sets); client->ssl_proxy = proxy; ssl_proxy_set_client(proxy, client); ssl_proxy_start(proxy); } if (auth_client_to != NULL) timeout_remove(&auth_client_to); }
/** * Allocate and launch a client in a new thread. */ void create_client() { client_t *c = NULL; c = client_create(g_started++); // If the allocation failed we can't really do much... abort_if_null(c, "client_create() failed while creating client"); // Make sure the thread handler knows about our new client add_client_to_thread_handler(c); // Actually start a new thread for the client and run it launch_client_thread(c); }
void test_client() { socket_t client_socket = client_create("127.0.0.1", SERVER_PORT); char buffer[] = "Hello,World!"; socket_send(client_socket, buffer, sizeof(buffer)); int len = 0; char* recv = socket_recv_all(client_socket, &len); if (recv){ printf(recv); } close(client_socket); }
void rpc_call_4(char *host, int arg_4bytes) { CLIENT *clnt; int *result_1; int rpc_call_4_1_arg; clnt = client_create(host); result_1 = rpc_call_4_1(&rpc_call_4_1_arg, clnt); if (result_1 == (int *) NULL) { clnt_perror(clnt, "call failed"); } clnt_destroy(clnt); }
static int register_req(mrp_dbus_t *dbus, mrp_dbus_msg_t *req, void *user_data) { static srs_client_ops_t ops = { .notify_focus = focus_notify, .notify_command = command_notify, .notify_render = voice_notify, }; dbusif_t *bus = (dbusif_t *)user_data; srs_context_t *srs = bus->self->srs; const char *id, *name, *appcls, *errmsg; char **cmds; int ncmd, err; srs_client_t *c; ncmd = 0; err = parse_register(req, &id, &name, &appcls, &cmds, &ncmd, &errmsg); if (err) { reply_register(dbus, req, err, errmsg); return TRUE; } mrp_debug("got register request from %s", id); c = client_create(srs, SRS_CLIENT_TYPE_EXTERNAL, name, appcls, cmds, ncmd, id, &ops, bus); if (c != NULL) { if (mrp_dbus_follow_name(dbus, id, name_change_cb, bus)) { err = 0; errmsg = NULL; } else { client_destroy(c); err = EINVAL; errmsg = "failed to track DBUS name"; } } else { err = EINVAL; errmsg = "failed to register client"; } reply_register(dbus, req, err, errmsg); return TRUE; }
static void _handle_source_request(connection_t *con, http_parser_t *parser, char *uri) { client_t *client; source_t *source; client = client_create(con, parser); INFO1("Source logging in at mountpoint \"%s\"", uri); if (uri[0] != '/') { WARN0 ("source mountpoint not starting with /"); client_send_401 (client); return; } if (!connection_check_source_pass(parser, uri)) { /* We commonly get this if the source client is using the wrong * protocol: attempt to diagnose this and return an error */ /* TODO: Do what the above comment says */ INFO1("Source (%s) attempted to login with invalid or missing password", uri); client_send_401(client); return; } source = source_reserve (uri); if (source) { source->client = client; source->parser = parser; source->con = con; if (connection_complete_source (source) < 0) { source->client = NULL; source_free_source (source); } else thread_create ("Source Thread", source_client_thread, source, THREAD_DETACHED); } else { client_send_404 (client, "Mountpoint in use"); WARN1 ("Mountpoint %s in use", uri); } }
static void mapreq_event(Window *w, XMapRequestEvent *e) { XWindowAttributes wa; if(!XGetWindowAttributes(display, e->window, &wa)) return; if(wa.override_redirect) { /* Do I really want these? */ /* Probably not. XSelectInput(display, e->window, PropertyChangeMask | StructureNotifyMask); */ return; } if(!win2client(e->window)) client_create(e->window, &wa); }
int server_accept(t_net_fd *nfd) { t_irc *irc; t_client *cl; irc = (t_irc *)nfd->data; cl = client_create(net_socket_accept(irc->server)); if (cl) { if (add_client(irc, cl) == -1) { client_destroy(cl); return (0); } } return (0); }