##// END OF EJS Templates
discovery: introduce a partialdiscovery object...
discovery: introduce a partialdiscovery object This object will ultimately gather the data about common, undecided and missing revs in a single place and deal with most graph related computations. The goal is both to clarify the algorithm and to help provides a simple and clear API that can be reimplemented in Rust. For now, we only moved the `common` set in the object. In this commit, some direct access to the "private" `disco._common` attribute persist. They have not been removed yet because we won't need to expose a full API identical to `incrementalmissingancestors` and it seems simpler to access the attribute directly until the replacement is in place.

File last commit:

r40005:208cb7a9 default
r41147:3023bc4b default
Show More
sendfds.c
51 lines | 1.3 KiB | text/x-c | CLexer
Yuya Nishihara
rust-chg: add function to send fds via domain socket...
r40005 /*
* Utility to send fds via Unix domain socket
*
* Copyright 2011, 2018 Yuya Nishihara <yuya@tcha.org>
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2 or any later version.
*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#define MAX_FD_LEN 10
/*
* Sends the given fds with 1-byte dummy payload.
*
* Returns the number of bytes sent on success, -1 on error and errno is set
* appropriately.
*/
ssize_t sendfds(int sockfd, const int *fds, size_t fdlen)
{
char dummy[1] = {0};
struct iovec iov = {dummy, sizeof(dummy)};
char fdbuf[CMSG_SPACE(sizeof(fds[0]) * MAX_FD_LEN)];
struct msghdr msgh;
struct cmsghdr *cmsg;
/* just use a fixed-size buffer since we'll never send tons of fds */
if (fdlen > MAX_FD_LEN) {
errno = EINVAL;
return -1;
}
memset(&msgh, 0, sizeof(msgh));
msgh.msg_iov = &iov;
msgh.msg_iovlen = 1;
msgh.msg_control = fdbuf;
msgh.msg_controllen = CMSG_SPACE(sizeof(fds[0]) * fdlen);
cmsg = CMSG_FIRSTHDR(&msgh);
cmsg->cmsg_level = SOL_SOCKET;
cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(fds[0]) * fdlen);
memcpy(CMSG_DATA(cmsg), fds, sizeof(fds[0]) * fdlen);
msgh.msg_controllen = cmsg->cmsg_len;
return sendmsg(sockfd, &msgh, 0);
}