-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
119 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
#ifndef SIMPLE_SOCKET_SOCKET_HPP | ||
#define SIMPLE_SOCKET_SOCKET_HPP | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace simple_socket { | ||
|
||
class SocketConnection { | ||
public: | ||
virtual int read(std::vector<unsigned char>& buffer) = 0; | ||
|
||
virtual int read(unsigned char* buffer, size_t size) = 0; | ||
|
||
virtual bool readExact(std::vector<unsigned char>& buffer) = 0; | ||
|
||
virtual bool readExact(unsigned char* buffer, size_t size) = 0; | ||
|
||
virtual bool write(const std::string& message) = 0; | ||
|
||
virtual bool write(const std::vector<unsigned char>& data) = 0; | ||
|
||
virtual void close() = 0; | ||
|
||
virtual ~SocketConnection() = default; | ||
}; | ||
|
||
class Socket: public SocketConnection { | ||
public: | ||
Socket(); | ||
|
||
int read(std::vector<unsigned char>& buffer) override; | ||
|
||
int read(unsigned char* buffer, size_t size) override; | ||
|
||
bool readExact(std::vector<unsigned char>& buffer) override; | ||
|
||
bool readExact(unsigned char* buffer, size_t size) override; | ||
|
||
bool write(const std::string& message) override; | ||
|
||
bool write(const std::vector<unsigned char>& data) override; | ||
|
||
void close() override; | ||
|
||
~Socket() override; | ||
|
||
protected: | ||
struct Impl; | ||
std::unique_ptr<Impl> pimpl_; | ||
}; | ||
|
||
}// namespace simple_socket | ||
|
||
#endif//SIMPLE_SOCKET_SOCKET_HPP |
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,23 @@ | ||
|
||
#ifndef SIMPLE_SOCKET_UNIXDOMAINSOCKET_HPP | ||
#define SIMPLE_SOCKET_UNIXDOMAINSOCKET_HPP | ||
|
||
#include "simple_socket/Socket.hpp" | ||
|
||
namespace simple_socket { | ||
|
||
class UnixDomainClient: public Socket { | ||
public: | ||
bool connect(const std::string& domain); | ||
}; | ||
|
||
class UnixDomainServer: public Socket { | ||
public: | ||
explicit UnixDomainServer(const std::string& domain, int backlog = 1); | ||
|
||
std::unique_ptr<SocketConnection> accept(); | ||
}; | ||
|
||
}// namespace simple_socket | ||
|
||
#endif//SIMPLE_SOCKET_UNIXDOMAINSOCKET_HPP |
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
Oops, something went wrong.