Skip to content

SctpChannel.send() return value ignored #21

Open
@dpalmer895

Description

@dpalmer895

In AssociationImpl.java the return value of send is ignored:

protected void write(SelectionKey key) {

	try {			
		// TODO Do we need to synchronize ConcurrentLinkedQueue?
		// synchronized (this.txQueue) {
		if (!txQueue.isEmpty()) {
			while (!txQueue.isEmpty()) {
				// Lets read all the messages in txQueue and send

				PayloadData payloadData = txQueue.poll();

				if (logger.isDebugEnabled()) {
					logger.debug(String.format("Tx : Ass=%s %s", this.name, payloadData));
				}

				if (this.ipChannelType == IpChannelType.SCTP) {
					int seqControl = payloadData.getStreamNumber();

					if (seqControl < 0 || seqControl >= this.associationHandler.getMaxOutboundStreams()) {
						try {
							// TODO : calling in same Thread. Is this ok? or
							// dangerous?
							this.associationListener.inValidStreamId(payloadData);
						} catch (Exception e) {

						}
						
						continue;
					}

					msgInfo = MessageInfo.createOutgoing(this.peerSocketAddress, seqControl);
					msgInfo.payloadProtocolID(payloadData.getPayloadProtocolId());
					msgInfo.complete(payloadData.isComplete());
					msgInfo.unordered(payloadData.isUnordered());
				}

				try
				{
					this.doSend(payloadData.getByteBuf());
				}
				finally {
					payloadData.releaseBuffer();
				}					

			}// end of while
		}

		if (txQueue.isEmpty()) {
			// We wrote away all data, so we're no longer interested
			// in writing on this socket. Switch back to waiting for
			// data.
			key.interestOps(SelectionKey.OP_READ);
		}

	} catch (IOException e) {
		this.ioErrors++;
		logger.error(String.format(
				"IOException while trying to write to underlying socket for Association=%s IOError count=%d",
				this.name, this.ioErrors), e);

		if (this.ioErrors > this.management.getMaxIOErrors()) {
			// Close this socket
			this.close();

			// retry to connect after delay
			this.scheduleConnect();
		}
	}// try-catch
}

private int doSend(ByteBuf buffer) throws IOException {
	if (this.ipChannelType == IpChannelType.SCTP)
		return this.doSendSctp(buffer);
	else
		return this.doSendTcp(buffer);
}

private int doSendSctp(ByteBuf buffer) throws IOException {
	return this.socketChannelSctp.send(buffer.nioBuffer(), msgInfo);
}

private int doSendTcp(ByteBuf buffer) throws IOException {
	return this.socketChannelTcp.write(buffer.nioBuffer());
}

You can see that the write method calls doSend() but ignores the return value. From what I could see the socket is configured in non blocking mode. In this case where the underlying output buffer is full the SctpChannel.send() method would return 0 indicating no bytes of the message were written. However the write() method doesn't check the return value and just assumes that the message was sent successfully (i.e. message not sent and therefore lost).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions