diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-07-02 21:05:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-07-02 21:05:43 +0000 |
commit | ba9c0e16195d8468f0a9c080e658f3d3f2131c6a (patch) | |
tree | d5ca467343b4f85b04474de784c63b479262831e /src/util/connection.c | |
parent | 3951bd96d608ab0f88ccb5a7b4b7e94e15d91a89 (diff) | |
download | gnunet-ba9c0e16195d8468f0a9c080e658f3d3f2131c6a.tar.gz gnunet-ba9c0e16195d8468f0a9c080e658f3d3f2131c6a.zip |
fixing calculations and code for buffer realloc
Diffstat (limited to 'src/util/connection.c')
-rw-r--r-- | src/util/connection.c | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/src/util/connection.c b/src/util/connection.c index e8a7453d2..57720c07e 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -1586,27 +1586,14 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle | |||
1586 | GNUNET_CONNECTION_TransmitReadyNotify | 1586 | GNUNET_CONNECTION_TransmitReadyNotify |
1587 | notify, void *notify_cls) | 1587 | notify, void *notify_cls) |
1588 | { | 1588 | { |
1589 | size_t temp_size; | ||
1590 | #if !REALLOC | ||
1591 | char *temp_buf; | ||
1592 | #endif | ||
1593 | if (sock->nth.notify_ready != NULL) | 1589 | if (sock->nth.notify_ready != NULL) |
1594 | return NULL; | 1590 | return NULL; |
1595 | GNUNET_assert (notify != NULL); | 1591 | GNUNET_assert (notify != NULL); |
1596 | if ((sock->write_buffer_size < size) && (size < GNUNET_SERVER_MAX_MESSAGE_SIZE)) | 1592 | GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
1593 | if (sock->write_buffer_size < size) | ||
1597 | { | 1594 | { |
1598 | temp_size = sock->write_buffer_size + size + 1; | 1595 | sock->write_buffer = GNUNET_realloc(sock->write_buffer, size); |
1599 | if (temp_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1596 | sock->write_buffer_size = size; |
1600 | temp_size = GNUNET_SERVER_MAX_MESSAGE_SIZE; | ||
1601 | #if REALLOC | ||
1602 | sock->write_buffer = GNUNET_realloc(sock->write_buffer, temp_size); | ||
1603 | #else | ||
1604 | temp_buf = GNUNET_malloc(temp_size); | ||
1605 | memcpy(temp_buf, sock->write_buffer, sock->write_buffer_size); | ||
1606 | GNUNET_free(sock->write_buffer); | ||
1607 | sock->write_buffer = temp_buf; | ||
1608 | #endif | ||
1609 | sock->write_buffer_size = temp_size; | ||
1610 | } | 1597 | } |
1611 | GNUNET_assert (sock->write_buffer_size >= size); | 1598 | GNUNET_assert (sock->write_buffer_size >= size); |
1612 | GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); | 1599 | GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size); |