Lines Matching full:peer

71 /* free a peer when the server advertises a disconnection or when the
74 ivshmem_server_free_peer(IvshmemServer *server, IvshmemServerPeer *peer) in ivshmem_server_free_peer() argument
79 IVSHMEM_SERVER_DEBUG(server, "free peer %" PRId64 "\n", peer->id); in ivshmem_server_free_peer()
80 close(peer->sock_fd); in ivshmem_server_free_peer()
81 QTAILQ_REMOVE(&server->peer_list, peer, next); in ivshmem_server_free_peer()
85 ivshmem_server_send_one_msg(other_peer->sock_fd, peer->id, -1); in ivshmem_server_free_peer()
88 for (vector = 0; vector < peer->vectors_count; vector++) { in ivshmem_server_free_peer()
89 event_notifier_cleanup(&peer->vectors[vector]); in ivshmem_server_free_peer()
92 g_free(peer); in ivshmem_server_free_peer()
95 /* send the peer id and the shm_fd just after a new client connection */
97 ivshmem_server_send_initial_info(IvshmemServer *server, IvshmemServerPeer *peer) in ivshmem_server_send_initial_info() argument
102 ret = ivshmem_server_send_one_msg(peer->sock_fd, IVSHMEM_PROTOCOL_VERSION, in ivshmem_server_send_initial_info()
110 /* send the peer id to the client */ in ivshmem_server_send_initial_info()
111 ret = ivshmem_server_send_one_msg(peer->sock_fd, peer->id, -1); in ivshmem_server_send_initial_info()
113 IVSHMEM_SERVER_DEBUG(server, "cannot send peer id: %s\n", in ivshmem_server_send_initial_info()
119 ret = ivshmem_server_send_one_msg(peer->sock_fd, -1, server->shm_fd); in ivshmem_server_send_initial_info()
133 IvshmemServerPeer *peer, *other_peer; in ivshmem_server_handle_new_conn() local
152 /* allocate new structure for this peer */ in ivshmem_server_handle_new_conn()
153 peer = g_malloc0(sizeof(*peer)); in ivshmem_server_handle_new_conn()
154 peer->sock_fd = newfd; in ivshmem_server_handle_new_conn()
156 /* get an unused peer id */ in ivshmem_server_handle_new_conn()
168 g_free(peer); in ivshmem_server_handle_new_conn()
171 peer->id = server->cur_id++; in ivshmem_server_handle_new_conn()
174 peer->vectors_count = server->n_vectors; in ivshmem_server_handle_new_conn()
175 for (i = 0; i < peer->vectors_count; i++) { in ivshmem_server_handle_new_conn()
176 if (event_notifier_init(&peer->vectors[i], FALSE) < 0) { in ivshmem_server_handle_new_conn()
182 /* send peer id and shm fd */ in ivshmem_server_handle_new_conn()
183 if (ivshmem_server_send_initial_info(server, peer) < 0) { in ivshmem_server_handle_new_conn()
188 /* advertise the new peer to others */ in ivshmem_server_handle_new_conn()
190 for (i = 0; i < peer->vectors_count; i++) { in ivshmem_server_handle_new_conn()
191 ivshmem_server_send_one_msg(other_peer->sock_fd, peer->id, in ivshmem_server_handle_new_conn()
192 peer->vectors[i].wfd); in ivshmem_server_handle_new_conn()
198 for (i = 0; i < peer->vectors_count; i++) { in ivshmem_server_handle_new_conn()
199 ivshmem_server_send_one_msg(peer->sock_fd, other_peer->id, in ivshmem_server_handle_new_conn()
204 /* advertise the new peer to itself */ in ivshmem_server_handle_new_conn()
205 for (i = 0; i < peer->vectors_count; i++) { in ivshmem_server_handle_new_conn()
206 ivshmem_server_send_one_msg(peer->sock_fd, peer->id, in ivshmem_server_handle_new_conn()
207 event_notifier_get_fd(&peer->vectors[i])); in ivshmem_server_handle_new_conn()
210 QTAILQ_INSERT_TAIL(&server->peer_list, peer, next); in ivshmem_server_handle_new_conn()
211 IVSHMEM_SERVER_DEBUG(server, "new peer id = %" PRId64 "\n", in ivshmem_server_handle_new_conn()
212 peer->id); in ivshmem_server_handle_new_conn()
217 event_notifier_cleanup(&peer->vectors[i]); in ivshmem_server_handle_new_conn()
220 g_free(peer); in ivshmem_server_handle_new_conn()
367 IvshmemServerPeer *peer, *npeer; in ivshmem_server_close() local
371 QTAILQ_FOREACH_SAFE(peer, &server->peer_list, next, npeer) { in ivshmem_server_close()
372 ivshmem_server_free_peer(server, peer); in ivshmem_server_close()
385 /* get the fd_set according to the unix socket and the peer list */
389 IvshmemServerPeer *peer; in ivshmem_server_get_fds() local
400 QTAILQ_FOREACH(peer, &server->peer_list, next) { in ivshmem_server_get_fds()
401 FD_SET(peer->sock_fd, fds); in ivshmem_server_get_fds()
402 if (peer->sock_fd >= *maxfd) { in ivshmem_server_get_fds()
403 *maxfd = peer->sock_fd + 1; in ivshmem_server_get_fds()
412 IvshmemServerPeer *peer, *peer_next; in ivshmem_server_handle_fds() local
421 QTAILQ_FOREACH_SAFE(peer, &server->peer_list, next, peer_next) { in ivshmem_server_handle_fds()
422 /* any message from a peer socket result in a close() */ in ivshmem_server_handle_fds()
423 IVSHMEM_SERVER_DEBUG(server, "peer->sock_fd=%d\n", peer->sock_fd); in ivshmem_server_handle_fds()
424 if (peer->sock_fd < maxfd && FD_ISSET(peer->sock_fd, fds)) { in ivshmem_server_handle_fds()
425 ivshmem_server_free_peer(server, peer); in ivshmem_server_handle_fds()
432 /* lookup peer from its id */
436 IvshmemServerPeer *peer; in ivshmem_server_search_peer() local
438 QTAILQ_FOREACH(peer, &server->peer_list, next) { in ivshmem_server_search_peer()
439 if (peer->id == peer_id) { in ivshmem_server_search_peer()
440 return peer; in ivshmem_server_search_peer()
450 const IvshmemServerPeer *peer; in ivshmem_server_dump() local
454 QTAILQ_FOREACH(peer, &server->peer_list, next) { in ivshmem_server_dump()
455 printf("peer_id = %" PRId64 "\n", peer->id); in ivshmem_server_dump()
457 for (vector = 0; vector < peer->vectors_count; vector++) { in ivshmem_server_dump()
459 event_notifier_get_fd(&peer->vectors[vector])); in ivshmem_server_dump()