diff options
author | ivanzhukov <ivanzhukov@ydb.tech> | 2022-08-26 10:45:09 +0300 |
---|---|---|
committer | ivanzhukov <ivanzhukov@ydb.tech> | 2022-08-26 10:45:09 +0300 |
commit | 89cae858a59ecae5378edcd229962b6d1be5e5f8 (patch) | |
tree | 5848d1648d954926c8048c0e9edaa261255aceea /util/network/sock.h | |
parent | af6b0b93037268a9ca1343dd09629cf910c944d9 (diff) | |
download | ydb-89cae858a59ecae5378edcd229962b6d1be5e5f8.tar.gz |
[http/client] Support unix domain sockets as a backend
Предыдущий заход: https://a.yandex-team.ru/review/2811077/details#comment--4489184
После изменений можно будет обращаться к HTTP серверу, слушающему на unix domain socket. Пример такого сервера:
```js
require('http').createServer((req, res) => {
console.log(req);
res.writeHead(200, {'Content-Type': 'application/json'});
res.end(JSON.stringify({
'metrics': [
{
'labels': {
'name': 'metric',
'some_key': 'some_value'
},
'type': 'GAUGE',
'value': 123
}
]
}, null, 4));
})
.listen('/home/ivanzhukov/test_ua/ua.sock');
// вместо .listen(7777);
```
Diffstat (limited to 'util/network/sock.h')
-rw-r--r-- | util/network/sock.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/util/network/sock.h b/util/network/sock.h index b10be2f715..d5ebeccbb0 100644 --- a/util/network/sock.h +++ b/util/network/sock.h @@ -77,6 +77,14 @@ struct TSockAddrLocal: public ISockAddr { strlcpy(Path, path, PathSize); } + inline void Set(TStringBuf path) noexcept { + Clear(); + in.sin_family = AF_INET; + in.sin_addr.s_addr = IpFromString("127.0.0.1"); + in.sin_port = 0; + strlcpy(Path, path.data(), Min(PathSize, path.size() + 1)); + } + sockaddr* SockAddr() { return (struct sockaddr*)(&in); } @@ -148,6 +156,10 @@ struct TSockAddrLocal: public sockaddr_un, public ISockAddr { Clear(); } + TSockAddrLocal(TStringBuf path) { + Set(path); + } + TSockAddrLocal(const char* path) { Set(path); } @@ -170,6 +182,12 @@ struct TSockAddrLocal: public sockaddr_un, public ISockAddr { strlcpy(sun_path, path, sizeof(sun_path)); } + inline void Set(TStringBuf path) noexcept { + Clear(); + sun_family = AF_UNIX; + strlcpy(sun_path, path.data(), Min(sizeof(sun_path), path.size() + 1)); + } + sockaddr* SockAddr() override { return (struct sockaddr*)(struct sockaddr_un*)this; } |