[Libpdtp-svn] r52 - /
Status: Alpha
Brought to you by:
bascule
From: <tar...@pd...> - 2004-12-14 23:39:33
|
Author: tarcieri Date: 2004-12-14 16:39:56 -0700 (Tue, 14 Dec 2004) New Revision: 52 Modified: connection.h download.c transaction.c transaction.h txnmgr.c Log: New asynchronous transaction interface, dependency cleanups, and strict aliasing cleanups Modified: connection.h =================================================================== --- connection.h 2004-12-08 00:12:22 UTC (rev 51) +++ connection.h 2004-12-14 23:39:56 UTC (rev 52) @@ -5,7 +5,6 @@ #include "pdtp.h" #include "socketops.h" #include "threadops.h" -#include "transaction.h" #include "txnmgr.h" /** Modified: download.c =================================================================== --- download.c 2004-12-08 00:12:22 UTC (rev 51) +++ download.c 2004-12-14 23:39:56 UTC (rev 52) @@ -165,7 +165,7 @@ if(piece_count * 16 != length) goto err; - if(pdtp__transaction_object_data(in, i, &data) < 0) + if(!(data = pdtp__transaction_object_data(in, i))) goto err; dl->hashes = (uint8_t *)pdtp__alloc(length); Modified: transaction.c =================================================================== --- transaction.c 2004-12-08 00:12:22 UTC (rev 51) +++ transaction.c 2004-12-14 23:39:56 UTC (rev 52) @@ -351,14 +351,12 @@ return 0; } -int pdtp__transaction_object_data(pdtp_transaction_in_t txn, unsigned objno, void **data) +void *pdtp__transaction_object_data(pdtp_transaction_in_t txn, unsigned objno) { if(pdtp__transaction_read_to_object(txn, objno) < 0) - return -1; + return 0; - *data = txn->object[objno].obj_data; - - return 0; + return txn->object[objno].obj_data; } int pdtp__transaction_object_uint16(pdtp_transaction_in_t txn, unsigned objno, uint16_t *object) @@ -373,7 +371,7 @@ if(length != 2) return -1; - if(pdtp__transaction_object_data(txn, objno, &data) < 0) + if(!(data = pdtp__transaction_object_data(txn, objno))) return -1; memcpy(&value, data, 2); @@ -393,7 +391,7 @@ if(length != 4) return -1; - if(pdtp__transaction_object_data(txn, objno, &data) < 0) + if(!(data = pdtp__transaction_object_data(txn, objno))) return -1; memcpy(&value, data, 4); @@ -418,7 +416,7 @@ if(length != 8) return -1; - if(pdtp__transaction_object_data(txn, objno, (void **)&data) < 0) + if(!(data = pdtp__transaction_object_data(txn, objno))) return -1; #ifdef HOST_BIGENDIAN @@ -442,7 +440,7 @@ if(pdtp__transaction_object_length(txn, objno, &length) < 0) return -1; - if(pdtp__transaction_object_data(txn, objno, &data) < 0) + if(!(data = pdtp__transaction_object_data(txn, objno))) return -1; *string = (char *)pdtp__alloc(length + 1); @@ -469,7 +467,7 @@ if(pdtp__transaction_object_length(txn, objno, &length) < 0) return -1; - if(pdtp__transaction_object_data(txn, objno, (void **)&bptr) < 0) + if(!(bptr = pdtp__transaction_object_data(txn, objno))) return -1; va_start(ap, format); @@ -867,30 +865,6 @@ #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 */ @@ -925,30 +899,25 @@ } /* Asynchronous transaction interface. A connection and transaction are - specified, as well as a multiplexer, object type, and callback. The - specified transaction is sent to the specified connection. When the - 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 out, uint16_t obj, void (*callback)(pdtp_transaction_in_t, void *arg), void *arg) -{ - int filter_object_index; + specified, as well as a multiplexer, success callback, and error callback. + This function is currently hardcoded only to support TXN_DOWNLOAD. Passing + a transaction of any other type will result in an assertion failure. - /* 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; - } + The specified transaction will be synchronously sent to the server. If + an error response is received, the specified error callback will be + invoked with the server's error message. The error callback will also + be invoked if the format of the response transaction is wrong. The + response transaction should include one 32-bit unsigned integer object + which will be used as the key for receiving asynchronous transactions. + If a successful response of the proper format is received, then a filter + is created for the given multiplexer which will invoke the specified + success_callback whenever a transaction is received containing the same + object as received in the initial successful transaction response. - /* 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; + The interface currently specifies no way to destroy filter rules for a + given multiplexer because it should be unnecessary. Filter rules will + be destroyed along with the multiplexer. + */ +void pdtp__transact_async(pdtp_connection_t conn, pdtp_multiplexer_t mplx, pdtp_transaction_out_t out, void (*success_callback)(pdtp_transaction_in_t, void *arg), void (*error_callback)(const char *msg, void *arg), void *arg) +{ } Modified: transaction.h =================================================================== --- transaction.h 2004-12-08 00:12:22 UTC (rev 51) +++ transaction.h 2004-12-14 23:39:56 UTC (rev 52) @@ -24,13 +24,27 @@ pdtp_transaction_in_t pdtp__transact(pdtp_connection_t, pdtp_transaction_out_t, pdtp_read_mode_t); /* Asynchronous transaction interface. A connection and transaction are - specified, as well as a multiplexer, object type, and callback. The - specified transaction is sent to the specified connection. When the - 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)(pdtp_transaction_in_t, void *arg), void *arg); + specified, as well as a multiplexer, success callback, and error callback. + This function is currently hardcoded only to support TXN_DOWNLOAD. Passing + a transaction of any other type will result in an assertion failure. + The specified transaction will be synchronously sent to the server. If + an error response is received, the specified error callback will be + invoked with the server's error message. The error callback will also + be invoked if the format of the response transaction is wrong. The + response transaction should include one 32-bit unsigned integer object + which will be used as the key for receiving asynchronous transactions. + If a successful response of the proper format is received, then a filter + is created for the given multiplexer which will invoke the specified + success_callback whenever a transaction is received containing the same + object as received in the initial successful transaction response. + + The interface currently specifies no way to destroy filter rules for a + given multiplexer because it should be unnecessary. Filter rules will + be destroyed along with the multiplexer. + */ +void pdtp__transact_async(pdtp_connection_t, pdtp_multiplexer_t, pdtp_transaction_out_t, void (*success_callback)(pdtp_transaction_in_t, void *arg), void (*error_callback)(const char *msg, void *arg), void *arg); + void pdtp__transaction_in_destroy(pdtp_transaction_in_t); pdtp_transaction_type_t pdtp__transaction_type(pdtp_transaction_in_t); uint16_t pdtp__transaction_id(pdtp_transaction_in_t); @@ -39,7 +53,7 @@ int pdtp__transaction_object_index(pdtp_transaction_in_t, uint16_t type); int pdtp__transaction_object_id(pdtp_transaction_in_t, unsigned objno, uint16_t *id); int pdtp__transaction_object_length(pdtp_transaction_in_t, unsigned objno, uint32_t *length); -int pdtp__transaction_object_data(pdtp_transaction_in_t, unsigned objno, void **data); +void *pdtp__transaction_object_data(pdtp_transaction_in_t txn, unsigned objno); int pdtp__transaction_object_uint16(pdtp_transaction_in_t, unsigned objno, uint16_t *object); int pdtp__transaction_object_uint32(pdtp_transaction_in_t, unsigned objno, uint32_t *object); int pdtp__transaction_object_uint64(pdtp_transaction_in_t, unsigned objno, uint64_t *object); Modified: txnmgr.c =================================================================== --- txnmgr.c 2004-12-08 00:12:22 UTC (rev 51) +++ txnmgr.c 2004-12-14 23:39:56 UTC (rev 52) @@ -35,6 +35,7 @@ #include "pdtp.h" #include "alloc.h" +#include "collection.h" #include "threadops.h" #include "txnmgr.h" @@ -42,6 +43,12 @@ /* Connection serial number and respective lock */ uint32_t serial; pdtp_mutex_t serial_lock; + + pdtp_collection_t serial_collection; + pdtp_mutex_t serial_collection_lock; + + pdtp_collection_t handle_collection; + pdtp_mutex_t handle_collection_lock; }; pdtp_txnmgr_t pdtp__txnmgr_create(void) |