add portability wrapper for in_port_t...

This commit is contained in:
Charles Kerr 2007-07-30 18:04:10 +00:00
parent 1be185aacd
commit d209052051
27 changed files with 76 additions and 47 deletions

View File

@ -30,6 +30,7 @@
#include "transmission.h"
#include "bencode.h"
#include "utils.h"
/* setting to 1 to help expose bugs with tr_bencListAdd and tr_bencDictAdd */
#define LIST_SIZE 20 /* number of items to increment list/dict buffer by */

View File

@ -28,6 +28,7 @@
#include "transmission.h"
#include "choking.h"
#include "utils.h"
#ifndef HAVE_LRINTF
# define lrintf(a) ((int)(0.5+(a)))

View File

@ -27,6 +27,7 @@
#include "transmission.h"
#include "completion.h"
#include "utils.h"
struct tr_completion_s
{

View File

@ -27,6 +27,8 @@
#include "transmission.h"
typedef struct tr_completion_s tr_completion_t;
tr_completion_t * tr_cpInit( tr_torrent_t * );
void tr_cpClose( tr_completion_t * );
void tr_cpReset( tr_completion_t * );
@ -44,7 +46,6 @@ void tr_cpInvalidateDND ( tr_completion_t * );
/* Pieces */
int tr_cpPieceHasAllBlocks( const tr_completion_t *, int piece );
int tr_cpPieceIsComplete( const tr_completion_t *, int piece );
const tr_bitfield_t * tr_cpPieceBitfield( const tr_completion_t* );
void tr_cpPieceAdd( tr_completion_t *, int piece );
void tr_cpPieceRem( tr_completion_t *, int piece );
@ -53,11 +54,13 @@ void tr_cpDownloaderAdd( tr_completion_t *, int block );
void tr_cpDownloaderRem( tr_completion_t *, int block );
int tr_cpBlockIsComplete( const tr_completion_t *, int block );
void tr_cpBlockAdd( tr_completion_t *, int block );
const tr_bitfield_t * tr_cpBlockBitfield( const tr_completion_t * );
void tr_cpBlockBitfieldSet( tr_completion_t *, tr_bitfield_t * );
void tr_cpBlockBitfieldSet( tr_completion_t *, struct tr_bitfield_s * );
float tr_cpPercentBlocksInPiece( const tr_completion_t * cp, int piece );
/* Missing = we don't have it and we are not getting it from any peer yet */
int tr_cpMissingBlocksForPiece( const tr_completion_t * cp, int piece );
int tr_cpMissingBlockInPiece( const tr_completion_t *, int piece );
const struct tr_bitfield_s * tr_cpPieceBitfield( const tr_completion_t* );
const struct tr_bitfield_s * tr_cpBlockBitfield( const tr_completion_t * );
#endif

View File

@ -53,7 +53,9 @@
#include <unistd.h>
#include "transmission.h"
#include "completion.h"
#include "fastresume.h"
#include "utils.h"
/* time_t can be 32 or 64 bits... for consistency we'll hardwire 64 */
typedef uint64_t tr_time_t;

View File

@ -40,7 +40,7 @@ enum
/**
* Returns a bitwise-or'ed set of the data loaded from fastresume
*/
uint64_t tr_fastResumeLoad( tr_torrent_t * tor,
tr_bitfield_t * uncheckedPieces );
uint64_t tr_fastResumeLoad( tr_torrent_t * tor,
struct tr_bitfield_s * uncheckedPieces );
#endif

View File

@ -36,6 +36,7 @@
#include <fcntl.h>
#include "transmission.h"
#include "utils.h"
#define TR_MAX_OPEN_FILES 16 /* That is, real files, not sockets */
#define TR_RESERVED_FDS 16 /* Number of sockets reserved for
@ -355,7 +356,7 @@ int tr_fdSocketCreate( int type, int priority )
return s;
}
int tr_fdSocketAccept( int b, struct in_addr * addr, in_port_t * port )
int tr_fdSocketAccept( int b, struct in_addr * addr, tr_port_t * port )
{
int s = -1;
unsigned len;

View File

@ -61,7 +61,7 @@ void tr_fdFileClose( const char * folder, const char * name );
* Sockets
**********************************************************************/
int tr_fdSocketCreate( int type, int priority );
int tr_fdSocketAccept( int b, struct in_addr * addr, in_port_t * port );
int tr_fdSocketAccept( int b, struct in_addr * addr, tr_port_t * port );
void tr_fdSocketClose( int s );
/***********************************************************************

View File

@ -37,6 +37,7 @@
#include "http.h"
#include "net.h"
#include "trcompat.h"
#include "utils.h"
#define HTTP_PORT 80 /* default http port 80 */
#define HTTP_TIMEOUT 60000 /* one minute http timeout */

View File

@ -17,7 +17,10 @@
#include <unistd.h>
#include "transmission.h"
#include "completion.h"
#include "fdlimit.h"
#include "inout.h"
#include "utils.h"
struct tr_io_s
{

View File

@ -42,10 +42,12 @@ extern int vasprintf( char **, const char *, va_list );
# define socklen_t uint32_t
#endif
#ifdef BEOS_NETSERVER
# define in_port_t uint16_t
#if defined(BEOS_NETSERVER) || defined(__MINGW__)
#include <stdint.h>
typedef uint16_t tr_port_t;
#else
# include <arpa/inet.h>
#include <arpa/inet.h>
typedef in_port_t tr_port_t;
#endif
#define TR_NAME "Transmission"
@ -81,17 +83,10 @@ extern int vasprintf( char **, const char *, va_list );
#define TR_MAX_PEER_COUNT 60
typedef struct tr_completion_s tr_completion_t;
typedef struct tr_shared_s tr_shared_t;
typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
#include "platform.h"
#include "tracker.h"
#include "platform.h" /* thread, lock */
#include "peer.h"
#include "inout.h"
#include "ratecontrol.h"
#include "utils.h"
#ifndef TRUE
#define TRUE 1
@ -106,7 +101,7 @@ void tr_torrentResetTransferStats( tr_torrent_t * );
int tr_torrentAddCompact( tr_torrent_t * tor, int from,
uint8_t * buf, int count );
int tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * peer );
int tr_torrentAttachPeer( tr_torrent_t * tor, tr_peer_t * );
void tr_torrentSetHasPiece( tr_torrent_t * tor, int pieceIndex, int has );
@ -158,9 +153,9 @@ struct tr_torrent_s
tr_speedlimit_t uploadLimitMode;
tr_speedlimit_t downloadLimitMode;
tr_ratecontrol_t * upload;
tr_ratecontrol_t * download;
tr_ratecontrol_t * swarmspeed;
struct tr_ratecontrol_s * upload;
struct tr_ratecontrol_s * download;
struct tr_ratecontrol_s * swarmspeed;
int error;
char errorString[128];
@ -187,17 +182,17 @@ struct tr_torrent_s
int blockCountInPiece;
int blockCountInLastPiece;
tr_completion_t * completion;
struct tr_completion_s * completion;
volatile char dieFlag;
tr_bitfield_t * uncheckedPieces;
struct tr_bitfield_s * uncheckedPieces;
run_status_t runStatus;
cp_status_t cpStatus;
tr_thread_t * thread;
tr_rwlock_t * lock;
tr_tracker_t * tracker;
tr_io_t * io;
struct tr_tracker_s * tracker;
struct tr_io_s * io;
uint64_t startDate;
uint64_t stopDate;
char ioLoaded;
@ -220,9 +215,6 @@ struct tr_torrent_s
tr_torrent_t * next;
};
#include "utils.h"
#include "completion.h"
struct tr_handle_s
{
int torrentCount;
@ -232,11 +224,11 @@ struct tr_handle_s
int isPortSet;
char useUploadLimit;
tr_ratecontrol_t * upload;
char useDownloadLimit;
tr_ratecontrol_t * download;
struct tr_ratecontrol_s * upload;
struct tr_ratecontrol_s * download;
tr_shared_t * shared;
struct tr_shared_s * shared;
char key[TR_KEY_LEN+1];

View File

@ -26,6 +26,7 @@
#include "makemeta.h"
#include "platform.h" /* threads, locks */
#include "shared.h" /* shared lock */
#include "utils.h" /* buildpath */
#include "version.h"
/****

View File

@ -35,6 +35,7 @@
#include "bencode.h"
#include "http.h" /* tr_httpParseUrl */
#include "metainfo.h"
#include "utils.h"
#define TORRENT_MAX_SIZE (5*1024*1024)

View File

@ -36,6 +36,7 @@
#include "transmission.h"
#include "natpmp.h"
#include "net.h"
#include "utils.h"
#define PMP_PORT 5351
#define PMP_MCAST_ADDR "224.0.0.1"

View File

@ -37,6 +37,7 @@
#include "transmission.h"
#include "fdlimit.h"
#include "net.h"
#include "utils.h"
/***********************************************************************
@ -271,7 +272,7 @@ static int createSocket( int type, int priority )
return makeSocketNonBlocking( s );
}
int tr_netOpen( const struct in_addr * addr, in_port_t port,
int tr_netOpen( const struct in_addr * addr, tr_port_t port,
int type, int priority )
{
int s;
@ -372,7 +373,7 @@ int tr_netBind( int port, int type )
return s;
}
int tr_netAccept( int b, struct in_addr * addr, in_port_t * port )
int tr_netAccept( int b, struct in_addr * addr, tr_port_t * port )
{
int s;
if( ( s = tr_fdSocketAccept( b, addr, port ) ) < 0 )

View File

@ -46,13 +46,13 @@ void tr_netResolveClose( tr_resolve_t * );
tr_netOpen( (addr), (port), SOCK_STREAM, (priority) )
#define tr_netOpenUDP( addr, port, priority ) \
tr_netOpen( (addr), (port), SOCK_DGRAM, (priority) )
int tr_netOpen ( const struct in_addr * addr, in_port_t port, int type,
int tr_netOpen ( const struct in_addr * addr, tr_port_t port, int type,
int priority );
int tr_netMcastOpen( int port, const struct in_addr * addr );
#define tr_netBindTCP( port ) tr_netBind( (port), SOCK_STREAM )
#define tr_netBindUDP( port ) tr_netBind( (port), SOCK_DGRAM )
int tr_netBind ( int port, int type );
int tr_netAccept ( int s, struct in_addr *, in_port_t * );
int tr_netAccept ( int s, struct in_addr *, tr_port_t * );
void tr_netClose ( int s );
#define TR_NET_BLOCK 0x80000000

View File

@ -36,9 +36,13 @@
#include "transmission.h"
#include "bencode.h"
#include "clients.h" /* for tr_clientForId() */
#include "peertree.h"
#include "completion.h"
#include "inout.h"
#include "list.h"
#include "net.h"
#include "peertree.h"
#include "ratecontrol.h"
#include "utils.h"
/*****
******
@ -131,7 +135,7 @@ struct tr_peer_s
tr_torrent_t * tor;
struct in_addr addr;
in_port_t port; /* peer's listening port, 0 if not known */
tr_port_t port; /* peer's listening port, 0 if not known */
#define PEER_STATUS_IDLE 1 /* Need to connect */
#define PEER_STATUS_CONNECTING 2 /* Trying to send handshake */
@ -256,7 +260,7 @@ static void tr_htonl( uint32_t a, void * p )
***********************************************************************
* Initializes a new peer.
**********************************************************************/
tr_peer_t * tr_peerInit( const struct in_addr * addr, in_port_t port,
tr_peer_t * tr_peerInit( const struct in_addr * addr, tr_port_t port,
int s, int from )
{
tr_peer_t * peer;

View File

@ -30,7 +30,7 @@
struct in_addr;
typedef struct tr_peer_s tr_peer_t;
tr_peer_t * tr_peerInit ( const struct in_addr *, in_port_t, int sock, int );
tr_peer_t * tr_peerInit ( const struct in_addr *, tr_port_t, int sock, int );
void tr_peerDestroy ( tr_peer_t * );
const char *tr_peerClient ( tr_peer_t * );
void tr_peerSetPrivate ( tr_peer_t *, int );

View File

@ -429,7 +429,7 @@ static int parseCancel( tr_torrent_t * tor, tr_peer_t * peer,
static int parsePort( tr_peer_t * peer, uint8_t * p, int len )
{
in_port_t port;
tr_port_t port;
if( len != 2 )
{
@ -437,7 +437,7 @@ static int parsePort( tr_peer_t * peer, uint8_t * p, int len )
return TR_ERROR_ASSERT;
}
port = *( (in_port_t *) p );
port = *( (tr_port_t *) p );
peer_dbg( "GET port %d", ntohs( port ) );
return TR_OK;

View File

@ -64,7 +64,7 @@ peertreeCount( tr_peertree_t * tree )
}
static tr_peertree_entry_t *
peertreeGet( tr_peertree_t * tree, struct in_addr * addr, in_port_t port )
peertreeGet( tr_peertree_t * tree, struct in_addr * addr, tr_port_t port )
{
tr_peertree_entry_t entry;
@ -76,7 +76,7 @@ peertreeGet( tr_peertree_t * tree, struct in_addr * addr, in_port_t port )
}
static tr_peertree_entry_t *
peertreeAdd( tr_peertree_t * tree, struct in_addr * addr, in_port_t port )
peertreeAdd( tr_peertree_t * tree, struct in_addr * addr, tr_port_t port )
{
tr_peertree_entry_t * entry;

View File

@ -25,7 +25,9 @@
#include <string.h>
#include "transmission.h"
#include "ratecontrol.h"
#include "shared.h"
#include "utils.h"
#define GRANULARITY_MSEC 250
#define SHORT_INTERVAL_MSEC 3000

View File

@ -38,6 +38,7 @@
#include "peer.h"
#include "shared.h"
#include "upnp.h"
#include "utils.h"
/* Maximum number of peers that we keep in our local list */
/* This is an arbitrary number, but it seems to work well */

View File

@ -27,6 +27,8 @@
#include "transmission.h"
typedef struct tr_shared_s tr_shared_t;
/***********************************************************************
* tr_sharedInit, tr_sharedClose
***********************************************************************

View File

@ -33,11 +33,16 @@
#include <arpa/inet.h>
#include "transmission.h"
#include "completion.h"
#include "fastresume.h"
#include "trcompat.h" /* for strlcpy */
#include "inout.h"
#include "metainfo.h"
#include "net.h" /* tr_netNtop */
#include "ratecontrol.h"
#include "shared.h"
#include "tracker.h"
#include "trcompat.h" /* for strlcpy */
#include "utils.h"
/***
**** LOCKS
@ -978,7 +983,7 @@ int tr_torrentAddCompact( tr_torrent_t * tor, int from,
uint8_t * buf, int count )
{
struct in_addr addr;
in_port_t port;
tr_port_t port;
int i, added;
tr_peer_t * peer;

View File

@ -34,9 +34,12 @@
#include "transmission.h"
#include "bencode.h"
#include "bsdqueue.h"
#include "completion.h"
#include "http.h"
#include "net.h"
#include "shared.h"
#include "tracker.h"
#include "utils.h"
/* Users aren't allowed to make a manual announce more often than this. */
static const int MANUAL_ANNOUNCE_INTERVAL_MSEC = (60*1000);
@ -1109,7 +1112,7 @@ static uint8_t *
parseOriginalPeers( benc_val_t * bePeers, int * peerCount )
{
struct in_addr addr;
in_port_t port;
tr_port_t port;
uint8_t * peerCompact;
benc_val_t * peer, * addrval, * portval;
int ii, count;

View File

@ -37,7 +37,9 @@
#include "fdlimit.h"
#include "list.h"
#include "net.h"
#include "ratecontrol.h"
#include "shared.h"
#include "utils.h"
/* Generate a peer id : "-TRxyzb-" + 12 random alphanumeric
characters, where x is the major version number, y is the

View File

@ -41,6 +41,7 @@
#include "net.h"
#include "trcompat.h"
#include "upnp.h"
#include "utils.h"
#include "xml.h"
/* uncomment this to log requests and responses to ~/transmission-upnp.log */