[Libpdtp-svn] r48 - /
Status: Alpha
Brought to you by:
bascule
From: <tar...@pd...> - 2004-12-04 23:32:59
|
Author: tarcieri Date: 2004-12-04 16:33:16 -0700 (Sat, 04 Dec 2004) New Revision: 48 Modified: connection.c connection.h transaction.c transaction.h txnmgr.c txnmgr.h Log: New transaction handling code improvements Modified: connection.c =================================================================== --- connection.c 2004-11-23 23:33:02 UTC (rev 47) +++ connection.c 2004-12-04 23:33:16 UTC (rev 48) @@ -104,7 +104,7 @@ connection->addr = addr; connection->socket_lock = pdtp__mutex_create(); - connection->txnmgr = pdtp__transaction_manager_create(); + connection->txnmgr = pdtp__txnmgr_create(); pdtp__set_error_ptr(0); return connection; @@ -124,7 +124,7 @@ pdtp__socket_close(connection->sock); pdtp__mutex_destroy(connection->socket_lock); - pdtp__transaction_manager_destroy(connection->txnmgr); + pdtp__txnmgr_destroy(connection->txnmgr); pdtp__free(connection); } Modified: connection.h =================================================================== --- connection.h 2004-11-23 23:33:02 UTC (rev 47) +++ connection.h 2004-12-04 23:33:16 UTC (rev 48) @@ -24,7 +24,7 @@ pdtp_addr_t addr; pdtp_mutex_t socket_lock; - pdtp_transaction_manager_t txnmgr; + pdtp_txnmgr_t txnmgr; }; #endif /* CONNECTION_H */ Modified: transaction.c =================================================================== --- transaction.c 2004-11-23 23:33:02 UTC (rev 47) +++ transaction.c 2004-12-04 23:33:16 UTC (rev 48) @@ -158,10 +158,10 @@ if(txn->length > 0) goto err1; - /* Nothing left to read. Unlock the connection */ - pdtp__mutex_unlock(conn->socket_lock); + /* Nothing left to read. Unlock the connection */ + pdtp__mutex_unlock(conn->socket_lock); #ifndef NDEBUG - debug("--- socket_lock: pdtp__transaction_read_direct()"); + debug("--- socket_lock: pdtp__transaction_read_direct()"); #endif return txn; @@ -264,17 +264,43 @@ /* XXX At this point we've lost the connection or encountered a protocol error at which point we should mark the connection as lost */ - + pdtp__mutex_unlock(txn->connection->socket_lock); #ifndef NDEBUG debug("--- socket_lock: pdtp__transaction_read_to_object()"); #endif - + txn->connection = 0; return -1; } +/* Synchronous transaction interface. A connection and transaction are + specified. The returned transaction is the response to the request + transaction being sent */ +pdtp_transaction_in_t pdtp__transact(pdtp_connection_t conn, pdtp_transaction_out_t out) +{ + /* XXX This implementation is temporary as it is incompatible with + pdtp__transact_async */ + + uint32_t serial; + pdtp_transaction_in_t in = 0; + + serial = pdtp__txnmgr_get_serial(conn->txnmgr); + + return in; +} + +/* 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 txn, uint16_t obj, void (*callback)(void *arg), void *arg) +{ +} + void pdtp__transaction_in_destroy(pdtp_transaction_in_t txn) { if(txn->total_objs) { @@ -322,11 +348,11 @@ if(txn->current_obj == txn->total_objs || txn->object[txn->current_obj].obj_id != id) return -1; - + #ifndef NDEBUG debug("txn->object[%d] is %d", txn->current_obj, id); #endif - + return txn->current_obj; } @@ -437,7 +463,7 @@ uint32_t length; void *data; - + if(pdtp__transaction_object_length(txn, objno, &length) < 0) return -1; @@ -633,20 +659,6 @@ pdtp__free(txn); } -void pdtp__transaction_set_serial(pdtp_transaction_out_t txn, pdtp_connection_t conn) -{ - uint32_t serial; - -#if 0 - pdtp__mutex_lock(conn->txnmgr->serial_lock); - serial = conn->txnmgr->serial++; - txn->serial = htonl(serial); - pdtp__mutex_unlock(conn->txnmgr->serial_lock); - - return pdtp__create_serial_notifier(conn, serial); -#endif -} - void pdtp__transaction_add_object(pdtp_transaction_out_t txn, uint16_t id, const void *data, uint32_t length) { uint16_t v16; Modified: transaction.h =================================================================== --- transaction.h 2004-11-23 23:33:02 UTC (rev 47) +++ transaction.h 2004-12-04 23:33:16 UTC (rev 48) @@ -19,8 +19,8 @@ } pdtp_transaction_type_t; /* Synchronous transaction interface. A connection and transaction are - specified, and when a response transaction whose serial matches the - request is received on the connection, it is returned */ + specified. The returned transaction is the response to the request + transaction being sent */ pdtp_transaction_in_t pdtp__transact(pdtp_connection_t, pdtp_transaction_out_t); /* Asynchronous transaction interface. A connection and transaction are @@ -48,7 +48,6 @@ pdtp_transaction_out_t pdtp__transaction_create(uint16_t tid, uint16_t obj_count); void pdtp__transaction_out_destroy(pdtp_transaction_out_t); -void pdtp__transaction_set_serial(pdtp_transaction_out_t txn, pdtp_connection_t conn); void pdtp__transaction_add_object(pdtp_transaction_out_t, uint16_t id, const void *data, uint32_t length); void pdtp__transaction_add_int16(pdtp_transaction_out_t, uint16_t id, uint16_t value); void pdtp__transaction_add_int32(pdtp_transaction_out_t, uint16_t id, uint32_t value); Modified: txnmgr.c =================================================================== --- txnmgr.c 2004-11-23 23:33:02 UTC (rev 47) +++ txnmgr.c 2004-12-04 23:33:16 UTC (rev 48) @@ -38,17 +38,17 @@ #include "threadops.h" #include "txnmgr.h" -struct pdtp_transaction_manager { +struct pdtp_txnmgr { /* Connection serial number and respective lock */ uint32_t serial; pdtp_mutex_t serial_lock; }; -pdtp_transaction_manager_t pdtp__transaction_manager_create(void) +pdtp_txnmgr_t pdtp__txnmgr_create(void) { - pdtp_transaction_manager_t txnmgr; + pdtp_txnmgr_t txnmgr; - txnmgr = NEW(pdtp_transaction_manager); + txnmgr = NEW(pdtp_txnmgr); /* Initialize serial counter and respective lock */ txnmgr->serial = 1; @@ -57,10 +57,30 @@ return txnmgr; } -void pdtp__transaction_manager_destroy(pdtp_transaction_manager_t txnmgr) +void pdtp__txnmgr_destroy(pdtp_txnmgr_t txnmgr) { pdtp__mutex_destroy(txnmgr->serial_lock); /* Free the structure itself */ pdtp__free(txnmgr); } + +/* XXX This implementation should be replaced by one that recycles used + transaction serial numbers */ +uint32_t pdtp__txnmgr_get_serial(pdtp_txnmgr_t txnmgr) +{ + uint32_t serial; + + pdtp__mutex_lock(txnmgr->serial_lock); + serial = txnmgr->serial++; + pdtp__mutex_unlock(txnmgr->serial_lock); + + return serial; +} + +/* XXX This will be used by a new implementation that recycles used + transaction serial numbers. Since we aren't doing that, right now + this is just a stub */ +void pdtp__txnmgr_free_serial(pdtp_txnmgr_t txnmgr, uint32_t serial) +{ +} Modified: txnmgr.h =================================================================== --- txnmgr.h 2004-11-23 23:33:02 UTC (rev 47) +++ txnmgr.h 2004-12-04 23:33:16 UTC (rev 48) @@ -3,9 +3,12 @@ #include "transaction.h" -typedef struct pdtp_transaction_manager *pdtp_transaction_manager_t; +typedef struct pdtp_txnmgr *pdtp_txnmgr_t; -pdtp_transaction_manager_t pdtp__transaction_manager_create(void); -void pdtp__transaction_manager_destroy(pdtp_transaction_manager_t txnmgr); +pdtp_txnmgr_t pdtp__txnmgr_create(void); +void pdtp__txnmgr_destroy(pdtp_txnmgr_t); +uint32_t pdtp__txnmgr_get_serial(pdtp_txnmgr_t); +void pdtp__txnmgr_free_serial(pdtp_txnmgr_t, uint32_t serial); + #endif /* TXNMGR_H */ |