]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Correct handling of closed TCP connections in proto_inet
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 27 May 2009 18:33:14 +0000 (20:33 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 27 May 2009 20:30:48 +0000 (22:30 +0200)
In FRSH_FORB this allows restarting resource managers without restart of fcb.
The problem of previous implementation was, that if the socket was closed but
peer structure was not unregistered the disconnected peer structure stored
fd of closed socket and when a new connection was made, the fd was the same
as stored in disconnected peer structure. Therefore the disconnected peer
appeared as alive.

src/proto_inet.c

index a77da0ce1add7f72f3577a21c55e1357133402ea..1da3605d0987a9abdc47703db5b98b5be0c62f19 100644 (file)
@@ -362,8 +362,13 @@ inet_recv(forb_port_t *port, void *buf, size_t len)
                                port->new_peer = NULL;
                        }
                        ul_logdeb("recv fd=%d disconnect\n", iport->last_recv_fd);
-                       close(iport->last_recv_fd);
-                       /* TODO: Notify FORB about peer disconnect */
+                       ul_list_for_each(forb_port_peer, port, peer) {
+                               struct inet_peer *ipeer = peer->proto_priv;
+                               if (ipeer && ipeer->socket == iport->last_recv_fd) {
+                                       forb_peer_disconnected(peer);
+                                       break;
+                               }
+                       }
                        iport->last_recv_fd = -1;
                        continue;
                }
@@ -408,6 +413,7 @@ inet_peer_destroy(forb_peer_t *peer)
        struct inet_peer *ipeer = peer->proto_priv;
        if (ipeer) {
                peer->proto_priv = NULL;
+               ul_logdeb("destroying peer fd=%d\n", ipeer->socket);
                close(ipeer->socket);
                free(ipeer);
        }