forked from facebookincubator/gloo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create libuv transport (facebookincubator#212)
Summary: Pull Request resolved: facebookincubator#212 This transport is largely modeled after the existing TCP transport. There is no support for the old style and only for the new style algorithms (there are no createSendBuffer/createRecvBuffer functions). This commit adds the basic functionality but more work is needed to properly deal with errors and timeouts. It requires libuv to be available. Either it should already be defined as a build target, if included by another project's build, or it must be installed and discoverable through pkg-config. Test Plan: Imported from OSS Reviewed By: mrshenli Differential Revision: D17072672 Pulled By: pietern fbshipit-source-id: 6594a8a580596e86253b3d8783978c40fafef373
- Loading branch information
1 parent
767c232
commit 5afa358
Showing
23 changed files
with
3,176 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
list(APPEND GLOO_TRANSPORT_SRCS | ||
"${CMAKE_CURRENT_SOURCE_DIR}/address.cc" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/device.cc" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/context.cc" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/libuv.cc" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/pair.cc" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/unbound_buffer.cc" | ||
) | ||
list(APPEND GLOO_TRANSPORT_HDRS | ||
"${CMAKE_CURRENT_SOURCE_DIR}/address.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/device.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/context.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/libuv.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/pair.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/unbound_buffer.h" | ||
) | ||
|
||
set(GLOO_TRANSPORT_SRCS ${GLOO_TRANSPORT_SRCS} PARENT_SCOPE) | ||
set(GLOO_TRANSPORT_HDRS ${GLOO_TRANSPORT_HDRS} PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016-2019 Michele Caini | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copy of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copy or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Copyright (c) 2019-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <gloo/transport/uv/address.h> | ||
|
||
#include <string.h> | ||
|
||
#include <uv.h> | ||
|
||
#include <gloo/common/logging.h> | ||
|
||
namespace gloo { | ||
namespace transport { | ||
namespace uv { | ||
|
||
Address::Address(struct sockaddr_storage ss, sequence_type seq) { | ||
impl_.ss = std::move(ss); | ||
impl_.seq = seq; | ||
} | ||
|
||
Address::Address(const std::vector<char>& bytes) { | ||
GLOO_ENFORCE_EQ(sizeof(impl_), bytes.size()); | ||
memcpy(&impl_, bytes.data(), sizeof(impl_)); | ||
} | ||
|
||
std::vector<char> Address::bytes() const { | ||
std::vector<char> bytes(sizeof(impl_)); | ||
memcpy(bytes.data(), &impl_, sizeof(impl_)); | ||
return bytes; | ||
} | ||
|
||
std::string Address::str() const { | ||
char str[INET6_ADDRSTRLEN + 128]; | ||
int port = 0; | ||
|
||
str[0] = '['; | ||
if (impl_.ss.ss_family == AF_INET) { | ||
auto in = (struct sockaddr_in*)&impl_.ss; | ||
uv_ip4_name(in, str + 1, sizeof(str) - 1); | ||
port = in->sin_port; | ||
} else if (impl_.ss.ss_family == AF_INET6) { | ||
auto in6 = (struct sockaddr_in6*)&impl_.ss; | ||
uv_ip6_name(in6, str + 1, sizeof(str) - 1); | ||
port = in6->sin6_port; | ||
} else { | ||
snprintf(str + 1, sizeof(str) - 1, "none"); | ||
} | ||
|
||
size_t len = strlen(str); | ||
if (port > 0) { | ||
len += snprintf(str + len, sizeof(str) - len, "]:%d", port); | ||
} else { | ||
len += snprintf(str + len, sizeof(str) - len, "]"); | ||
} | ||
|
||
// Append sequence number if one is set. | ||
if (impl_.seq != SIZE_MAX) { | ||
len += snprintf(str + len, sizeof(str) - len, "$%d", impl_.seq); | ||
} | ||
|
||
return str; | ||
} | ||
|
||
} // namespace uv | ||
} // namespace transport | ||
} // namespace gloo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright (c) 2019-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <sys/socket.h> | ||
|
||
#include <gloo/transport/address.h> | ||
|
||
namespace gloo { | ||
namespace transport { | ||
namespace uv { | ||
|
||
class Address : public ::gloo::transport::Address { | ||
public: | ||
using sequence_type = int; | ||
|
||
Address() {} | ||
|
||
Address(struct sockaddr_storage ss, sequence_type seq = -1); | ||
|
||
explicit Address(const std::vector<char>&); | ||
|
||
virtual std::vector<char> bytes() const override; | ||
|
||
virtual std::string str() const override; | ||
|
||
const struct sockaddr_storage& getSockaddr() const { | ||
return impl_.ss; | ||
} | ||
|
||
sequence_type getSeq() const { | ||
return impl_.seq; | ||
} | ||
|
||
Address withSeq(sequence_type seq) const { | ||
return Address(impl_.ss, seq); | ||
} | ||
|
||
protected: | ||
// Encapsulate fields such that it is trivially copyable. This class | ||
// is not trivially copyable itself (because it is a subclass?). | ||
struct Impl { | ||
// IP address of the listening socket. | ||
struct sockaddr_storage ss; | ||
|
||
// Sequence number of this address. | ||
// If this is equal to -1, the address is assumed to | ||
// represent the listening socket of a device. The sequence number | ||
// must be set before it can be used by a pair. | ||
sequence_type seq = -1; | ||
}; | ||
|
||
static_assert(std::is_trivially_copyable<Impl>::value, "!"); | ||
|
||
Impl impl_; | ||
}; | ||
|
||
} // namespace uv | ||
} // namespace transport | ||
} // namespace gloo |
Oops, something went wrong.