Skip to content
Snippets Groups Projects
Unverified Commit 554c4906 authored by Bensong Liu's avatar Bensong Liu
Browse files

fix some error

parent cc56a20b
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ constexpr size_t DGRAM_BUFFER_SIZE = 20480;
// to the real openvpn server.
constexpr size_t SERVER_ENCRYPT_CONNECTION_TIMEOUT_SECONDS = 60;
// MAGIC PORT NUMBER! Warning!
// MAGIC PORT NUMBER! Warning! Used for Inbound - Outbound IPC talking. Windows wepoll doesn't support PIPE, so I have to use this.
constexpr uint16_t TCP_TMP_PORT_NUMBER = 50999;
#endif
......
......@@ -30,6 +30,11 @@ public:
if (ptrOutbound) delete ptrOutbound;
}
[[noreturn]] void runForever() {
std::thread([this] {ptrInbound->listenForever(ptrOutbound);}).detach();
ptrOutbound->listenForever(ptrInbound); // Blocks
}
private:
Protocols::BaseInbound *ptrInbound;
......
......@@ -504,6 +504,11 @@ namespace rlib {
currvptr = (char *)vptr + current / 2;
}
}
static void close_ex(sockfd_t fd) {
if (closesocket(fd) == SOCKET_ERROR) {
throw std::runtime_error("closeSocket failed. error code: " + std::to_string(WSAGetLastError()));
}
}
#else
// POSIX sockIO
public:
......@@ -589,6 +594,11 @@ namespace rlib {
currvptr = (char *)vptr + current / 2;
}
}
static void close_ex(sockfd_t fd) {
if (close(fd) == -1) {
throw std::runtime_error("close failed. error code: " + std::to_string(errno));
}
}
#endif
#ifndef MSG_NOSIGNAL
......
......@@ -11,6 +11,9 @@ using namespace std::chrono_literals;
#if RLIB_OS_ID == OS_WINDOWS
#define windows_main main
#ifdef ERROR
#undef ERROR
#endif
#else
#define real_main main
#endif
......@@ -39,7 +42,7 @@ int real_main(int argc, char **argv) {
else
throw std::runtime_error("Unknown log level: " + log_level);
Forwarder(inboundConfig, outboundConfig).run_forever();
Forwarder(inboundConfig, outboundConfig).runForever();
return 0;
}
......
......@@ -16,6 +16,8 @@ User
*/
namespace Protocols {
struct BaseInbound;
// Outbound holds the senderId=>nextHopFd mapping.
// senderId is "$ip@$port", for example, `fe80:8100::1@1080`.
// Note: this interface works for both TCP and UDP.
......
......@@ -20,14 +20,14 @@ namespace Protocols {
}
virtual void forwardMessageToOutbound(string binaryMessage, string senderId) override {
// Outbound calls this function, to alert the inbound listener thread, for the new msg.
rlib::sockIO::send_msg(ipcPipe, senderId);
rlib::sockIO::send_msg(ipcPipe, binaryMessage);
}
virtual void listenForever(BaseOutbound* nextHop) override {
std::tie(this->ipcPipe, nextHop->ipcPipe) = mk_tcp_pipe();
auto listenFd = rlib::quick_listen(listenAddr, listenPort, true);
rlib_defer([&] {close(listenFd);});
rlib_defer([&] {rlib::sockIO::close_ex(listenFd);});
auto epollFd = epoll_create1(0);
dynamic_assert((int)epollFd != -1, "epoll_create1 failed");
......
......@@ -13,6 +13,9 @@
#include <wepoll.h>
#endif
#include <string>
using std::string;
struct SockAddr {
union {
sockaddr_storage addr_storage;
......@@ -20,7 +23,7 @@ struct SockAddr {
sockaddr_in in4;
sockaddr_in6 in6;
};
int len;
socklen_t len;
};
struct ConnectionMapping {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment