Repository: qpid-proton Updated Branches: refs/heads/master 8ca7e2a53 -> ade77512c
PROTON-1277: pn_connection_engine to use pn_bytes_t and pn_rwbytes_t Removed types pn_buf_t and pn_cbuf_t. Replaced pn_cbuf_t with existing public type pn_bytes_t. Replaced pn_buf_t with new public type pn_rwbytes_t. Replaced internal pn_buffer_memory_t with pn_rwbytes_t. Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/ade77512 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/ade77512 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/ade77512 Branch: refs/heads/master Commit: ade77512c11de31ea2ef1ec27101e38b982ae311 Parents: 8ca7e2a Author: Alan Conway <[email protected]> Authored: Tue Aug 9 18:11:22 2016 +0100 Committer: Alan Conway <[email protected]> Committed: Tue Aug 16 10:51:05 2016 +0100 ---------------------------------------------------------------------- .../bindings/cpp/src/io/connection_engine.cpp | 8 +++--- .../go/src/qpid.apache.org/proton/engine.go | 4 +-- proton-c/include/proton/connection_engine.h | 26 +++----------------- proton-c/include/proton/types.h | 11 ++++++++- proton-c/src/buffer.c | 6 ++--- proton-c/src/buffer.h | 7 +----- proton-c/src/codec/codec.c | 2 +- proton-c/src/engine/connection_engine.c | 22 +++++------------ proton-c/src/transport/transport.c | 4 +-- proton-c/src/types.c | 6 +++++ 10 files changed, 39 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/bindings/cpp/src/io/connection_engine.cpp ---------------------------------------------------------------------- diff --git a/proton-c/bindings/cpp/src/io/connection_engine.cpp b/proton-c/bindings/cpp/src/io/connection_engine.cpp index 4ca4ce3..4712b3e 100644 --- a/proton-c/bindings/cpp/src/io/connection_engine.cpp +++ b/proton-c/bindings/cpp/src/io/connection_engine.cpp @@ -109,8 +109,8 @@ bool connection_engine::dispatch() { } mutable_buffer connection_engine::read_buffer() { - pn_buf_t buffer = pn_connection_engine_read_buffer(&c_engine_); - return mutable_buffer(buffer.data, buffer.size); + pn_rwbytes_t buffer = pn_connection_engine_read_buffer(&c_engine_); + return mutable_buffer(buffer.start, buffer.size); } void connection_engine::read_done(size_t n) { @@ -122,8 +122,8 @@ void connection_engine::read_close() { } const_buffer connection_engine::write_buffer() { - pn_cbuf_t buffer = pn_connection_engine_write_buffer(&c_engine_); - return const_buffer(buffer.data, buffer.size); + pn_bytes_t buffer = pn_connection_engine_write_buffer(&c_engine_); + return const_buffer(buffer.start, buffer.size); } void connection_engine::write_done(size_t n) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go ---------------------------------------------------------------------- diff --git a/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go b/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go index 5b9dbf0..3cc6524 100644 --- a/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go +++ b/proton-c/bindings/go/src/qpid.apache.org/proton/engine.go @@ -133,7 +133,7 @@ func NewEngine(conn net.Conn, handlers ...EventHandler) (*Engine, error) { return eng, nil } -// Create a byte slice backed by the memory of a pn_buf_t, no copy. +// Create a byte slice backed by the memory of a pn_rwbytes_t, no copy. // Empty buffer {0,0} returns a nil byte slice. func byteSlice(data unsafe.Pointer, size C.size_t) []byte { if data == nil || size == 0 { @@ -146,7 +146,7 @@ func byteSlice(data unsafe.Pointer, size C.size_t) []byte { func (eng *Engine) buffers() ([]byte, []byte) { r := C.pn_connection_engine_read_buffer(&eng.engine) w := C.pn_connection_engine_write_buffer(&eng.engine) - return byteSlice(unsafe.Pointer(r.data), r.size), byteSlice(unsafe.Pointer(w.data), w.size) + return byteSlice(unsafe.Pointer(r.start), r.size), byteSlice(unsafe.Pointer(w.start), w.size) } func (eng *Engine) Connection() Connection { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/include/proton/connection_engine.h ---------------------------------------------------------------------- diff --git a/proton-c/include/proton/connection_engine.h b/proton-c/include/proton/connection_engine.h index bf2b69a..cf5006b 100644 --- a/proton-c/include/proton/connection_engine.h +++ b/proton-c/include/proton/connection_engine.h @@ -67,24 +67,6 @@ extern "C" { #endif -/// A modifiable memory buffer. -typedef struct pn_buf_t { - char* data; ///< Beginning of the buffered data. - size_t size; ///< Number of bytes in the buffer. -} pn_buf_t; - -/// Create a pn_buf -PN_EXTERN pn_buf_t pn_buf(char* data, size_t size); - -/// A read-only memory buffer. -typedef struct pn_cbuf_t { - const char* data; ///< Beginning of the buffered data. - size_t size; ///< Number of bytes in the buffer. -} pn_cbuf_t; - -/// Create a pn_cbuf -PN_EXTERN pn_cbuf_t pn_cbuf(const char* data, size_t size); - /// A connection engine is a trio of pn_connection_t, pn_transport_t and pn_collector_t. /// Use the pn_connection_engine_*() functions to operate on it. /// It is a plain struct, not a proton object. Use pn_connection_engine_init to set up @@ -105,13 +87,13 @@ PN_EXTERN int pn_connection_engine_init(pn_connection_engine_t* engine); /// to NULL. Only call on an engine that was initialized with pn_connection_engine_init PN_EXTERN void pn_connection_engine_final(pn_connection_engine_t* engine); -/// The engine's read buffer. Read data from your IO source into buf.data, up to +/// The engine's read buffer. Read data from your IO source to buf.start, up to /// a max of buf.size. Then call pn_connection_engine_read_done(). /// /// buf.size==0 means the engine cannot read presently, calling /// pn_connection_engine_dispatch() may create more buffer space. /// -PN_EXTERN pn_buf_t pn_connection_engine_read_buffer(pn_connection_engine_t*); +PN_EXTERN pn_rwbytes_t pn_connection_engine_read_buffer(pn_connection_engine_t*); /// Consume the first n bytes of data in pn_connection_engine_read_buffer() and /// update the buffer. @@ -122,12 +104,12 @@ PN_EXTERN void pn_connection_engine_read_done(pn_connection_engine_t*, size_t n) /// in pn_connection_engine_write_buffer() PN_EXTERN void pn_connection_engine_read_close(pn_connection_engine_t*); -/// The engine's write buffer. Write data from buf.data to your IO destination, +/// The engine's write buffer. Write data from buf.start to your IO destination, /// up to a max of buf.size. Then call pn_connection_engine_write_done(). /// /// buf.size==0 means the engine has nothing to write presently. Calling /// pn_connection_engine_dispatch() may generate more data. -PN_EXTERN pn_cbuf_t pn_connection_engine_write_buffer(pn_connection_engine_t*); +PN_EXTERN pn_bytes_t pn_connection_engine_write_buffer(pn_connection_engine_t*); /// Call when the first n bytes of pn_connection_engine_write_buffer() have been /// written to IO and can be re-used for new data. Updates the buffer. http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/include/proton/types.h ---------------------------------------------------------------------- diff --git a/proton-c/include/proton/types.h b/proton-c/include/proton/types.h index 3f2ebcb..72db6f8 100644 --- a/proton-c/include/proton/types.h +++ b/proton-c/include/proton/types.h @@ -64,13 +64,22 @@ typedef struct { char bytes[16]; } pn_uuid_t; -typedef struct { +/** A const byte buffer. */ +typedef struct pn_bytes_t { size_t size; const char *start; } pn_bytes_t; PN_EXTERN pn_bytes_t pn_bytes(size_t size, const char *start); +/** A non-const byte buffer. */ +typedef struct pn_rwbytes_t { + size_t size; + char *start; +} pn_rwbytes_t; + +PN_EXTERN pn_rwbytes_t pn_rwbytes(size_t size, char *start); + /** @} */ http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/src/buffer.c ---------------------------------------------------------------------- diff --git a/proton-c/src/buffer.c b/proton-c/src/buffer.c index 64fa61f..c3015f4 100644 --- a/proton-c/src/buffer.c +++ b/proton-c/src/buffer.c @@ -288,14 +288,14 @@ pn_bytes_t pn_buffer_bytes(pn_buffer_t *buf) } } -pn_buffer_memory_t pn_buffer_memory(pn_buffer_t *buf) +pn_rwbytes_t pn_buffer_memory(pn_buffer_t *buf) { if (buf) { pn_buffer_defrag(buf); - pn_buffer_memory_t r = {buf->size, buf->bytes}; + pn_rwbytes_t r = {buf->size, buf->bytes}; return r; } else { - pn_buffer_memory_t r = {0, NULL}; + pn_rwbytes_t r = {0, NULL}; return r; } } http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/src/buffer.h ---------------------------------------------------------------------- diff --git a/proton-c/src/buffer.h b/proton-c/src/buffer.h index 94d48ac..da557ef 100644 --- a/proton-c/src/buffer.h +++ b/proton-c/src/buffer.h @@ -29,11 +29,6 @@ extern "C" { #endif -typedef struct { - size_t size; - char *start; -} pn_buffer_memory_t; - typedef struct pn_buffer_t pn_buffer_t; pn_buffer_t *pn_buffer(size_t capacity); @@ -49,7 +44,7 @@ int pn_buffer_trim(pn_buffer_t *buf, size_t left, size_t right); void pn_buffer_clear(pn_buffer_t *buf); int pn_buffer_defrag(pn_buffer_t *buf); pn_bytes_t pn_buffer_bytes(pn_buffer_t *buf); -pn_buffer_memory_t pn_buffer_memory(pn_buffer_t *buf); +pn_rwbytes_t pn_buffer_memory(pn_buffer_t *buf); int pn_buffer_print(pn_buffer_t *buf); #ifdef __cplusplus http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/src/codec/codec.c ---------------------------------------------------------------------- diff --git a/proton-c/src/codec/codec.c b/proton-c/src/codec/codec.c index ae77b08..2a4532c 100644 --- a/proton-c/src/codec/codec.c +++ b/proton-c/src/codec/codec.c @@ -472,7 +472,7 @@ static int pni_data_intern_node(pn_data_t *data, pni_node_t *node) node->data = true; node->data_offset = offset; node->data_size = bytes->size; - pn_buffer_memory_t buf = pn_buffer_memory(data->buf); + pn_rwbytes_t buf = pn_buffer_memory(data->buf); bytes->start = buf.start + offset; if (pn_buffer_capacity(data->buf) != oldcap) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/src/engine/connection_engine.c ---------------------------------------------------------------------- diff --git a/proton-c/src/engine/connection_engine.c b/proton-c/src/engine/connection_engine.c index 75a16ae..41a1bdc 100644 --- a/proton-c/src/engine/connection_engine.c +++ b/proton-c/src/engine/connection_engine.c @@ -23,16 +23,6 @@ #include <proton/transport.h> #include <string.h> -pn_buf_t pn_buf(char* data, size_t size) { - pn_buf_t b = { data, size }; - return b; -} - -pn_cbuf_t pn_cbuf(const char* data, size_t size) { - pn_cbuf_t b = { data, size }; - return b; -} - int pn_connection_engine_init(pn_connection_engine_t* e) { memset(e, 0, sizeof(*e)); e->connection = pn_connection(); @@ -65,12 +55,12 @@ void pn_connection_engine_final(pn_connection_engine_t* e) { memset(e, 0, sizeof(*e)); } -pn_buf_t pn_connection_engine_read_buffer(pn_connection_engine_t* e) { +pn_rwbytes_t pn_connection_engine_read_buffer(pn_connection_engine_t* e) { ssize_t cap = pn_transport_capacity(e->transport); if (cap > 0) - return pn_buf(pn_transport_tail(e->transport), cap); + return pn_rwbytes(cap, pn_transport_tail(e->transport)); else - return pn_buf(0, 0); + return pn_rwbytes(0, 0); } void pn_connection_engine_read_done(pn_connection_engine_t* e, size_t n) { @@ -82,12 +72,12 @@ void pn_connection_engine_read_close(pn_connection_engine_t* e) { pn_transport_close_tail(e->transport); } -pn_cbuf_t pn_connection_engine_write_buffer(pn_connection_engine_t* e) { +pn_bytes_t pn_connection_engine_write_buffer(pn_connection_engine_t* e) { ssize_t pending = pn_transport_pending(e->transport); if (pending > 0) - return pn_cbuf(pn_transport_head(e->transport), pending); + return pn_bytes(pending, pn_transport_head(e->transport)); else - return pn_cbuf(0, 0); + return pn_bytes(0, 0); } void pn_connection_engine_write_done(pn_connection_engine_t* e, size_t n) { http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/src/transport/transport.c ---------------------------------------------------------------------- diff --git a/proton-c/src/transport/transport.c b/proton-c/src/transport/transport.c index 1d7cc87..cdecfd2 100644 --- a/proton-c/src/transport/transport.c +++ b/proton-c/src/transport/transport.c @@ -920,7 +920,7 @@ int pn_post_frame(pn_transport_t *transport, uint8_t type, uint16_t ch, const ch encode_performatives: pn_buffer_clear( frame_buf ); - pn_buffer_memory_t buf = pn_buffer_memory( frame_buf ); + pn_rwbytes_t buf = pn_buffer_memory( frame_buf ); buf.size = pn_buffer_available( frame_buf ); ssize_t wr = pn_data_encode( transport->output_args, buf.start, buf.size ); @@ -992,7 +992,7 @@ static int pni_post_amqp_transfer_frame(pn_transport_t *transport, uint16_t ch, encode_performatives: pn_buffer_clear( frame ); - pn_buffer_memory_t buf = pn_buffer_memory( frame ); + pn_rwbytes_t buf = pn_buffer_memory( frame ); buf.size = pn_buffer_available( frame ); ssize_t wr = pn_data_encode(transport->output_args, buf.start, buf.size); http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ade77512/proton-c/src/types.c ---------------------------------------------------------------------- diff --git a/proton-c/src/types.c b/proton-c/src/types.c index 5433e19..4f8048d 100644 --- a/proton-c/src/types.c +++ b/proton-c/src/types.c @@ -30,6 +30,12 @@ pn_bytes_t pn_bytes(size_t size, const char *start) return bytes; } +pn_rwbytes_t pn_rwbytes(size_t size, char *start) +{ + pn_rwbytes_t bytes = {size, start}; + return bytes; +} + pn_timestamp_t pn_timestamp_now() { return pn_i_now(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
