1 /* 2 * hunt-proton: AMQP Protocol library for D programming language. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net/ 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 12 module hunt.proton.engine.Receiver; 13 14 import hunt.proton.codec.ReadableBuffer; 15 import hunt.proton.codec.WritableBuffer; 16 17 import hunt.proton.engine.Link; 18 /** 19 * Receiver 20 * 21 */ 22 interface Receiver : Link 23 { 24 25 /** 26 * Adds the specified number of credits. 27 * 28 * The number of link credits initialises to zero. It is the application's responsibility to call 29 * this method to allow the receiver to receive {@code credits} more deliveries. 30 */ 31 public void flow(int credits); 32 33 /** 34 * Receive message data for the current delivery. 35 * 36 * If the caller takes all the bytes the Receiver currently has for this delivery then it is removed from 37 * the Connection's work list. 38 * 39 * Before considering a delivery to be complete, the caller should examine {@link Delivery#isPartial()}. If 40 * the delivery is partial, the caller should call {@link #recv(byte[], int, int)} again to receive 41 * the additional bytes once the Delivery appears again on the Connection work-list. 42 * 43 * TODO might the flags other than IO_WORK in DeliveryImpl also prevent the work list being pruned? 44 * e.g. what if a slow JMS consumer receives a disposition frame containing state=RELEASED? This is not IO_WORK. 45 * 46 * @param bytes the destination array where the message data is written 47 * @param offset index in the array to start writing data at 48 * @param size the maximum number of bytes to write 49 * 50 * @return number of bytes written. -1 if there are no more bytes for the current delivery. 51 * 52 * @see #current() 53 */ 54 public int recv(byte[] bytes, int offset, int size); 55 56 /** 57 * Receive message data for the current delivery. 58 * 59 * @param buffer the buffer to write the message data. 60 * 61 * @return number of bytes written. -1 if there are no more bytes for the current delivery. 62 */ 63 public int recv(WritableBuffer buffer); 64 65 /** 66 * Receive message data for the current delivery returning the data in a Readable buffer. 67 * 68 * The delivery will return an empty buffer if there is no pending data to be read or if all 69 * data has been read either by a previous call to this method or by a call to one of the other 70 * receive methods. 71 * 72 * @return a ReadableBuffer that contains the currently available data for the current delivery. 73 */ 74 public ReadableBuffer recv(); 75 76 public void drain(int credit); 77 78 /** 79 * {@inheritDoc} 80 * 81 * TODO document what this method conceptually does and when you should use it. 82 */ 83 public bool advance(); 84 85 public bool draining(); 86 87 public void setDrain(bool drain); 88 89 }