package org.opendaylight.controller.protocol_plugin.openflow.core.internal;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousCloseException;
import java.nio.channels.ClosedChannelException;
/**
* Sends the OF message out over the socket channel.
- *
+ *
* @param msg
* OF message to be sent
* @throws Exception
*/
@Override
- public void asyncSend(OFMessage msg) throws IOException {
+ public void asyncSend(OFMessage msg) throws Exception {
synchronized (outBuffer) {
int msgLen = msg.getLengthU();
if (outBuffer.remaining() < msgLen) {
this.clientSelectionKey = this.socket.register(this.selector,
SelectionKey.OP_WRITE, this);
}
- logger.trace("Message sent: {}", msg.toString());
+ logger.trace("Message sent: {}", msg);
}
}
/**
* Resumes sending the remaining messages in the outgoing buffer
- *
+ *
* @throws Exception
*/
@Override
- public void resumeSend() throws IOException {
+ public void resumeSend() throws Exception {
synchronized (outBuffer) {
if (!socket.isOpen()) {
return;
/**
* Reads the incoming network data from the socket and retrieves the OF
* messages.
- *
+ *
* @return list of OF messages
* @throws Exception
*/
@Override
- public List<OFMessage> readMessages() throws IOException {
+ public List<OFMessage> readMessages() throws Exception {
if (!socket.isOpen()) {
return null;
}
throw new AsynchronousCloseException();
}
- inBuffer.flip();
- msgs = factory.parseMessages(inBuffer);
- if (inBuffer.hasRemaining()) {
- inBuffer.compact();
- } else {
+ try {
+ inBuffer.flip();
+ msgs = factory.parseMessages(inBuffer);
+ if (inBuffer.hasRemaining()) {
+ inBuffer.compact();
+ } else {
+ inBuffer.clear();
+ }
+ } catch (Exception e) {
inBuffer.clear();
+ logger.debug("Caught exception: ", e);
}
return msgs;
}