Skip to content

Commit

Permalink
Move localsocket up out of generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
GothAck committed Mar 13, 2020
1 parent 0316fe3 commit b0d7d7d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
18 changes: 1 addition & 17 deletions compiler/flatrpcc_inja/flatrpc.cpp.inja
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ using namespace flatrpc::rpc;
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

struct LocalSocket : zmqpp::socket {
LocalSocket(zmqpp::context &ctx, zmqpp::socket_type type) : zmqpp::socket(ctx, type) {
connect("inproc://frontend");
}
~LocalSocket() {
disconnect("inproc://frontend");
}
};

## for service in services

## for call in service.calls
Expand Down Expand Up @@ -130,9 +121,7 @@ void {{ service.nameClient }}::makeRequest(
TRequestVar req,
TResponsePromiseVar &&resProm
) {
thread_local LocalSocket socket(_context, zmqpp::socket_type::dealer);

auto buf = packInt(
RpcClientBase::makeRequest(
nextRequestId(move(resProm), callName),
RPCType::CLIENT_REQ,
callName,
Expand All @@ -149,11 +138,6 @@ void {{ service.nameClient }}::makeRequest(
## endfor
}, req)
);

zmqpp::message msg;
msg << "";
msg << buf;
socket.send(msg);
}

## endfor
9 changes: 9 additions & 0 deletions rpc/rpcclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ inline bool coinflip(float occ) {
return rand() < (RAND_MAX * occ);
}

struct LocalSocket : zmqpp::socket {
LocalSocket(zmqpp::context &ctx, zmqpp::socket_type type) : zmqpp::socket(ctx, type) {
connect("inproc://frontend");
}
~LocalSocket() {
disconnect("inproc://frontend");
}
};

RpcClientBase::RpcClientBase(zmqpp::context &ctx) :
RpcBase(ctx, zmqpp::socket_type::dealer)
{}
Expand Down

0 comments on commit b0d7d7d

Please sign in to comment.