<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi, Ross<br>
<br>
When restoring using RPC or Libcriu response message contains
"restored" field set to true,<br>
that help process to detect if it was restored. You say that every
time you restore the connection<br>
is broken, right? So maybe you could utilize "restored" flag?<br>
<br>
Thanks,<br>
Ruslan <br>
<br>
<div class="moz-cite-prefix">On 05/12/2015 09:59 PM, Ross Boucher
wrote:<br>
</div>
<blockquote
cite="mid:CAPVGJRJ8Q-E05qzpgs=Os9zZwi_PycBtOrNtGU5MWvv9mE2bjg@mail.gmail.com"
type="cite">
<div dir="ltr">In order to get support working in my application,
I've resorted to a hack that works but is almost certainly not
the best way to do things. I'm interested if anyone has
suggestions for a better way. First, let me explain how it
works.
<div><br>
</div>
<div>The process I'm checkpointing is a node.js process that
opens a socket, and waits for a connection on that socket.
Once established, the connecting process sends code for the
node.js process to evaluate, in a loop. The node process is
checkpointed between every message containing new code to
evaluate. </div>
<div><br>
</div>
<div>Now, when we restore, it is always a completely new process
sending code to the node.js process, so the built in tcp
socket restoration won't work. We had lots of difficulty
figuring out how to detect that the socket connection had been
broken. Ultimately, the hack we ended up using was to simply
loop forever on a separate thread checking the time, and
noticing if an unexplained huge gap in time had occurred. The
looping thread looks like this:</div>
<div><br>
</div>
<div><br>
</div>
<blockquote style="margin:0px 0px 0px
40px;border:none;padding:0px">
<div>
<div>void * canceler(void * threadPointer)</div>
</div>
<div>
<div>{</div>
</div>
<div>
<div> pthread_t thread = *(pthread_t *)threadPointer;</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> time_t start,end;</div>
</div>
<div>
<div> time(&start);</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> while(true)</div>
</div>
<div>
<div> {</div>
</div>
<div>
<div> usleep(1000);</div>
</div>
<div>
<div> time(&end);</div>
</div>
<div>
<div> double diff = difftime(end,start);</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> if (diff > 1.0) {<br>
</div>
</div>
<div>
<div> // THIS IS ALMOST CERTAINLY A RESTORE</div>
</div>
<div>
<div> break;</div>
</div>
<div>
<div> }</div>
</div>
<div>
<div> }</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> // cancel the read thread<br>
</div>
</div>
</blockquote>
<blockquote style="margin:0px 0px 0px
40px;border:none;padding:0px">
<div>
<div> int result = pthread_cancel(thread);</div>
</div>
<div>
<div><br>
</div>
</div>
<div>
<div> return NULL;</div>
</div>
</blockquote>
<blockquote style="margin:0px 0px 0px
40px;border:none;padding:0px">
<div>
<div>}</div>
</div>
</blockquote>
<div><br>
</div>
<div><br>
</div>
<div>Elsewhere, in the code that actually does the reading, we
spawn this thread with a handle to the read thread:</div>
<div><br>
</div>
<blockquote style="margin:0px 0px 0px
40px;border:none;padding:0px">
<div>
<div>pthread_create(&cancelThread, NULL, canceler, (void
*)readThread);</div>
</div>
</blockquote>
<div><br>
</div>
<div><br>
</div>
<div>The rest of our code understand how to deal with a broken
connection and is able to seamlessly reconnect. This is all
working well, but it seems like there is probably a better way
so I wanted to ask for suggestions. I also tried getting
things to work with a file based socket rather than a TCP
socket, but that proved even more difficult (and was far more
complicated in our architecture anyway, so I'd prefer not to
return down that path).</div>
<div><br>
</div>
<div>- Ross</div>
<div><br>
</div>
<div>[1] From my other email thread, this video might help
illustrate the actual process going on, if my description
isn't that clear: </div>
<div><br>
</div>
<div><a moz-do-not-send="true"
href="https://www.youtube.com/watch?v=F2L6JLFuFWs&feature=youtu.be">https://www.youtube.com/watch?v=F2L6JLFuFWs&feature=youtu.be</a><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
CRIU mailing list
<a class="moz-txt-link-abbreviated" href="mailto:CRIU@openvz.org">CRIU@openvz.org</a>
<a class="moz-txt-link-freetext" href="https://lists.openvz.org/mailman/listinfo/criu">https://lists.openvz.org/mailman/listinfo/criu</a>
</pre>
</blockquote>
<br>
</body>
</html>