MCPcopy Create free account
hub / github.com/apache/thrift / fillUnixSocketAddr

Function fillUnixSocketAddr

lib/cpp/src/thrift/transport/SocketCommon.cpp:33–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31namespace transport {
32
33socklen_t fillUnixSocketAddr(struct sockaddr_un& address, std::string& path)
34{
35 // abstract namespace socket ?
36 bool isAbstractNamespace = path[0] == 0;
37
38#ifndef __linux__
39 if (isAbstractNamespace) {
40 TOutput::instance().perror("TSocket::open() Abstract Namespace Domain sockets only supported on linux: ", -99);
41 throw TTransportException(TTransportException::NOT_OPEN,
42 " Abstract Namespace Domain socket path not supported");
43 }
44#endif
45
46 /*
47 * For abstract namespace sockets, the path string is not null-terminated (as opposite to path based), so we
48 * rely in pass the string size, to the bind() call.
49 */
50 size_t addr_len = isAbstractNamespace ? path.size() : path.size() + 1;
51
52 if (addr_len > sizeof(((sockaddr_un*)nullptr)->sun_path)) {
53 int errno_copy = THRIFT_GET_SOCKET_ERROR;
54 TOutput::instance().perror("TSocket::open() Unix Domain socket path too long", errno_copy);
55 throw TTransportException(TTransportException::NOT_OPEN, " Unix Domain socket path too long");
56 }
57
58 address.sun_family = AF_UNIX;
59 memcpy(address.sun_path, path.c_str(), addr_len);
60
61 return static_cast<socklen_t>(sizeof((sockaddr_un*)nullptr)->sun_family + addr_len);
62}
63
64}
65}

Callers 3

listenMethod · 0.85
openConnectionMethod · 0.85
listenMethod · 0.85

Calls 3

TTransportExceptionClass · 0.70
perrorMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected