MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / open_sockpool_ll

Function open_sockpool_ll

cdb2api/cdb2api.c:1796–1845  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1794enum { SOCKPOOL_DONATE = 0, SOCKPOOL_REQUEST = 1 };
1795
1796static int open_sockpool_ll(void)
1797{
1798 struct sockpool_hello hello;
1799 const char *ptr;
1800 size_t bytesleft;
1801 int fd = socket(AF_UNIX, SOCK_STREAM, 0);
1802 if (fd == -1) {
1803 fprintf(stderr, "%s:socket: %d %s\n", __func__, errno, strerror(errno));
1804 return -1;
1805 }
1806
1807 struct sockaddr_sun addr = {0};
1808 addr.sun_family = AF_UNIX;
1809 if (SOCKPOOL_OTHER_NAME)
1810 strncpy(addr.sun_path, SOCKPOOL_OTHER_NAME, sizeof(addr.sun_path) - 1);
1811 else
1812 strncpy(addr.sun_path, SOCKPOOL_SOCKET_NAME, sizeof(addr.sun_path) - 1);
1813
1814 if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1) {
1815 close(fd);
1816 return -1;
1817 }
1818
1819 /* Connected - write hello message */
1820 memcpy(hello.magic, "SQLP", 4);
1821 hello.protocol_version = 0;
1822 hello.pid = _PID;
1823 hello.slot = 0;
1824
1825 ptr = (const char *)&hello;
1826 bytesleft = sizeof(hello);
1827 while (bytesleft > 0) {
1828 ssize_t nbytes;
1829 nbytes = write(fd, ptr, bytesleft);
1830 if (nbytes == -1) {
1831 fprintf(stderr, "%s:error writing hello: %d %s\n", __func__, errno,
1832 strerror(errno));
1833 close(fd);
1834 return -1;
1835 } else if (nbytes == 0) {
1836 fprintf(stderr, "%s:unexpected eof writing hello\n", __func__);
1837 close(fd);
1838 return -1;
1839 }
1840 bytesleft -= nbytes;
1841 ptr += nbytes;
1842 }
1843
1844 return fd;
1845}
1846
1847void cdb2_enable_sockpool()
1848{

Callers 2

cdb2_socket_pool_get_llFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected