diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-19 13:59:39 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-19 13:59:39 +0000 |
commit | 35b25e9f0758fa3d4a2ce3f0ab828ab898ed549d (patch) | |
tree | 220fb4d4e2790048dd2771ddb24ecc7cb67fd332 /src/stream | |
parent | f22ba8fd7e5e514ad29277016ba8759d664cbe6c (diff) | |
download | gnunet-35b25e9f0758fa3d4a2ce3f0ab828ab898ed549d.tar.gz gnunet-35b25e9f0758fa3d4a2ce3f0ab828ab898ed549d.zip |
cleanup write handle upon shutdown
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/stream_api.c | 92 |
1 files changed, 61 insertions, 31 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 24fd8e8f8..b55ae46f0 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -1640,20 +1640,30 @@ handle_transmit_close (struct GNUNET_STREAM_Socket *socket, | |||
1640 | 1640 | ||
1641 | switch (socket->state) | 1641 | switch (socket->state) |
1642 | { | 1642 | { |
1643 | case STATE_ESTABLISHED: | 1643 | case STATE_INIT: |
1644 | socket->state = STATE_RECEIVE_CLOSED; | 1644 | case STATE_LISTEN: |
1645 | /* Send TRANSMIT_CLOSE_ACK */ | 1645 | case STATE_HELLO_WAIT: |
1646 | reply = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1646 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1647 | reply->header.type = | 1647 | "%s: Ignoring RECEIVE_CLOSE as it cannot be handled now\n", |
1648 | htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK); | 1648 | GNUNET_i2s (&socket->other_peer)); |
1649 | reply->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1649 | return GNUNET_OK; |
1650 | queue_message (socket, reply, NULL, NULL, GNUNET_NO); | ||
1651 | break; | ||
1652 | default: | 1650 | default: |
1653 | /* FIXME: Call statistics? */ | ||
1654 | break; | 1651 | break; |
1655 | } | 1652 | } |
1656 | return GNUNET_YES; | 1653 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received TRANSMIT_CLOSE from %s\n", |
1654 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); | ||
1655 | socket->receive_closed = GNUNET_YES; | ||
1656 | if (GNUNET_YES == socket->transmit_closed) | ||
1657 | socket->state = STATE_CLOSED; | ||
1658 | else | ||
1659 | socket->state = STATE_RECEIVE_CLOSED; | ||
1660 | /* Send TRANSMIT_CLOSE_ACK */ | ||
1661 | reply = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | ||
1662 | reply->header.type = | ||
1663 | htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK); | ||
1664 | reply->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | ||
1665 | queue_message (socket, reply, NULL, NULL, GNUNET_NO); | ||
1666 | return GNUNET_OK; | ||
1657 | } | 1667 | } |
1658 | 1668 | ||
1659 | 1669 | ||
@@ -1734,7 +1744,7 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1734 | shutdown_handle = socket->shutdown_handle; | 1744 | shutdown_handle = socket->shutdown_handle; |
1735 | if (NULL == shutdown_handle) | 1745 | if (NULL == shutdown_handle) |
1736 | { | 1746 | { |
1737 | /* This happens when the shudown handle is cancelled */ | 1747 | /* This may happen when the shudown handle is cancelled */ |
1738 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1748 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1739 | "%s: Received CLOSE_ACK when shutdown handle is NULL\n", | 1749 | "%s: Received CLOSE_ACK when shutdown handle is NULL\n", |
1740 | GNUNET_i2s (&socket->other_peer)); | 1750 | GNUNET_i2s (&socket->other_peer)); |
@@ -1759,7 +1769,7 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1759 | break; | 1769 | break; |
1760 | default: | 1770 | default: |
1761 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1771 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1762 | "%s: Received CLOSE_ACK when in it not expected\n", | 1772 | "%s: Received CLOSE_ACK when it is not expected\n", |
1763 | GNUNET_i2s (&socket->other_peer)); | 1773 | GNUNET_i2s (&socket->other_peer)); |
1764 | return GNUNET_OK; | 1774 | return GNUNET_OK; |
1765 | } | 1775 | } |
@@ -1781,7 +1791,7 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1781 | break; | 1791 | break; |
1782 | default: | 1792 | default: |
1783 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1793 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1784 | "%s: Received RECEIVE_CLOSE_ACK when in it not expected\n", | 1794 | "%s: Received RECEIVE_CLOSE_ACK when it is not expected\n", |
1785 | GNUNET_i2s (&socket->other_peer)); | 1795 | GNUNET_i2s (&socket->other_peer)); |
1786 | return GNUNET_OK; | 1796 | return GNUNET_OK; |
1787 | } | 1797 | } |
@@ -1804,7 +1814,7 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1804 | break; | 1814 | break; |
1805 | default: | 1815 | default: |
1806 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1816 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1807 | "%s: Received TRANSMIT_CLOSE_ACK when in it not expected\n", | 1817 | "%s: Received TRANSMIT_CLOSE_ACK when it is not expected\n", |
1808 | GNUNET_i2s (&socket->other_peer)); | 1818 | GNUNET_i2s (&socket->other_peer)); |
1809 | return GNUNET_OK; | 1819 | return GNUNET_OK; |
1810 | } | 1820 | } |
@@ -1889,23 +1899,31 @@ handle_receive_close (struct GNUNET_STREAM_Socket *socket, | |||
1889 | return GNUNET_OK; | 1899 | return GNUNET_OK; |
1890 | default: | 1900 | default: |
1891 | break; | 1901 | break; |
1892 | } | 1902 | } |
1893 | 1903 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received RECEIVE_CLOSE from %s\n", | |
1894 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1904 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); |
1895 | "%s: Received RECEIVE_CLOSE from %s\n", | 1905 | socket->transmit_closed = GNUNET_YES; |
1896 | GNUNET_i2s (&socket->other_peer), | 1906 | if (GNUNET_YES == socket->receive_closed) |
1897 | GNUNET_i2s (&socket->other_peer)); | 1907 | socket->state = STATE_CLOSED; |
1908 | else | ||
1909 | socket->state = STATE_TRANSMIT_CLOSED; | ||
1898 | receive_close_ack = | 1910 | receive_close_ack = |
1899 | GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1911 | GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); |
1900 | receive_close_ack->header.size = | 1912 | receive_close_ack->header.size = |
1901 | htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1913 | htons (sizeof (struct GNUNET_STREAM_MessageHeader)); |
1902 | receive_close_ack->header.type = | 1914 | receive_close_ack->header.type = |
1903 | htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK); | 1915 | htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK); |
1904 | queue_message (socket, receive_close_ack, &set_state_closed, | 1916 | queue_message (socket, receive_close_ack, NULL, NULL, GNUNET_NO); |
1905 | NULL, GNUNET_NO); | 1917 | /* If write handle is present call it with GNUNET_STREAM_SHUTDOWN to signal |
1906 | /* FIXME: Handle the case where write handle is present; the write operation | 1918 | that that stream has been shutdown */ |
1907 | should be deemed as finised and the write continuation callback | 1919 | if (NULL != socket->write_handle) |
1908 | has to be called with the stream status GNUNET_STREAM_SHUTDOWN */ | 1920 | { |
1921 | if (NULL != socket->write_handle->write_cont) | ||
1922 | socket->write_handle->write_cont (socket->write_handle->write_cont_cls, | ||
1923 | GNUNET_STREAM_SHUTDOWN, 0); | ||
1924 | GNUNET_STREAM_io_write_cancel (socket->write_handle); | ||
1925 | socket->write_handle = NULL; | ||
1926 | } | ||
1909 | return GNUNET_OK; | 1927 | return GNUNET_OK; |
1910 | } | 1928 | } |
1911 | 1929 | ||
@@ -2005,10 +2023,8 @@ handle_close (struct GNUNET_STREAM_Socket *socket, | |||
2005 | default: | 2023 | default: |
2006 | break; | 2024 | break; |
2007 | } | 2025 | } |
2008 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2026 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received CLOSE from %s\n", |
2009 | "%s: Received CLOSE from %s\n", | 2027 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); |
2010 | GNUNET_i2s (&socket->other_peer), | ||
2011 | GNUNET_i2s (&socket->other_peer)); | ||
2012 | close_ack = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 2028 | close_ack = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); |
2013 | close_ack->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 2029 | close_ack->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); |
2014 | close_ack->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK); | 2030 | close_ack->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK); |
@@ -2019,7 +2035,17 @@ handle_close (struct GNUNET_STREAM_Socket *socket, | |||
2019 | socket->transmit_closed = GNUNET_YES; | 2035 | socket->transmit_closed = GNUNET_YES; |
2020 | GNUNET_free_non_null (socket->receive_buffer); /* Free the receive buffer */ | 2036 | GNUNET_free_non_null (socket->receive_buffer); /* Free the receive buffer */ |
2021 | socket->receive_buffer = NULL; | 2037 | socket->receive_buffer = NULL; |
2022 | socket->receive_buffer_size = 0; | 2038 | socket->receive_buffer_size = 0; |
2039 | /* If write handle is present call it with GNUNET_STREAM_SHUTDOWN to signal | ||
2040 | that that stream has been shutdown */ | ||
2041 | if (NULL != socket->write_handle) | ||
2042 | { | ||
2043 | if (NULL != socket->write_handle->write_cont) | ||
2044 | socket->write_handle->write_cont (socket->write_handle->write_cont_cls, | ||
2045 | GNUNET_STREAM_SHUTDOWN, 0); | ||
2046 | GNUNET_STREAM_io_write_cancel (socket->write_handle); | ||
2047 | socket->write_handle = NULL; | ||
2048 | } | ||
2023 | return GNUNET_OK; | 2049 | return GNUNET_OK; |
2024 | } | 2050 | } |
2025 | 2051 | ||
@@ -3101,6 +3127,7 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3101 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE); | 3127 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE); |
3102 | queue_message (socket, msg, &set_state_receive_close_wait, NULL, | 3128 | queue_message (socket, msg, &set_state_receive_close_wait, NULL, |
3103 | GNUNET_NO); | 3129 | GNUNET_NO); |
3130 | socket->receive_closed = GNUNET_YES; | ||
3104 | break; | 3131 | break; |
3105 | case SHUT_WR: | 3132 | case SHUT_WR: |
3106 | handle->operation = SHUT_WR; | 3133 | handle->operation = SHUT_WR; |
@@ -3111,6 +3138,7 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3111 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE); | 3138 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE); |
3112 | queue_message (socket, msg, &set_state_transmit_close_wait, NULL, | 3139 | queue_message (socket, msg, &set_state_transmit_close_wait, NULL, |
3113 | GNUNET_NO); | 3140 | GNUNET_NO); |
3141 | socket->transmit_closed = GNUNET_YES; | ||
3114 | break; | 3142 | break; |
3115 | case SHUT_RDWR: | 3143 | case SHUT_RDWR: |
3116 | handle->operation = SHUT_RDWR; | 3144 | handle->operation = SHUT_RDWR; |
@@ -3124,6 +3152,8 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3124 | " down reading\n"); | 3152 | " down reading\n"); |
3125 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE); | 3153 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE); |
3126 | queue_message (socket, msg, &set_state_close_wait, NULL, GNUNET_NO); | 3154 | queue_message (socket, msg, &set_state_close_wait, NULL, GNUNET_NO); |
3155 | socket->transmit_closed = GNUNET_YES; | ||
3156 | socket->receive_closed = GNUNET_YES; | ||
3127 | break; | 3157 | break; |
3128 | default: | 3158 | default: |
3129 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3159 | LOG (GNUNET_ERROR_TYPE_WARNING, |