@Override
	public void send() throws IOException
	{
		if (isNotReady()) {
			return;
		}
		
		long startTime = System.nanoTime();
		
		ByteBuffer out = protocol.allocateBuffer();
		
		out.clear();
		onWritePacketHeader( out );
		
		callsSent = 0;
		
		while (!outbound.isEmpty() && tryPut(outbound.peek(), out))
		{
			RemoteMethodCall call = outbound.poll();
			call.packetIndex = packetIndex;
			onCallWrite( call );
			callsSent++;
		}

		out.flip();
		
		if (callsSent > 0)
		{
			lastSentPacketSize = onWritePacketSize( out );
			
			bufferOut.offer( out );
			
			packetIndex++;
			
			write();
		}
		else
		{
			protocol.releaseBuffer( out );
		}
		
		durationSend = System.nanoTime() - startTime;
		sendIndex++;
	}