-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* release: v3.4.3
- Loading branch information
Showing
27 changed files
with
323 additions
and
89 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
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,79 @@ | ||
#include "unix_socket.hpp" | ||
#include <arpa/inet.h> | ||
#include <netdb.h> | ||
#include <netinet/in.h> | ||
#include <stdexcept> | ||
#include <sys/socket.h> | ||
#include <unistd.h> | ||
|
||
namespace interface { | ||
|
||
UnixSocketInterface::UnixSocketInterface(std::string path, bool reconnect) IF_NOEXCEPT | ||
: mPath(std::move(path)), | ||
mReconnect(reconnect) {} | ||
|
||
UnixSocketInterface::~UnixSocketInterface() IF_NOEXCEPT { | ||
close(); | ||
} | ||
|
||
void UnixSocketInterface::open() { | ||
if (mSocket.is_open()) { | ||
return; | ||
} | ||
|
||
auto address = NetworkAddress::unix_socket_stream(mPath); | ||
mSocket = ReconnectableSocket::connect(address, mReconnect); | ||
if (!mSocket.is_open()) { | ||
throw std::runtime_error("Failed to connect to unix socket: '" + mPath + "'"); | ||
} | ||
} | ||
|
||
void UnixSocketInterface::close() { | ||
mSocket.close(); | ||
} | ||
|
||
size_t UnixSocketInterface::read(void* data, const size_t size) { | ||
return mSocket.read(data, size); | ||
} | ||
|
||
size_t UnixSocketInterface::write(const void* data, const size_t size) { | ||
return mSocket.write(data, size); | ||
} | ||
|
||
bool UnixSocketInterface::can_read() IF_NOEXCEPT { | ||
return mSocket.can_read(); | ||
} | ||
|
||
bool UnixSocketInterface::can_write() IF_NOEXCEPT { | ||
return mSocket.can_write(); | ||
} | ||
|
||
void UnixSocketInterface::wait_for_read() IF_NOEXCEPT { | ||
mSocket.wait_for_read(); | ||
} | ||
|
||
void UnixSocketInterface::wait_for_write() IF_NOEXCEPT { | ||
mSocket.wait_for_write(); | ||
} | ||
|
||
bool UnixSocketInterface::is_open() IF_NOEXCEPT { | ||
return mSocket.is_open(); | ||
} | ||
|
||
void UnixSocketInterface::print_info() IF_NOEXCEPT { | ||
printf("[interface]\n"); | ||
printf(" type: unix-socket (stream)\n"); | ||
printf(" path: %s\n", mPath.c_str()); | ||
printf(" reconnect: %s\n", mReconnect ? "true" : "false"); | ||
mSocket.print_info(); | ||
} | ||
|
||
// | ||
// | ||
// | ||
|
||
Interface* Interface::unix_socket_stream(std::string path, bool reconnect) { | ||
return new UnixSocketInterface(std::move(path), reconnect); | ||
} | ||
|
||
} // namespace interface |
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,35 @@ | ||
#pragma once | ||
#include <cstddef> | ||
#include <string> | ||
#include "interface.hpp" | ||
#include "reconnectable_socket.hpp" | ||
|
||
namespace interface { | ||
|
||
class UnixSocketInterface final : public Interface { | ||
public: | ||
explicit UnixSocketInterface(std::string path, bool reconnect) IF_NOEXCEPT; | ||
~UnixSocketInterface() IF_NOEXCEPT override; | ||
|
||
void open() override; | ||
void close() override; | ||
|
||
size_t read(void* data, size_t length) override; | ||
size_t write(const void* data, size_t length) override; | ||
|
||
IF_NODISCARD bool can_read() IF_NOEXCEPT override; | ||
IF_NODISCARD bool can_write() IF_NOEXCEPT override; | ||
|
||
void wait_for_read() IF_NOEXCEPT override; | ||
void wait_for_write() IF_NOEXCEPT override; | ||
|
||
IF_NODISCARD bool is_open() IF_NOEXCEPT override; | ||
void print_info() IF_NOEXCEPT override; | ||
|
||
private: | ||
std::string mPath; | ||
bool mReconnect; | ||
ReconnectableSocket mSocket; | ||
}; | ||
|
||
} // namespace interface |
Oops, something went wrong.