<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">That code is incomplete and not
runnable. What is "[0:netip]" for example? More importantly, what
is "c" when you do c.Write(data) ?<br>
</div>
<p>However, there is also an unstated question here, which is "how
are the requests and responses delimited when PowerDNS using the
unixsock remote backend?" You're just assuming that a Read() and
a Write() are sufficient to delimit messages, and that seems
pretty unlikely to me.<br>
</p>
<p>Now, looking in the Ruby code in
modules/remotebackend/unittest_pipe.rb, it appears that the format
is newline-delimited, i.e. this is <a
href="https://jsonlines.org/">JSON-Lines</a>.</p>
<p>This appears to be confirmed in
modules/remotebackend/pipeconnector.cc<font face="monospace"><br>
</font></p>
<p><font face="monospace">int PipeConnector::send_message(const
Json& input)<br>
{<br>
auto line = input.dump();<br>
launch();<br>
<br>
<b> line.append(1, '\n');</b></font></p>
<p><font face="monospace">...<br>
</font></p>
<p><font face="monospace"> if (!stringfgets(d_fp.get(), receive))
{<br>
throw PDNSException("Child closed pipe");<br>
}</font></p>
<p><font face="monospace">// stringfgets is in pdns/misc.cc, and it
reads up to a newline:</font></p>
<p><font face="monospace"> do {<br>
if(!fgets(buffer, sizeof(buffer), fp))<br>
return !line.empty();<br>
<br>
line.append(buffer);<br>
<b> } while(!strchr(buffer, '\n'));</b><br>
return true;</font></p>
<p>So the main issue seems to be: you need to write a newline after
your JSON response. (And make sure your response *isn't*
pretty-printed, and any embedded newlines in strings are
represented by "\n", so that each JSON object is exactly one line)</p>
<p>Then instead of Read(1024), you need to either read up to a
newline (e.g. using bufio.Scanner or bufio.Reader) - or you need
to use a streaming JSON decoder which will use the end of each
JSON object as the delimiter, and ignores the newlines in between
them. (Go's encoding/json can quite happily do that)<br>
</p>
<p>HTH,</p>
<p>Brian.<br>
</p>
</body>
</html>