1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

use sendpkmsg()

This commit is contained in:
Charles Kerr 2008-05-07 11:57:23 +00:00
parent 00035cb8d8
commit e839456a86

View file

@ -38,6 +38,7 @@
#include <libtransmission/bencode.h> #include <libtransmission/bencode.h>
#include <libtransmission/ipcparse.h> #include <libtransmission/ipcparse.h>
#include <libtransmission/utils.h> /* tr_free */
#include "bsdtree.h" #include "bsdtree.h"
#include "errors.h" #include "errors.h"
@ -387,7 +388,7 @@ doread( struct bufferevent * ev, void * arg )
} }
} }
int static int
queuemsg( struct client * client, uint8_t * buf, size_t buflen ) queuemsg( struct client * client, uint8_t * buf, size_t buflen )
{ {
if( NULL == buf ) if( NULL == buf )
@ -416,6 +417,16 @@ queuemsg( struct client * client, uint8_t * buf, size_t buflen )
return 0; return 0;
} }
static int
queuepkmsg( struct client * client, tr_benc * pk )
{
size_t buflen;
uint8_t * buf = ipc_serialize( pk, &buflen );
int ret = queuemsg( client, buf, buflen );
tr_free( buf );
return ret;
}
int int
msgresp( struct client * client, int64_t tag, enum ipc_msg id ) msgresp( struct client * client, int64_t tag, enum ipc_msg id )
{ {
@ -459,8 +470,6 @@ addmsg1( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg )
struct client * client = arg; struct client * client = arg;
benc_val_t pk, * added; benc_val_t pk, * added;
int ii, tor; int ii, tor;
size_t buflen;
uint8_t * buf;
if( !tr_bencIsList( val ) ) if( !tr_bencIsList( val ) )
{ {
@ -496,10 +505,8 @@ addmsg1( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg )
} }
} }
buf = ipc_serialize( &pk, &buflen ); queuepkmsg( client, &pk );
tr_bencFree( &pk ); tr_bencFree( &pk );
queuemsg( client, buf, buflen );
free( buf );
} }
void void
@ -508,8 +515,6 @@ addmsg2( enum ipc_msg id UNUSED, benc_val_t * dict, int64_t tag, void * arg )
struct client * client = arg; struct client * client = arg;
benc_val_t * val, pk; benc_val_t * val, pk;
int tor, start; int tor, start;
size_t buflen;
uint8_t * buf;
const char * dir; const char * dir;
if( !tr_bencIsDict( dict ) ) if( !tr_bencIsDict( dict ) )
@ -557,10 +562,9 @@ addmsg2( enum ipc_msg id UNUSED, benc_val_t * dict, int64_t tag, void * arg )
byebye( client->ev, EVBUFFER_EOF, NULL ); byebye( client->ev, EVBUFFER_EOF, NULL );
return; return;
} }
buf = ipc_serialize( &pk, &buflen );
queuepkmsg( client, &pk );
tr_bencFree( &pk ); tr_bencFree( &pk );
queuemsg( client, buf, buflen );
free( buf );
} }
else else
{ {
@ -657,8 +661,6 @@ void
infomsg( enum ipc_msg id, benc_val_t * val, int64_t tag, void * arg ) infomsg( enum ipc_msg id, benc_val_t * val, int64_t tag, void * arg )
{ {
struct client * client = arg; struct client * client = arg;
uint8_t * buf;
size_t buflen;
benc_val_t pk, * pkinf, * typelist, * idlist, * idval; benc_val_t pk, * pkinf, * typelist, * idlist, * idval;
int all, types, ii, tor; int all, types, ii, tor;
void * iter; void * iter;
@ -754,11 +756,8 @@ infomsg( enum ipc_msg id, benc_val_t * val, int64_t tag, void * arg )
} }
} }
/* generate packet data and send it */ queuepkmsg( client, &pk );
buf = ipc_serialize( &pk, &buflen );
tr_bencFree( &pk ); tr_bencFree( &pk );
queuemsg( client, buf, buflen );
free( buf );
} }
int int
@ -853,8 +852,6 @@ void
lookmsg( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg ) lookmsg( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg )
{ {
struct client * client = arg; struct client * client = arg;
uint8_t * buf;
size_t buflen;
int ii; int ii;
benc_val_t * hash, pk, * pkinf; benc_val_t * hash, pk, * pkinf;
int64_t found; int64_t found;
@ -896,10 +893,8 @@ lookmsg( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg )
} }
} }
buf = ipc_serialize( &pk, &buflen ); queuepkmsg( client, &pk );
tr_bencFree( &pk ); tr_bencFree( &pk );
queuemsg( client, buf, buflen );
free( buf );
} }
void void
@ -962,8 +957,6 @@ void
supmsg( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg ) supmsg( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg )
{ {
struct client * client = arg; struct client * client = arg;
uint8_t * buf;
size_t buflen;
int ii; int ii;
benc_val_t pk, *pkval; benc_val_t pk, *pkval;
enum ipc_msg found; enum ipc_msg found;
@ -1008,8 +1001,6 @@ supmsg( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg )
name->val.s.s, name->val.s.i, 1 ); name->val.s.s, name->val.s.i, 1 );
} }
buf = ipc_serialize( &pk, &buflen ); queuepkmsg( client, &pk );
tr_bencFree( &pk ); tr_bencFree( &pk );
queuemsg( client, buf, buflen );
free( buf );
} }