<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 23, 2018 at 3:06 AM, Liam Kelly <span dir="ltr"><<a href="mailto:liamkelly17@gmail.com" target="_blank">liamkelly17@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="#954F72"><div class="m_675736588365373071WordSection1"><p class="MsoNormal">How does Systemd communicate to socket activated application that the connection has been closed? How can I modify my application to detect this event if it cannot be configured to be closed automatically?</p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">We are trying to add network support to legacy code using Systemd sockets. Using the 0pointer tutorials, we were able to configure a listening TCP port and launch an instance of the application when a TCP connection came in. The problem is that when the connection is closed, the service is still running.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">The systemct list-units and netstat -tuapn outputs are what you would expect when the connection is established<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">    systemctl list-units:<u></u><u></u></p><p class="MsoNormal">    myapp@5-192.168.0.75:10001-<wbr>192.168.210.102:19983.service loaded active running   My App<u></u><u></u></p><p class="MsoNormal">    netstat -tuapn:<u></u><u></u></p><p class="MsoNormal">    tcp        0      0 <a href="http://192.168.0.75:10001" target="_blank">192.168.0.75:10001</a>      <a href="http://192.168.210.102:19983" target="_blank">192.168.210.102:19983</a>   ESTABLISHED 1/init<u></u><u></u></p><p class="MsoNormal">However, once the client closes the connection, the socket is closed and removed, but the application is still running as a service:</p></div></div></blockquote><div><br></div><div>It is no different from any other type of networked service. Whether you opened the socket yourself, or received it from a superserver, makes no difference.</div><div><br></div><div>For example, if your program uses poll(), the kernel reports POLLHUP on a closed socket. If the program uses read() or recv(), 0 bytes indicates that the socket is closed. If the program uses simple stdio (inetd style), it's enough to check for EOF on reads from stdin.</div></div><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div>
</div></div>