3 #include <sys/socket.h>
7 msg_recv_creds(Pulse *conn, Pulse_Tag *tag)
15 uint8_t data[CMSG_SPACE(sizeof(struct ucred))];
18 memset(&iov, 0, sizeof(iov));
19 iov.iov_base = &tag->header[tag->pos];
20 iov.iov_len = sizeof(tag->header) - tag->pos;
22 memset(&cmsg, 0, sizeof(cmsg));
23 memset(&mh, 0, sizeof(mh));
26 mh.msg_control = &cmsg;
27 mh.msg_controllen = sizeof(cmsg);
29 r = recvmsg(ecore_main_fd_handler_fd_get(conn->fdh), &mh, 0);
30 if ((!r) || (r == sizeof(tag->header))) tag->auth = EINA_TRUE;
33 if (errno != EAGAIN) ecore_main_fd_handler_del(conn->fdh);
37 DBG("%zu bytes left", sizeof(tag->header) - r);
47 msg_recv(Pulse *conn, Pulse_Tag *tag)
55 uint8_t data[CMSG_SPACE(sizeof(struct ucred))];
58 memset(&iov, 0, sizeof(iov));
59 iov.iov_base = tag->data + tag->pos;
60 iov.iov_len = tag->dsize - tag->pos;
62 memset(&cmsg, 0, sizeof(cmsg));
63 memset(&mh, 0, sizeof(mh));
66 mh.msg_control = &cmsg;
67 mh.msg_controllen = sizeof(cmsg);
69 r = recvmsg(ecore_main_fd_handler_fd_get(conn->fdh), &mh, 0);
70 DBG("recv %li bytes", r);
71 /* things we don't really care about: credentials */
72 if ((!r) || ((unsigned int)r == tag->dsize))
74 conn->iq = eina_list_remove(conn->iq, tag);
79 if (errno != EAGAIN) ecore_main_fd_handler_del(conn->fdh);
91 msg_sendmsg_creds(Pulse *conn, Pulse_Tag *tag)
99 uint8_t data[CMSG_SPACE(sizeof(struct ucred))];
103 memset(&iov, 0, sizeof(iov));
104 iov.iov_base = (void*) &tag->header[tag->pos];
105 iov.iov_len = sizeof(tag->header) - tag->pos;
107 memset(&cmsg, 0, sizeof(cmsg));
108 cmsg.hdr.cmsg_len = CMSG_LEN(sizeof(struct ucred));
109 cmsg.hdr.cmsg_level = SOL_SOCKET;
110 cmsg.hdr.cmsg_type = SCM_CREDENTIALS;
112 u = (struct ucred*) CMSG_DATA(&cmsg.hdr);
118 memset(&mh, 0, sizeof(mh));
121 mh.msg_control = &cmsg;
122 mh.msg_controllen = sizeof(cmsg);
124 r = sendmsg(ecore_main_fd_handler_fd_get(conn->fdh), &mh, MSG_NOSIGNAL);
125 if ((!r) || (r == (int)sizeof(tag->header))) tag->auth = EINA_TRUE;
128 if (errno != EAGAIN) ecore_main_fd_handler_del(conn->fdh);
139 msg_send_creds(Pulse *conn, Pulse_Tag *tag)
144 INF("trying to send 20 byte auth header");
145 r = send(ecore_main_fd_handler_fd_get(conn->fdh), &tag->header[tag->pos], sizeof(tag->header) - tag->pos, MSG_NOSIGNAL);
146 INF("%i bytes sent!", r);
147 if ((!r) || (r == (int)sizeof(tag->header))) tag->auth = EINA_TRUE;
150 if (errno != EAGAIN) ecore_main_fd_handler_del(conn->fdh);
161 msg_send(Pulse *conn, Pulse_Tag *tag)
166 INF("trying to send %zu bytes", tag->dsize - tag->pos);
167 r = send(ecore_main_fd_handler_fd_get(conn->fdh), tag->data + tag->pos, tag->dsize - tag->pos, MSG_NOSIGNAL);
168 INF("%i bytes sent!", r);
169 if ((!r) || ((unsigned int)r == tag->dsize - tag->pos))
171 DBG("Send complete! Deleting tag...");
172 conn->oq = eina_list_remove(conn->oq, tag);
178 if (errno != EAGAIN) ecore_main_fd_handler_del(conn->fdh);