| 1 |
#ifndef PROTON_TRANSPORT_H |
| 2 |
#define PROTON_TRANSPORT_H 1 |
| 3 |
|
| 4 |
/* |
| 5 |
* |
| 6 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 7 |
* or more contributor license agreements. See the NOTICE file |
| 8 |
* distributed with this work for additional information |
| 9 |
* regarding copyright ownership. The ASF licenses this file |
| 10 |
* to you under the Apache License, Version 2.0 (the |
| 11 |
* "License"); you may not use this file except in compliance |
| 12 |
* with the License. You may obtain a copy of the License at |
| 13 |
* |
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
* |
| 16 |
* Unless required by applicable law or agreed to in writing, |
| 17 |
* software distributed under the License is distributed on an |
| 18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 |
* KIND, either express or implied. See the License for the |
| 20 |
* specific language governing permissions and limitations |
| 21 |
* under the License. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#include <proton/import_export.h> |
| 26 |
#include <proton/type_compat.h> |
| 27 |
#include <proton/condition.h> |
| 28 |
#include <proton/logger.h> |
| 29 |
#include <stddef.h> |
| 30 |
|
| 31 |
#ifdef __cplusplus |
| 32 |
extern "C" { |
| 33 |
#endif |
| 34 |
|
| 35 |
/** |
| 36 |
* @file |
| 37 |
* |
| 38 |
* @copybrief transport |
| 39 |
* |
| 40 |
* @addtogroup transport |
| 41 |
* @{ |
| 42 |
*/ |
| 43 |
|
| 44 |
/** |
| 45 |
* Holds the trace flags for an AMQP transport. |
| 46 |
* |
| 47 |
* The trace flags for an AMQP transport control what sort of |
| 48 |
* information is logged by an AMQP transport. The following bits can |
| 49 |
* be set: |
| 50 |
* |
| 51 |
* - ::PN_TRACE_OFF |
| 52 |
* - ::PN_TRACE_RAW |
| 53 |
* - ::PN_TRACE_FRM |
| 54 |
* - ::PN_TRACE_DRV |
| 55 |
* - ::PN_TRACE_EVT |
| 56 |
* |
| 57 |
* @internal XXX Deprecate when logging is made independent |
| 58 |
*/ |
| 59 |
typedef int pn_trace_t; |
| 60 |
|
| 61 |
/** |
| 62 |
* Callback for customizing logging behaviour. |
| 63 |
* |
| 64 |
* @internal XXX Deprecate when logging is made independent |
| 65 |
*/ |
| 66 |
typedef void (*pn_tracer_t)(pn_transport_t *transport, const char *message); |
| 67 |
|
| 68 |
/** |
| 69 |
* Turn logging off entirely. |
| 70 |
* |
| 71 |
* @internal XXX Deprecate when logging is made independent |
| 72 |
*/ |
| 73 |
#define PN_TRACE_OFF (0) |
| 74 |
|
| 75 |
/** |
| 76 |
* Log raw binary data going in and out of the transport. |
| 77 |
* |
| 78 |
* @internal XXX Deprecate when logging is made independent |
| 79 |
*/ |
| 80 |
#define PN_TRACE_RAW (1) |
| 81 |
|
| 82 |
/** |
| 83 |
* Log protocol frames going in and out of the transport. |
| 84 |
* |
| 85 |
* @internal XXX Deprecate when logging is made independent |
| 86 |
*/ |
| 87 |
#define PN_TRACE_FRM (2) |
| 88 |
|
| 89 |
/** |
| 90 |
* Log driver-related events. For example, initialization, end of |
| 91 |
* stream, and so on. |
| 92 |
* |
| 93 |
* @internal XXX Deprecate when logging is made independent |
| 94 |
*/ |
| 95 |
#define PN_TRACE_DRV (4) |
| 96 |
|
| 97 |
/** |
| 98 |
* Log events. |
| 99 |
* |
| 100 |
* @internal XXX Deprecate when logging is made independent |
| 101 |
*/ |
| 102 |
#define PN_TRACE_EVT (8) |
| 103 |
|
| 104 |
/** |
| 105 |
* Factory for creating a transport. |
| 106 |
* |
| 107 |
* A transport is used by a connection to interface with the network. |
| 108 |
* There can only be one connection associated with a transport. |
| 109 |
* |
| 110 |
* Initially a transport is configured to be a client transport. Use |
| 111 |
* pn_transport_set_server() to configure the transport as a server |
| 112 |
* transport. |
| 113 |
* |
| 114 |
* A client transport initiates outgoing connections. |
| 115 |
* |
| 116 |
* A client transport must be configured with the protocol layers to |
| 117 |
* use and cannot configure itself automatically. |
| 118 |
* |
| 119 |
* A server transport accepts incoming connections. It can |
| 120 |
* automatically configure itself to include the various protocol |
| 121 |
* layers depending on the incoming protocol headers. |
| 122 |
* |
| 123 |
* @return pointer to new transport |
| 124 |
*/ |
| 125 |
PN_EXTERN pn_transport_t *pn_transport(void); |
| 126 |
|
| 127 |
/** |
| 128 |
* Configure a transport as a server |
| 129 |
* |
| 130 |
* @param[in] transport a transport object |
| 131 |
*/ |
| 132 |
PN_EXTERN void pn_transport_set_server(pn_transport_t *transport); |
| 133 |
|
| 134 |
/** |
| 135 |
* Free a transport object. |
| 136 |
* |
| 137 |
* When a transport is freed, it is automatically unbound from its |
| 138 |
* associated connection. |
| 139 |
* |
| 140 |
* @param[in] transport a transport object or NULL |
| 141 |
*/ |
| 142 |
PN_EXTERN void pn_transport_free(pn_transport_t *transport); |
| 143 |
|
| 144 |
/** |
| 145 |
* Retrieve the authenticated user. |
| 146 |
* |
| 147 |
* This is usually used at the the server end to find the name of the |
| 148 |
* authenticated user. On the client it will merely return whatever |
| 149 |
* user was passed in to the pn_connection_set_user() API of the bound |
| 150 |
* connection. |
| 151 |
* |
| 152 |
* The returned value is only reliable after the |
| 153 |
* PN_TRANSPORT_AUTHENTICATED event has been received. |
| 154 |
* |
| 155 |
* @param[in] transport the transport |
| 156 |
* |
| 157 |
* @return If a the user is anonymous (either no SASL layer is |
| 158 |
* negotiated or the SASL ANONYMOUS mechanism is used) then the user |
| 159 |
* will be "anonymous" Otherwise a string containing the user is |
| 160 |
* returned. |
| 161 |
*/ |
| 162 |
PN_EXTERN const char *pn_transport_get_user(pn_transport_t *transport); |
| 163 |
|
| 164 |
/** |
| 165 |
* Set whether a non-authenticated transport connection is allowed. |
| 166 |
* |
| 167 |
* There are several ways within the AMQP protocol suite to get |
| 168 |
* unauthenticated connections: |
| 169 |
* |
| 170 |
* - Use no SASL layer (with either no TLS or TLS without client certificates) |
| 171 |
* - Use a SASL layer but the ANONYMOUS mechanism |
| 172 |
* |
| 173 |
* The default if this option is not set is to allow unauthenticated connections. |
| 174 |
* |
| 175 |
* @param[in] transport the transport |
| 176 |
* @param[in] required boolean is true when authenticated connections are required |
| 177 |
*/ |
| 178 |
PN_EXTERN void pn_transport_require_auth(pn_transport_t *transport, bool required); |
| 179 |
|
| 180 |
/** |
| 181 |
* Tell whether the transport connection is authenticated |
| 182 |
* |
| 183 |
* Note that this property may not be stable until the PN_CONNECTION_REMOTE_OPEN |
| 184 |
* event is received. |
| 185 |
* |
| 186 |
* @param[in] transport the transport |
| 187 |
* @return bool representing authentication |
| 188 |
*/ |
| 189 |
PN_EXTERN bool pn_transport_is_authenticated(pn_transport_t *transport); |
| 190 |
|
| 191 |
/** |
| 192 |
* Set whether a non encrypted transport connection is allowed |
| 193 |
* |
| 194 |
* There are several ways within the AMQP protocol suite to get encrypted connections: |
| 195 |
* - Use TLS |
| 196 |
* - Use a SASL with a mechanism that supports security layers |
| 197 |
* |
| 198 |
* The default if this option is not set is to allow unencrypted connections. |
| 199 |
* |
| 200 |
* @param[in] transport the transport |
| 201 |
* @param[in] required boolean is true when encrypted connections are required |
| 202 |
*/ |
| 203 |
PN_EXTERN void pn_transport_require_encryption(pn_transport_t *transport, bool required); |
| 204 |
|
| 205 |
/** |
| 206 |
* Tell whether the transport connection is encrypted |
| 207 |
* |
| 208 |
* Note that this property may not be stable until the PN_CONNECTION_REMOTE_OPEN |
| 209 |
* event is received. |
| 210 |
* |
| 211 |
* @param[in] transport the transport |
| 212 |
* @return bool representing encryption |
| 213 |
*/ |
| 214 |
PN_EXTERN bool pn_transport_is_encrypted(pn_transport_t *transport); |
| 215 |
|
| 216 |
/** |
| 217 |
* Get additional information about the condition of the transport. |
| 218 |
* |
| 219 |
* When a PN_TRANSPORT_ERROR event occurs, this operation can be used |
| 220 |
* to access the details of the error condition. |
| 221 |
* |
| 222 |
* The pointer returned by this operation is valid until the |
| 223 |
* transport object is freed. |
| 224 |
* |
| 225 |
* @param[in] transport the transport object |
| 226 |
* @return the transport's condition object |
| 227 |
*/ |
| 228 |
PN_EXTERN pn_condition_t *pn_transport_condition(pn_transport_t *transport); |
| 229 |
|
| 230 |
/** |
| 231 |
* Get the transport logger |
| 232 |
* |
| 233 |
* This can be used to control the logging information emitted by the transport |
| 234 |
* |
| 235 |
* The pointer returned by this operation is valid until the |
| 236 |
* transport object is freed. |
| 237 |
* |
| 238 |
* @param[in] transport the transport object |
| 239 |
* @return the transport's logger object |
| 240 |
*/ |
| 241 |
PN_EXTERN pn_logger_t *pn_transport_logger(pn_transport_t *transport); |
| 242 |
|
| 243 |
/** |
| 244 |
* **Deprecated** - Use ::pn_transport_condition(). |
| 245 |
*/ |
| 246 |
PN_EXTERN pn_error_t *pn_transport_error(pn_transport_t *transport); |
| 247 |
|
| 248 |
/** |
| 249 |
* **Deprecated** - Use ::pn_connection_driver_init(). |
| 250 |
* |
| 251 |
* Binds the transport to an AMQP connection. |
| 252 |
* |
| 253 |
* @return an error code, or 0 on success |
| 254 |
*/ |
| 255 |
PN_EXTERN int pn_transport_bind(pn_transport_t *transport, pn_connection_t *connection); |
| 256 |
|
| 257 |
/** |
| 258 |
* **Deprecated** - Use ::pn_connection_driver_destroy(). |
| 259 |
* |
| 260 |
* Unbinds a transport from its AMQP connection. |
| 261 |
* |
| 262 |
* @return an error code, or 0 on success |
| 263 |
*/ |
| 264 |
PN_EXTERN int pn_transport_unbind(pn_transport_t *transport); |
| 265 |
|
| 266 |
/** |
| 267 |
* Update a transports trace flags. |
| 268 |
* |
| 269 |
* The trace flags for a transport control what sort of information is |
| 270 |
* logged. See ::pn_trace_t for more details. |
| 271 |
* |
| 272 |
* @param[in] transport a transport object |
| 273 |
* @param[in] trace the trace flags |
| 274 |
* |
| 275 |
* @internal XXX Deprecate when logging is made independent |
| 276 |
*/ |
| 277 |
PN_EXTERN void pn_transport_trace(pn_transport_t *transport, pn_trace_t trace); |
| 278 |
|
| 279 |
/** |
| 280 |
* Set the tracing function used by a transport. |
| 281 |
* |
| 282 |
* The tracing function is called to perform logging. Overriding this |
| 283 |
* function allows embedding applications to divert the engine's |
| 284 |
* logging to a place of their choice. |
| 285 |
* |
| 286 |
* @param[in] transport a transport object |
| 287 |
* @param[in] tracer the tracing function |
| 288 |
* |
| 289 |
* @internal XXX Deprecate when logging is made independent |
| 290 |
*/ |
| 291 |
PN_EXTERN void pn_transport_set_tracer(pn_transport_t *transport, pn_tracer_t tracer); |
| 292 |
|
| 293 |
/** |
| 294 |
* Get the tracing function used by a transport. |
| 295 |
* |
| 296 |
* @param[in] transport a transport object |
| 297 |
* @return the tracing function used by a transport |
| 298 |
* |
| 299 |
* @internal XXX Deprecate when logging is made independent |
| 300 |
*/ |
| 301 |
PN_EXTERN pn_tracer_t pn_transport_get_tracer(pn_transport_t *transport); |
| 302 |
|
| 303 |
/** |
| 304 |
* Get the application context that is associated with a transport object. |
| 305 |
* |
| 306 |
* The application context for a transport may be set using |
| 307 |
* ::pn_transport_set_context. |
| 308 |
* |
| 309 |
* @param[in] transport the transport whose context is to be returned. |
| 310 |
* @return the application context for the transport object |
| 311 |
*/ |
| 312 |
PN_EXTERN void *pn_transport_get_context(pn_transport_t *transport); |
| 313 |
|
| 314 |
/** |
| 315 |
* Set a new application context for a transport object. |
| 316 |
* |
| 317 |
* The application context for a transport object may be retrieved using |
| 318 |
* ::pn_transport_get_context. |
| 319 |
* |
| 320 |
* @param[in] transport the transport object |
| 321 |
* @param[in] context the application context |
| 322 |
*/ |
| 323 |
PN_EXTERN void pn_transport_set_context(pn_transport_t *transport, void *context); |
| 324 |
|
| 325 |
/** |
| 326 |
* Get the attachments that are associated with a transport object. |
| 327 |
* |
| 328 |
* @param[in] transport the transport whose attachments are to be returned. |
| 329 |
* @return the attachments for the transport object |
| 330 |
*/ |
| 331 |
PN_EXTERN pn_record_t *pn_transport_attachments(pn_transport_t *transport); |
| 332 |
|
| 333 |
/** |
| 334 |
* Log a message using a transport's logging mechanism. |
| 335 |
* |
| 336 |
* This can be useful in a debugging context as the log message will |
| 337 |
* be prefixed with the transport's identifier. |
| 338 |
* |
| 339 |
* @param[in] transport a transport object |
| 340 |
* @param[in] message the message to be logged |
| 341 |
* |
| 342 |
* @internal XXX Deprecate when logging is made independent |
| 343 |
*/ |
| 344 |
PN_EXTERN void pn_transport_log(pn_transport_t *transport, const char *message); |
| 345 |
|
| 346 |
/** |
| 347 |
* Log a printf formatted message using a transport's logging |
| 348 |
* mechanism. |
| 349 |
* |
| 350 |
* This can be useful in a debugging context as the log message will |
| 351 |
* be prefixed with the transport's identifier. |
| 352 |
* |
| 353 |
* @param[in] transport a transport object |
| 354 |
* @param[in] fmt the printf formatted message to be logged |
| 355 |
* @param[in] ap a vector containing the format arguments |
| 356 |
* |
| 357 |
* @internal XXX Deprecate when logging is made independent |
| 358 |
*/ |
| 359 |
PN_EXTERN void pn_transport_vlogf(pn_transport_t *transport, const char *fmt, va_list ap); |
| 360 |
|
| 361 |
/** |
| 362 |
* Log a printf formatted message using a transport's logging |
| 363 |
* mechanism. |
| 364 |
* |
| 365 |
* This can be useful in a debugging context as the log message will |
| 366 |
* be prefixed with the transport's identifier. |
| 367 |
* |
| 368 |
* @param[in] transport a transport object |
| 369 |
* @param[in] fmt the printf formatted message to be logged |
| 370 |
* |
| 371 |
* @internal XXX Deprecate when logging is made independent |
| 372 |
*/ |
| 373 |
PN_EXTERN void pn_transport_logf(pn_transport_t *transport, const char *fmt, ...); |
| 374 |
|
| 375 |
/** |
| 376 |
* Get the maximum allowed channel for a transport. |
| 377 |
* This will be the minimum of |
| 378 |
* 1. limit imposed by this proton implementation |
| 379 |
* 2. limit imposed by remote peer |
| 380 |
* 3. limit imposed by this application, using pn_transport_set_channel_max() |
| 381 |
* |
| 382 |
* @param[in] transport a transport object |
| 383 |
* @return the maximum allowed channel |
| 384 |
* |
| 385 |
* @internal XXX Deprecate when moved to connection |
| 386 |
*/ |
| 387 |
PN_EXTERN uint16_t pn_transport_get_channel_max(pn_transport_t *transport); |
| 388 |
|
| 389 |
/** |
| 390 |
* Set the maximum allowed channel number for a transport. |
| 391 |
* Note that this is the maximum channel number allowed, giving a |
| 392 |
* valid channel number range of [0..channel_max]. Therefore the |
| 393 |
* maximum number of simultaneously active channels will be |
| 394 |
* channel_max plus 1. |
| 395 |
* You can call this function more than once to raise and lower |
| 396 |
* the limit your application imposes on max channels for this |
| 397 |
* transport. However, smaller limits may be imposed by this |
| 398 |
* library, or by the remote peer. |
| 399 |
* After the OPEN frame has been sent to the remote peer, |
| 400 |
* further calls to this function will have no effect. |
| 401 |
* |
| 402 |
* @param[in] transport a transport object |
| 403 |
* @param[in] channel_max the maximum allowed channel |
| 404 |
* @return PN_OK, or PN_STATE_ERR if it is too late to change channel_max |
| 405 |
* |
| 406 |
* @internal XXX Deprecate when moved to connection |
| 407 |
*/ |
| 408 |
PN_EXTERN int pn_transport_set_channel_max(pn_transport_t *transport, uint16_t channel_max); |
| 409 |
|
| 410 |
/** |
| 411 |
* Get the maximum allowed channel of a transport's remote peer. |
| 412 |
* |
| 413 |
* @param[in] transport a transport object |
| 414 |
* @return the maximum allowed channel of the transport's remote peer |
| 415 |
* |
| 416 |
* @internal XXX Deprecate when moved to connection |
| 417 |
*/ |
| 418 |
PN_EXTERN uint16_t pn_transport_remote_channel_max(pn_transport_t *transport); |
| 419 |
|
| 420 |
/** |
| 421 |
* Get the maximum frame size of a transport. |
| 422 |
* |
| 423 |
* @param[in] transport a transport object |
| 424 |
* @return the maximum frame size of the transport object |
| 425 |
* |
| 426 |
* @internal XXX Deprecate when moved to connection |
| 427 |
*/ |
| 428 |
PN_EXTERN uint32_t pn_transport_get_max_frame(pn_transport_t *transport); |
| 429 |
|
| 430 |
/** |
| 431 |
* Set the maximum frame size of a transport. |
| 432 |
* |
| 433 |
* @param[in] transport a transport object |
| 434 |
* @param[in] size the maximum frame size for the transport object |
| 435 |
* |
| 436 |
* @internal XXX Deprecate when moved to connection |
| 437 |
*/ |
| 438 |
PN_EXTERN void pn_transport_set_max_frame(pn_transport_t *transport, uint32_t size); |
| 439 |
|
| 440 |
/** |
| 441 |
* Get the maximum frame size of a transport's remote peer. |
| 442 |
* |
| 443 |
* @param[in] transport a transport object |
| 444 |
* @return the maximum frame size of the transport's remote peer |
| 445 |
* |
| 446 |
* @internal XXX Deprecate when moved to connection |
| 447 |
*/ |
| 448 |
PN_EXTERN uint32_t pn_transport_get_remote_max_frame(pn_transport_t *transport); |
| 449 |
|
| 450 |
/** |
| 451 |
* Get the idle timeout for a transport. |
| 452 |
* |
| 453 |
* A zero idle timeout means heartbeats are disabled. |
| 454 |
* |
| 455 |
* @param[in] transport a transport object |
| 456 |
* @return the transport's idle timeout |
| 457 |
* |
| 458 |
* @internal XXX Deprecate when moved to connection |
| 459 |
*/ |
| 460 |
PN_EXTERN pn_millis_t pn_transport_get_idle_timeout(pn_transport_t *transport); |
| 461 |
|
| 462 |
/** |
| 463 |
* Set the idle timeout for a transport. |
| 464 |
* |
| 465 |
* A zero idle timeout means heartbeats are disabled. |
| 466 |
* |
| 467 |
* @param[in] transport a transport object |
| 468 |
* @param[in] timeout the idle timeout for the transport object |
| 469 |
* |
| 470 |
* @internal XXX Deprecate when moved to connection |
| 471 |
*/ |
| 472 |
PN_EXTERN void pn_transport_set_idle_timeout(pn_transport_t *transport, pn_millis_t timeout); |
| 473 |
|
| 474 |
/** |
| 475 |
* Get the idle timeout for a transport's remote peer. |
| 476 |
* |
| 477 |
* A zero idle timeout means heartbeats are disabled. |
| 478 |
* |
| 479 |
* @param[in] transport a transport object |
| 480 |
* @return the idle timeout for the transport's remote peer |
| 481 |
* |
| 482 |
* @internal XXX Deprecate when moved to connection |
| 483 |
*/ |
| 484 |
PN_EXTERN pn_millis_t pn_transport_get_remote_idle_timeout(pn_transport_t *transport); |
| 485 |
|
| 486 |
/** |
| 487 |
* **Deprecated** - Use the @ref connection_driver API. |
| 488 |
*/ |
| 489 |
PN_EXTERN ssize_t pn_transport_input(pn_transport_t *transport, const char *bytes, size_t available); |
| 490 |
|
| 491 |
/** |
| 492 |
* **Deprecated** - Use the @ref connection_driver API. |
| 493 |
*/ |
| 494 |
PN_EXTERN ssize_t pn_transport_output(pn_transport_t *transport, char *bytes, size_t size); |
| 495 |
|
| 496 |
/** |
| 497 |
* **Deprecated** - Use the @ref connection_driver API. |
| 498 |
* |
| 499 |
* Get the amount of free space for input following the transport's |
| 500 |
* tail pointer. |
| 501 |
* |
| 502 |
* If the engine is in an exceptional state such as encountering an |
| 503 |
* error condition or reaching the end of stream state, a negative |
| 504 |
* value will be returned indicating the condition. If an error is |
| 505 |
* indicated, further details can be obtained from |
| 506 |
* ::pn_transport_condition(). Calls to ::pn_transport_process() may |
| 507 |
* alter the value of this pointer. See ::pn_transport_process for |
| 508 |
* details. |
| 509 |
* |
| 510 |
* @param[in] transport the transport |
| 511 |
* @return the free space in the transport, PN_EOS or error code if < 0 |
| 512 |
*/ |
| 513 |
PN_EXTERN ssize_t pn_transport_capacity(pn_transport_t *transport); |
| 514 |
|
| 515 |
/** |
| 516 |
* **Deprecated** - Use the @ref connection_driver API. |
| 517 |
* |
| 518 |
* Get the transport's tail pointer. |
| 519 |
* |
| 520 |
* The amount of free space following this pointer is reported by |
| 521 |
* ::pn_transport_capacity. Calls to ::pn_transport_process may alter |
| 522 |
* the value of this pointer. See ::pn_transport_process for details. |
| 523 |
* |
| 524 |
* @param[in] transport the transport |
| 525 |
* @return a pointer to the transport's input buffer, NULL if no capacity available. |
| 526 |
*/ |
| 527 |
PN_EXTERN char *pn_transport_tail(pn_transport_t *transport); |
| 528 |
|
| 529 |
/** |
| 530 |
* **Deprecated** - Use the @ref connection_driver API. |
| 531 |
* |
| 532 |
* Pushes the supplied bytes into the tail of the transport. |
| 533 |
* |
| 534 |
* This is equivalent to copying @c size bytes after the tail pointer |
| 535 |
* and then calling ::pn_transport_process with an argument of @c |
| 536 |
* size. Only some of the bytes will be copied if there is |
| 537 |
* insufficient capacity available. Use ::pn_transport_capacity to |
| 538 |
* determine how much capacity the transport has. |
| 539 |
* |
| 540 |
* @param[in] transport the transport |
| 541 |
* @param[in] src the start of the data to push into the transport |
| 542 |
* @param[in] size the amount of data to push into the transport |
| 543 |
* |
| 544 |
* @return the number of bytes pushed on success, or error code if < 0 |
| 545 |
*/ |
| 546 |
PN_EXTERN ssize_t pn_transport_push(pn_transport_t *transport, const char *src, size_t size); |
| 547 |
|
| 548 |
/** |
| 549 |
* **Deprecated** - Use the @ref connection_driver API. |
| 550 |
* |
| 551 |
* Process input data following the tail pointer. |
| 552 |
* |
| 553 |
* Calling this function will cause the transport to consume @c size |
| 554 |
* bytes of input occupying the free space following the tail pointer. |
| 555 |
* Calls to this function may change the value of ::pn_transport_tail, |
| 556 |
* as well as the amount of free space reported by |
| 557 |
* ::pn_transport_capacity. |
| 558 |
* |
| 559 |
* @param[in] transport the transport |
| 560 |
* @param[in] size the amount of data written to the transport's input buffer |
| 561 |
* @return 0 on success, or error code if < 0 |
| 562 |
*/ |
| 563 |
PN_EXTERN int pn_transport_process(pn_transport_t *transport, size_t size); |
| 564 |
|
| 565 |
/** |
| 566 |
* **Deprecated** - Use the @ref connection_driver API. |
| 567 |
* |
| 568 |
* Indicate that the input has reached End Of Stream (EOS). |
| 569 |
* |
| 570 |
* This tells the transport that no more input will be forthcoming. |
| 571 |
* |
| 572 |
* @param[in] transport the transport |
| 573 |
* @return 0 on success, or error code if < 0 |
| 574 |
*/ |
| 575 |
PN_EXTERN int pn_transport_close_tail(pn_transport_t *transport); |
| 576 |
|
| 577 |
/** |
| 578 |
* **Deprecated** - Use the @ref connection_driver API. |
| 579 |
* |
| 580 |
* Get the number of pending output bytes following the transport's |
| 581 |
* head pointer. |
| 582 |
* |
| 583 |
* If the engine is in an exceptional state such as encountering an |
| 584 |
* error condition or reaching the end of stream state, a negative |
| 585 |
* value will be returned indicating the condition. If an error is |
| 586 |
* indicated, further details can be obtained from |
| 587 |
* ::pn_transport_condition(). Calls to ::pn_transport_pop() may alter |
| 588 |
* the value of this pointer. See ::pn_transport_pop() for details. |
| 589 |
* |
| 590 |
* @param[in] transport the transport |
| 591 |
* @return the number of pending output bytes, or an error code |
| 592 |
*/ |
| 593 |
PN_EXTERN ssize_t pn_transport_pending(pn_transport_t *transport); |
| 594 |
|
| 595 |
/** |
| 596 |
* **Deprecated** - Use the @ref connection_driver API. |
| 597 |
* |
| 598 |
* Get the transport's head pointer. |
| 599 |
* |
| 600 |
* This pointer references queued output data. The |
| 601 |
* ::pn_transport_pending function reports how many bytes of output |
| 602 |
* data follow this pointer. Calls to ::pn_transport_pop may alter |
| 603 |
* this pointer and any data it references. See ::pn_transport_pop for |
| 604 |
* details. |
| 605 |
* |
| 606 |
* @param[in] transport the transport |
| 607 |
* @return a pointer to the transport's output buffer, or NULL if no pending output. |
| 608 |
*/ |
| 609 |
PN_EXTERN const char *pn_transport_head(pn_transport_t *transport); |
| 610 |
|
| 611 |
/** |
| 612 |
* **Deprecated** - Use the @ref connection_driver API. |
| 613 |
* |
| 614 |
* Copies @c size bytes from the head of the transport to the @c dst |
| 615 |
* pointer. |
| 616 |
* |
| 617 |
* It is an error to call this with a value of @c size that is greater |
| 618 |
* than the value reported by ::pn_transport_pending. |
| 619 |
* |
| 620 |
* @param[in] transport the transport |
| 621 |
* @param[out] dst the destination buffer |
| 622 |
* @param[in] size the capacity of the destination buffer |
| 623 |
* @return number of bytes copied on success, or error code if < 0 |
| 624 |
*/ |
| 625 |
PN_EXTERN ssize_t pn_transport_peek(pn_transport_t *transport, char *dst, size_t size); |
| 626 |
|
| 627 |
/** |
| 628 |
* **Deprecated** - Use the @ref connection_driver API. |
| 629 |
* |
| 630 |
* Removes @c size bytes of output from the pending output queue |
| 631 |
* following the transport's head pointer. |
| 632 |
* |
| 633 |
* Calls to this function may alter the transport's head pointer as |
| 634 |
* well as the number of pending bytes reported by |
| 635 |
* ::pn_transport_pending. |
| 636 |
* |
| 637 |
* @param[in] transport the transport |
| 638 |
* @param[in] size the number of bytes to remove |
| 639 |
*/ |
| 640 |
PN_EXTERN void pn_transport_pop(pn_transport_t *transport, size_t size); |
| 641 |
|
| 642 |
/** |
| 643 |
* **Deprecated** - Use the @ref connection_driver API. |
| 644 |
* |
| 645 |
* Indicate that the output has closed. |
| 646 |
* |
| 647 |
* This tells the transport that no more output will be popped. |
| 648 |
* |
| 649 |
* @param[in] transport the transport |
| 650 |
* @return 0 on success, or error code if < 0 |
| 651 |
*/ |
| 652 |
PN_EXTERN int pn_transport_close_head(pn_transport_t *transport); |
| 653 |
|
| 654 |
/** |
| 655 |
* **Deprecated** - Use the @ref connection_driver API. |
| 656 |
* |
| 657 |
* Check if a transport has buffered data. |
| 658 |
* |
| 659 |
* @param[in] transport a transport object |
| 660 |
* @return true if the transport has buffered data, false otherwise |
| 661 |
*/ |
| 662 |
PN_EXTERN bool pn_transport_quiesced(pn_transport_t *transport); |
| 663 |
|
| 664 |
/** |
| 665 |
* **Deprecated** - Use the @ref connection_driver API. |
| 666 |
* |
| 667 |
* True if pn_transport_close_head() has been called. |
| 668 |
*/ |
| 669 |
PN_EXTERN bool pn_transport_head_closed(pn_transport_t *transport); |
| 670 |
|
| 671 |
/** |
| 672 |
* **Deprecated** - Use the @ref connection_driver API. |
| 673 |
* |
| 674 |
* True if pn_transport_close_tail() has been called. |
| 675 |
*/ |
| 676 |
PN_EXTERN bool pn_transport_tail_closed(pn_transport_t *transport); |
| 677 |
|
| 678 |
/** |
| 679 |
* **Deprecated** - Use the @ref connection_driver API. |
| 680 |
* |
| 681 |
* Equivalent to pn_transport_head_closed(transport) && pn_transport_tail_closed(transport) |
| 682 |
*/ |
| 683 |
PN_EXTERN bool pn_transport_closed(pn_transport_t *transport); |
| 684 |
|
| 685 |
/** |
| 686 |
* Process any pending transport timer events. |
| 687 |
* |
| 688 |
* This method should be called after all pending input has been |
| 689 |
* processed by the transport and before generating output. It returns |
| 690 |
* the deadline for the next pending timer event, if any are present. |
| 691 |
* |
| 692 |
* Note that this function does nothing until the first data is read |
| 693 |
* from or written to the transport. |
| 694 |
* |
| 695 |
* |
| 696 |
* @param[in] transport the transport to process. |
| 697 |
* @param[in] now A monotonically-increasing time value in milliseconds. |
| 698 |
* Does not need to be wall-clock time or a valid AMQP timestamp, but must increase monotonically. |
| 699 |
* |
| 700 |
* @return If non-zero, then the monotonic expiration time of the next pending |
| 701 |
* timer event for the transport. The caller must invoke pn_transport_tick |
| 702 |
* again at least once at or before this deadline occurs. If 0 there are no |
| 703 |
* pending events. |
| 704 |
* |
| 705 |
* @internal XXX Deprecate when tick is added to connection driver |
| 706 |
*/ |
| 707 |
PN_EXTERN int64_t pn_transport_tick(pn_transport_t *transport, int64_t now); |
| 708 |
|
| 709 |
/** |
| 710 |
* **Deprecated** - No replacement. |
| 711 |
* |
| 712 |
* Get the number of frames output by a transport. |
| 713 |
* |
| 714 |
* @param[in] transport a transport object |
| 715 |
* @return the number of frames output by the transport |
| 716 |
*/ |
| 717 |
PN_EXTERN uint64_t pn_transport_get_frames_output(const pn_transport_t *transport); |
| 718 |
|
| 719 |
/** |
| 720 |
* **Deprecated** - No replacement. |
| 721 |
* |
| 722 |
* Get the number of frames input by a transport. |
| 723 |
* |
| 724 |
* @param[in] transport a transport object |
| 725 |
* @return the number of frames input by the transport |
| 726 |
*/ |
| 727 |
PN_EXTERN uint64_t pn_transport_get_frames_input(const pn_transport_t *transport); |
| 728 |
|
| 729 |
/** |
| 730 |
* Access the AMQP Connection associated with the transport. |
| 731 |
* |
| 732 |
* @param[in] transport a transport object |
| 733 |
* @return the connection context for the transport, or NULL if |
| 734 |
* none |
| 735 |
*/ |
| 736 |
PN_EXTERN pn_connection_t *pn_transport_connection(pn_transport_t *transport); |
| 737 |
|
| 738 |
#ifdef __cplusplus |
| 739 |
} |
| 740 |
#endif |
| 741 |
|
| 742 |
/** |
| 743 |
* @} |
| 744 |
*/ |
| 745 |
|
| 746 |
#endif /* transport.h */ |