[Libpdtp-svn] r51 - /
Status: Alpha
Brought to you by:
bascule
From: <tar...@pd...> - 2004-12-08 00:11:56
|
Author: tarcieri Date: 2004-12-07 17:12:22 -0700 (Tue, 07 Dec 2004) New Revision: 51 Modified: download.c make-machdep.h.sh multiplexer.c multiplexer.h transaction.c transaction.h txnmgr.h Log: More modifications for download support Modified: download.c =================================================================== --- download.c 2004-12-06 19:37:43 UTC (rev 50) +++ download.c 2004-12-08 00:12:22 UTC (rev 51) @@ -44,6 +44,7 @@ #include "errmsg.h" #include "error.h" #include "fileops.h" +#include "multiplexer.h" #include "piecelist.h" #include "transaction.h" #include "txid.h" @@ -71,6 +72,9 @@ /* Connection associated with download */ pdtp_connection_t conn; + /* Multiplexer associated with download */ + pdtp_multiplexer_t mplx; + /* File being downloaded */ pdtp_file_t file; }; @@ -255,6 +259,8 @@ pdtp__transaction_in_destroy(in); + dl->mplx = pdtp__multiplexer_create(dl->conn); + return; err: pdtp_set_last_error(ERROR_DOWNLOAD_INIT); @@ -265,7 +271,6 @@ pdtp__transaction_in_destroy(in); - /* XXX Yipe, we really need to do something here */ #ifndef NDEBUG debug("Error running download"); #endif Modified: make-machdep.h.sh =================================================================== --- make-machdep.h.sh 2004-12-06 19:37:43 UTC (rev 50) +++ make-machdep.h.sh 2004-12-08 00:12:22 UTC (rev 51) @@ -12,7 +12,7 @@ echo "#ifndef MACHDEP_H" > machdep.h echo "#define MACHDEP_H" >> machdep.h echo "/** @file machdep.h" >> machdep.h -echo "* @brief machine dependancys (auto-generated)">> machdep.h +echo "* @brief machine dependancies (auto-generated)">> machdep.h echo "*/" >> machdep.h echo >> machdep.h Modified: multiplexer.c =================================================================== --- multiplexer.c 2004-12-06 19:37:43 UTC (rev 50) +++ multiplexer.c 2004-12-08 00:12:22 UTC (rev 51) @@ -34,4 +34,25 @@ #include "machdep.h" #include "pdtp.h" +#include "connection.h" #include "multiplexer.h" + +#if defined(HAVE_POLL) && !defined(HAVE_MULTIPLEXER) +#define HAVE_MULTIPLEXER + +#include <sys/poll.h> +#include <unistd.h> + +/* Initial size of the file descriptor table */ +#define INITIAL_TABLE_SIZE 16 + +pdtp_multiplexer_t pdtp__multiplexer_create(pdtp_connection_t conn) +{ + return 0; +} + +void pdtp_multiplexer_destroy(pdtp_multiplexer_t mplx) +{ +} + +#endif /* defined(HAVE_POLL) && !defined(HAVE_MULTIPLEXER) */ Modified: multiplexer.h =================================================================== --- multiplexer.h 2004-12-06 19:37:43 UTC (rev 50) +++ multiplexer.h 2004-12-08 00:12:22 UTC (rev 51) @@ -1,6 +1,14 @@ #ifndef MULTIPLEXER_H #define MULTIPLEXER_H +#include "machdep.h" +#include "pdtp.h" + +#include "connection.h" + typedef struct pdtp_multiplexer *pdtp_multiplexer_t; +pdtp_multiplexer_t pdtp__multiplexer_create(pdtp_connection_t); +void pdtp_multiplexer_destroy(pdtp_multiplexer_t); + #endif Modified: transaction.c =================================================================== --- transaction.c 2004-12-06 19:37:43 UTC (rev 50) +++ transaction.c 2004-12-08 00:12:22 UTC (rev 51) @@ -36,6 +36,7 @@ #include "sockets.h" #include <sys/types.h> +#include <assert.h> #include <stdarg.h> #include <string.h> #include <time.h> @@ -186,7 +187,7 @@ /* Ensure that the transaction's objects are populated to at least the specified object index. */ -int pdtp__transaction_read_to_object(pdtp_transaction_in_t txn, unsigned obj) +static int pdtp__transaction_read_to_object(pdtp_transaction_in_t txn, unsigned obj) { int len; uint16_t v16; @@ -655,7 +656,7 @@ #ifdef HAVE_UIO txn->iov[txn->obj_count + 4].iov_len = 6 + length; - txn->iov[txn->obj_count + 4].iov_base = (char *)obj_buf; + txn->iov[txn->obj_count + 4].iov_base = obj_buf; #endif #ifdef WIN32 @@ -805,11 +806,11 @@ length = htonl(txn->length); obj_count = htons(txn->obj_count); - txn->iov[0].iov_base = (char *)&length; - txn->iov[3].iov_base = (char *)&obj_count; + txn->iov[0].iov_base = &length; + txn->iov[3].iov_base = &obj_count; return writev(conn->sock, txn->iov, 4 + txn->obj_count); -#endif +#endif /* HAVE_UIO */ #ifdef WIN32 uint32_t length; @@ -826,7 +827,7 @@ return -1; return bytes; -#endif +#endif /* WIN32 */ #if !defined(HAVE_UIO) && !defined(WIN32) int i, ret; @@ -866,6 +867,30 @@ #endif } +/* This could likely be implemented a bit more cleanly */ +static uint16_t pdtp__transaction_out_object_id(pdtp_transaction_out_t txn, unsigned objno) +{ + uint16_t ret; + +#ifdef HAVE_UIO + assert(objno < txn->obj_count); + + memcpy(&ret, (uint8_t *)txn->iov[objno + 4].iov_base + 4, 2); + ret = htons(ret); +#endif /* HAVE_UIO */ + +#ifdef WIN32 + memcpy(&ret, (uint8_t *)txn->buf[objno + 4].buf + 4, 2); + ret = htons(ret); +#endif /* WIN32 */ + +#if !defined(HAVE_UIO) && !defined(WIN32) + ret = txn->object[txn->obj_count].obj_id; +#endif /* !defined(HAVE_UIO) && !defined(WIN32) */ + + return ret; +} + /* Synchronous transaction interface. A connection and transaction are specified. The returned transaction is the response to the request transaction being sent */ @@ -905,6 +930,25 @@ specified multiplexer is running, it will invoke the given callback whenever a transaction is received with an object of the specified type which is identical to the same object in the request */ -void pdtp__transact_async(pdtp_connection_t conn, pdtp_multiplexer_t mplx, pdtp_transaction_out_t txn, uint16_t obj, void (*callback)(void *arg), void *arg) +void pdtp__transact_async(pdtp_connection_t conn, pdtp_multiplexer_t mplx, pdtp_transaction_out_t out, uint16_t obj, void (*callback)(pdtp_transaction_in_t, void *arg), void *arg) { + int filter_object_index; + + /* Locate the object we'll be filtering by */ + for(filter_object_index = 0; filter_object_index < out->obj_count; filter_object_index++) { + if(pdtp__transaction_out_object_id(out, filter_object_index) == obj) + break; + } + + /* assert that at least one of the objects in our outgoing transaction + matches the passed ID. This is what we'll be filtering asynchronous + transaction responses by, so if this doesn't match either the + given transaction was miscontructed or the object ID is wrong */ + assert(filter_object_index < out->obj_count); + + /* XXX Set up filter rules here */ + + pdtp__transaction_write(conn, out); + + return; } Modified: transaction.h =================================================================== --- transaction.h 2004-12-06 19:37:43 UTC (rev 50) +++ transaction.h 2004-12-08 00:12:22 UTC (rev 51) @@ -29,7 +29,7 @@ specified multiplexer is running, it will invoke the given callback whenever a transaction is received with an object of the specified type which is identical to the same object in the request */ -void pdtp__transact_async(pdtp_connection_t, pdtp_multiplexer_t, pdtp_transaction_out_t, uint16_t obj, void (*callback)(void *arg), void *arg); +void pdtp__transact_async(pdtp_connection_t, pdtp_multiplexer_t, pdtp_transaction_out_t, uint16_t obj, void (*callback)(pdtp_transaction_in_t, void *arg), void *arg); void pdtp__transaction_in_destroy(pdtp_transaction_in_t); pdtp_transaction_type_t pdtp__transaction_type(pdtp_transaction_in_t); Modified: txnmgr.h =================================================================== --- txnmgr.h 2004-12-06 19:37:43 UTC (rev 50) +++ txnmgr.h 2004-12-08 00:12:22 UTC (rev 51) @@ -1,8 +1,6 @@ #ifndef TXNMGR_H #define TXNMGR_H -#include "transaction.h" - typedef struct pdtp_txnmgr *pdtp_txnmgr_t; pdtp_txnmgr_t pdtp__txnmgr_create(void); |