size_t bytesLeft;
uint32_t offset = 0;
tr_bool success = TRUE;
- uint8_t buffer[MAX_STACK_ARRAY_SIZE];
- const size_t buflen = MAX_STACK_ARRAY_SIZE;
+ uint8_t * buffer = tr_sessionGetBuffer( tor->session );
+ const size_t buflen = SESSION_BUFFER_SIZE;
SHA_CTX sha;
assert( tor != NULL );
if( success )
SHA1_Final( setme, &sha );
+ tr_sessionReleaseBuffer( tor->session );
return success;
}
#include "list.h"
#include "net.h"
#include "peer-io.h"
-#include "platform.h" /* MAX_STACK_ARRAY_SIZE */
#include "trevent.h" /* tr_runInEventThread() */
#include "utils.h"
case PEER_ENCRYPTION_RC4:
{
/* FIXME(libevent2): use evbuffer_reserve_space() and evbuffer_commit_space() instead of tmp */
- uint8_t tmp[MAX_STACK_ARRAY_SIZE];
+ void * tmp = tr_sessionGetBuffer( io->session );
+ const size_t tmplen = SESSION_BUFFER_SIZE;
const uint8_t * walk = bytes;
evbuffer_expand( io->outbuf, byteCount );
while( byteCount > 0 )
{
- const size_t thisPass = MIN( byteCount, sizeof( tmp ) );
+ const size_t thisPass = MIN( byteCount, tmplen );
tr_cryptoEncrypt( io->crypto, thisPass, walk, tmp );
evbuffer_add( io->outbuf, tmp, thisPass );
walk += thisPass;
byteCount -= thisPass;
}
+ tr_sessionReleaseBuffer( io->session );
break;
}
struct evbuffer * inbuf,
size_t byteCount )
{
- uint8_t tmp[MAX_STACK_ARRAY_SIZE];
+ void * buf = tr_sessionGetBuffer( io->session );
+ const size_t buflen = SESSION_BUFFER_SIZE;
while( byteCount > 0 )
{
- const size_t thisPass = MIN( byteCount, sizeof( tmp ) );
- tr_peerIoReadBytes( io, inbuf, tmp, thisPass );
+ const size_t thisPass = MIN( byteCount, buflen );
+ tr_peerIoReadBytes( io, inbuf, buf, thisPass );
byteCount -= thisPass;
}
+
+ tr_sessionReleaseBuffer( io->session );
}
/***
#include "peer-io.h"
#include "peer-mgr.h"
#include "peer-msgs.h"
-#include "platform.h" /* MAX_STACK_ARRAY_SIZE */
#include "session.h"
#include "stats.h"
#include "torrent.h"
const size_t nLeft = req->length - EVBUFFER_LENGTH( msgs->incoming.block );
size_t n = MIN( nLeft, inlen );
size_t i = n;
+ void * buf = tr_sessionGetBuffer( getSession( msgs ) );
+ const size_t buflen = SESSION_BUFFER_SIZE;
while( i > 0 )
{
- uint8_t buf[MAX_STACK_ARRAY_SIZE];
- const size_t thisPass = MIN( i, sizeof( buf ) );
+ const size_t thisPass = MIN( i, buflen );
tr_peerIoReadBytes( msgs->peer->io, inbuf, buf, thisPass );
evbuffer_add( msgs->incoming.block, buf, thisPass );
i -= thisPass;
}
+ tr_sessionReleaseBuffer( getSession( msgs ) );
+ buf = NULL;
+
fireClientGotData( msgs, n, TRUE );
*setme_piece_bytes_read += n;
dbgmsg( msgs, "got %zu bytes for block %u:%u->%u ... %d remain",
#define MAX_PATH_LENGTH 2048
#endif
-#define MAX_STACK_ARRAY_SIZE 7168
-
/**
* @addtogroup tr_session Session
* @{
session->lock = tr_lockNew( );
session->tag = tr_strdup( tag );
session->magicNumber = SESSION_MAGIC_NUMBER;
+ session->buffer = tr_valloc( SESSION_BUFFER_SIZE );
tr_bencInitList( &session->removedTorrents, 0 );
/* nice to start logging at the very beginning */
****
***/
+void*
+tr_sessionGetBuffer( tr_session * session )
+{
+ assert( tr_isSession( session ) );
+ assert( !session->bufferInUse );
+ assert( tr_amInEventThread( session ) );
+
+ session->bufferInUse = TRUE;
+ return session->buffer;
+}
+
+void
+tr_sessionReleaseBuffer( tr_session * session )
+{
+ assert( tr_isSession( session ) );
+ assert( session->bufferInUse );
+ assert( tr_amInEventThread( session ) );
+
+ session->bufferInUse = FALSE;
+}
+
void
tr_sessionLock( tr_session * session )
{
tr_bencFree( session->metainfoLookup );
tr_free( session->metainfoLookup );
}
+ tr_free( session->buffer );
tr_free( session->tag );
tr_free( session->configDir );
tr_free( session->resumeDir );
struct tr_bindinfo * public_ipv4;
struct tr_bindinfo * public_ipv6;
+
+ /* a page-aligned buffer for use by the libtransmission thread.
+ * @see SESSION_BUFFER_SIZE */
+ void * buffer;
+
+ tr_bool bufferInUse;
};
tr_bool tr_sessionAllowsDHT( const tr_session * session );
enum
{
- SESSION_MAGIC_NUMBER = 3845
+ SESSION_MAGIC_NUMBER = 3845,
+
+ /* @see tr_session.buffer */
+ SESSION_BUFFER_SIZE = (16*1024)
};
+void* tr_sessionGetBuffer( tr_session * session );
+
+void tr_sessionReleaseBuffer( tr_session * session );
+
static inline tr_bool tr_isSession( const tr_session * session )
{
return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER );