Lines Matching defs:peer
76 struct tmuxpeer *peer = arg;
80 if (!(peer->flags & PEER_BAD) && (events & EV_READ)) {
81 if (((n = imsg_read(&peer->ibuf)) == -1 && errno != EAGAIN) ||
83 peer->dispatchcb(NULL, peer->arg);
87 if ((n = imsg_get(&peer->ibuf, &imsg)) == -1) {
88 peer->dispatchcb(NULL, peer->arg);
93 log_debug("peer %p message %d", peer, imsg.hdr.type);
95 if (peer_check_version(peer, &imsg) != 0) {
103 peer->dispatchcb(&imsg, peer->arg);
109 if (msgbuf_write(&peer->ibuf.w) <= 0 && errno != EAGAIN) {
110 peer->dispatchcb(NULL, peer->arg);
115 if ((peer->flags & PEER_BAD) && peer->ibuf.w.queued == 0) {
116 peer->dispatchcb(NULL, peer->arg);
120 proc_update_event(peer);
132 peer_check_version(struct tmuxpeer *peer, struct imsg *imsg)
138 log_debug("peer %p bad version %d", peer, version);
140 proc_send(peer, MSG_VERSION, -1, NULL, 0);
141 peer->flags |= PEER_BAD;
149 proc_update_event(struct tmuxpeer *peer)
153 event_del(&peer->event);
156 if (peer->ibuf.w.queued > 0)
158 event_set(&peer->event, peer->ibuf.fd, events, proc_event_cb, peer);
160 event_add(&peer->event, NULL);
164 proc_send(struct tmuxpeer *peer, enum msgtype type, int fd, const void *buf,
167 struct imsgbuf *ibuf = &peer->ibuf;
171 if (peer->flags & PEER_BAD)
173 log_debug("sending message %d to peer %p (%zu bytes)", type, peer, len);
178 proc_update_event(peer);
225 struct tmuxpeer *peer;
227 TAILQ_FOREACH(peer, &tp->peers, entry)
228 imsg_flush(&peer->ibuf);
307 struct tmuxpeer *peer;
310 peer = xcalloc(1, sizeof *peer);
311 peer->parent = tp;
313 peer->dispatchcb = dispatchcb;
314 peer->arg = arg;
316 imsg_init(&peer->ibuf, fd);
317 event_set(&peer->event, fd, EV_READ, proc_event_cb, peer);
319 if (getpeereid(fd, &peer->uid, &gid) != 0)
320 peer->uid = (uid_t)-1;
322 log_debug("add peer %p: %d (%p)", peer, fd, arg);
323 TAILQ_INSERT_TAIL(&tp->peers, peer, entry);
325 proc_update_event(peer);
326 return (peer);
330 proc_remove_peer(struct tmuxpeer *peer)
332 TAILQ_REMOVE(&peer->parent->peers, peer, entry);
333 log_debug("remove peer %p", peer);
335 event_del(&peer->event);
336 imsg_clear(&peer->ibuf);
338 close(peer->ibuf.fd);
339 free(peer);
343 proc_kill_peer(struct tmuxpeer *peer)
345 peer->flags |= PEER_BAD;
349 proc_flush_peer(struct tmuxpeer *peer)
351 imsg_flush(&peer->ibuf);
385 proc_get_peer_uid(struct tmuxpeer *peer)
387 return (peer->uid);